Skip to content

Commit 541e90a

Browse files
author
Alyar
committed
DataGrid: remove AI chat onChatCleared callback
1 parent 254f238 commit 541e90a

5 files changed

Lines changed: 22 additions & 52 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('AIAssistantView', () => {
140140
expect(AIChat).toHaveBeenCalledTimes(1);
141141
});
142142

143-
it('should pass container, createComponent, popupOptions, chatOptions, onChatCleared, and onRegenerate to AIChat', () => {
143+
it('should pass container, createComponent, popupOptions, chatOptions, and onRegenerate to AIChat', () => {
144144
const { aiAssistantView } = createAIAssistantView();
145145

146146
expect(AIChat).toHaveBeenCalledWith(
@@ -149,7 +149,6 @@ describe('AIAssistantView', () => {
149149
createComponent: expect.any(Function),
150150
popupOptions: expect.any(Object),
151151
chatOptions: expect.any(Object),
152-
onChatCleared: expect.any(Function),
153152
onRegenerate: expect.any(Function),
154153
}),
155154
);
@@ -293,20 +292,6 @@ describe('AIAssistantView', () => {
293292
});
294293

295294
describe('chat event handlers', () => {
296-
describe('onChatCleared', () => {
297-
it('should call clear on aiChatInstance when triggered', () => {
298-
createAIAssistantView();
299-
300-
const aiChatInstance = (AIChat as jest.Mock)
301-
.mock.results[0].value as { clear: jest.Mock };
302-
303-
const aiChatConfig = (AIChat as jest.Mock).mock.calls[0][0] as AIChatOptions;
304-
aiChatConfig.onChatCleared?.();
305-
306-
expect(aiChatInstance.clear).toHaveBeenCalledTimes(1);
307-
});
308-
});
309-
310295
describe('onRegenerate', () => {
311296
it('should send request to AI with the AI message', () => {
312297
mockAIAssistantController.sendRequestToAI.mockReturnValue(Promise.resolve());

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ export class AIAssistantView extends View {
4545
return {
4646
container: this.element(),
4747
createComponent: this._createComponent.bind(this),
48-
onChatCleared: (): void => {
49-
this.aiChatInstance.clear();
50-
},
5148
onRegenerate: (aiMessage: AIMessage): void => {
5249
this.executeRequest(aiMessage);
5350
},

packages/devextreme/js/__internal/grids/grid_core/ai_chat/ai_chat.test.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ describe('AIChat', () => {
219219
});
220220

221221
describe('clearChatButton', () => {
222-
it('should include toolbarItems with clear chat button when onChatCleared is provided', () => {
223-
const onChatCleared = jest.fn();
224-
createAIChat({ onChatCleared });
222+
it('should include toolbarItems with clear chat button', () => {
223+
createAIChat();
225224

226225
const popupConfig = getPopupConfig();
227226

@@ -232,18 +231,25 @@ describe('AIChat', () => {
232231
location: 'after',
233232
options: expect.objectContaining({
234233
icon: CLEAR_CHAT_ICON,
235-
onClick: onChatCleared,
234+
onClick: expect.any(Function),
236235
}),
237236
}),
238237
]);
239238
});
240239

241-
it('should not include toolbarItems when onChatCleared is not provided', () => {
240+
it('should call clear when clear chat button is clicked', () => {
241+
const mockStore = { clear: jest.fn() };
242+
mockDataSource.store.mockReturnValue(mockStore);
243+
242244
createAIChat();
245+
triggerContentTemplate();
243246

244247
const popupConfig = getPopupConfig();
248+
const clearButton = popupConfig.toolbarItems[0];
249+
clearButton.options.onClick();
245250

246-
expect(popupConfig.toolbarItems).toBeUndefined();
251+
expect(mockStore.clear).toHaveBeenCalledTimes(1);
252+
expect(mockDataSource.reload).toHaveBeenCalledTimes(1);
247253
});
248254
});
249255

@@ -780,8 +786,7 @@ describe('AIChat', () => {
780786
});
781787

782788
it('should disable clear button via popup toolbarItems option', () => {
783-
const onChatCleared = jest.fn();
784-
const { aiChat } = createAIChat({ onChatCleared });
789+
const { aiChat } = createAIChat();
785790
triggerContentTemplate();
786791

787792
aiChat.setDisabled(true);
@@ -790,8 +795,7 @@ describe('AIChat', () => {
790795
});
791796

792797
it('should enable clear button via popup toolbarItems option', () => {
793-
const onChatCleared = jest.fn();
794-
const { aiChat } = createAIChat({ onChatCleared });
798+
const { aiChat } = createAIChat();
795799
triggerContentTemplate();
796800

797801
aiChat.setDisabled(true);
@@ -800,18 +804,6 @@ describe('AIChat', () => {
800804
expect(mockClearChatButtonInstance.option).toHaveBeenCalledWith('disabled', false);
801805
});
802806

803-
it('should not update popup toolbarItems when onChatCleared is not provided', () => {
804-
const { aiChat } = createAIChat();
805-
triggerContentTemplate();
806-
807-
aiChat.setDisabled(true);
808-
809-
expect(mockClearChatButtonInstance.option).not.toHaveBeenCalledWith(
810-
'disabled',
811-
expect.anything(),
812-
);
813-
});
814-
815807
it('should not update when setting same disabled value', () => {
816808
const { aiChat } = createAIChat();
817809
triggerContentTemplate();

packages/devextreme/js/__internal/grids/grid_core/ai_chat/ai_chat.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import messageLocalization from '@js/common/core/localization/message';
44
import type { ArrayStore } from '@js/common/data';
55
import type { dxElementWrapper } from '@js/core/renderer';
66
import $ from '@js/core/renderer';
7+
import type { InitializedEvent } from '@js/ui/button';
8+
import type dxButton from '@js/ui/button';
79
import type { Message, Properties as ChatProperties } from '@js/ui/chat';
810
import Chat from '@js/ui/chat';
911
import type { Properties as PopupProperties, ToolbarItem } from '@js/ui/popup';
1012
import { MessageStatus } from '@ts/grids/grid_core/ai_assistant/const';
11-
import type Button from '@ts/ui/button';
1213
import {
1314
CHAT_MESSAGELIST_EMPTY_IMAGE_CLASS,
1415
CHAT_MESSAGELIST_EMPTY_MESSAGE_CLASS,
@@ -44,7 +45,7 @@ export class AIChat {
4445

4546
private chatInstance?: Chat;
4647

47-
private clearChatButtonInstance?: Button;
48+
private clearChatButtonInstance?: dxButton;
4849

4950
private disabled = false;
5051

@@ -124,12 +125,6 @@ export class AIChat {
124125
}
125126

126127
private getClearChatButton(): ToolbarItem | undefined {
127-
const { onChatCleared } = this.options;
128-
129-
if (!onChatCleared) {
130-
return undefined;
131-
}
132-
133128
return {
134129
widget: 'dxButton',
135130
toolbar: 'top',
@@ -138,8 +133,10 @@ export class AIChat {
138133
options: {
139134
icon: CLEAR_CHAT_ICON,
140135
hint: messageLocalization.format('dxDataGrid-aiAssistantClearButtonText'),
141-
onClick: onChatCleared,
142-
onInitialized: (e): void => {
136+
onClick: (): void => {
137+
this.clear();
138+
},
139+
onInitialized: (e: InitializedEvent): void => {
143140
this.clearChatButtonInstance = e.component;
144141
},
145142
},

packages/devextreme/js/__internal/grids/grid_core/ai_chat/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ export interface AIChatOptions {
1313
createComponent: CreateComponent<any>;
1414
popupOptions?: PopupProperties;
1515
chatOptions?: ChatProperties;
16-
onChatCleared?: () => void;
1716
onRegenerate?: (aiMessage: AIMessage) => void;
1817
}

0 commit comments

Comments
 (0)