Skip to content

Commit c4851b0

Browse files
authored
DataGrid - AI Column: Endless prompt editor loading when edit prompt and rollback changes (#31848)
1 parent e63954c commit c4851b0

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

packages/devextreme/js/__internal/grids/grid_core/ai_column/views/m_ai_prompt_editor_view.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,57 @@ describe('AIPromptEditorView', () => {
336336
true,
337337
);
338338
});
339+
340+
it('should not trigger loading state when prompt has not changed', async () => {
341+
const {
342+
cellElement,
343+
aiPromptEditorView,
344+
aiPromptEditorPOM,
345+
} = createAIPromptEditorView();
346+
const columnWithPrompt = {
347+
...mockColumn,
348+
index: 2,
349+
ai: { prompt: 'existing prompt' },
350+
};
351+
352+
await aiPromptEditorView.show(cellElement, columnWithPrompt);
353+
354+
aiPromptEditorPOM.getTextArea().setValue('existing prompt');
355+
aiPromptEditorPOM.getApplyButton().getElement().click();
356+
357+
expect(aiPromptEditorView.getPromptEditorInstance().updateStateOnAction)
358+
.not.toHaveBeenCalled();
359+
360+
expect(mockColumnsController.columnOption).not.toHaveBeenCalled();
361+
});
362+
363+
it('should trigger loading state only when prompt has changed', async () => {
364+
const {
365+
cellElement,
366+
aiPromptEditorView,
367+
aiPromptEditorPOM,
368+
} = createAIPromptEditorView();
369+
const columnWithPrompt = {
370+
...mockColumn,
371+
index: 2,
372+
ai: { prompt: 'old prompt' },
373+
};
374+
375+
await aiPromptEditorView.show(cellElement, columnWithPrompt);
376+
377+
aiPromptEditorPOM.getTextArea().setValue('new prompt');
378+
aiPromptEditorPOM.getApplyButton().getElement().click();
379+
380+
expect(aiPromptEditorView.getPromptEditorInstance().updateStateOnAction)
381+
.toHaveBeenCalledWith('apply');
382+
383+
expect(mockColumnsController.columnOption).toHaveBeenCalledWith(
384+
2,
385+
'ai.prompt',
386+
'new prompt',
387+
true,
388+
);
389+
});
339390
});
340391

341392
describe('onStop', () => {

packages/devextreme/js/__internal/grids/grid_core/ai_prompt_editor/ai_prompt_editor.integration.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,25 @@ describe('Regenerate Data button', () => {
261261
expect(POM.getRefreshButton().isDisabled()).toBe(false);
262262
});
263263
});
264+
265+
describe('when text area value is changed back to initial value', () => {
266+
it('should be enabled', () => {
267+
const { POM } = createAIPromptEditor({
268+
prompt: 'initial text',
269+
popupOptions: { visible: true },
270+
});
271+
272+
expect(POM.getRefreshButton().isDisabled()).toBe(false);
273+
274+
// Change value
275+
POM.getTextArea().setValue('changed text');
276+
expect(POM.getRefreshButton().isDisabled()).toBe(true);
277+
278+
// Change back to initial
279+
POM.getTextArea().setValue('initial text');
280+
expect(POM.getRefreshButton().isDisabled()).toBe(false);
281+
});
282+
});
264283
});
265284

266285
describe('Apply button', () => {
@@ -318,7 +337,7 @@ describe('Apply button', () => {
318337
});
319338

320339
describe('when text area value is changed back to initial value', () => {
321-
it('should be enabled', () => {
340+
it('should be disabled', () => {
322341
const { POM } = createAIPromptEditor({
323342
prompt: 'initial text',
324343
popupOptions: { visible: true },
@@ -332,7 +351,7 @@ describe('Apply button', () => {
332351

333352
// Change back to initial
334353
POM.getTextArea().setValue('initial text');
335-
expect(POM.getApplyButton().isDisabled()).toBe(false);
354+
expect(POM.getApplyButton().isDisabled()).toBe(true);
336355
});
337356
});
338357

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class AIPromptEditor {
5050
height: 110,
5151
stylingMode: 'outlined',
5252
onValueChanged: (e): void => {
53-
this.updateButtonOption(APPLY_BUTTON_INDEX, 'disabled', !e.value); // Update the disable state of the Apply button
54-
this.updateButtonOption(REGENERATE_DATA_BUTTON_INDEX, 'disabled', true); // Update the disable state of the Regenerate Data button
53+
this.updateButtonOption(APPLY_BUTTON_INDEX, 'disabled', !e.value || e.value === this.prompt); // Update the disable state of the Apply button
54+
this.updateButtonOption(REGENERATE_DATA_BUTTON_INDEX, 'disabled', !e.value || e.value !== this.prompt); // Update the disable state of the Regenerate Data button
5555
},
5656
placeholder: messageLocalization.format('dxDataGrid-aiPromptEditorPlaceholder'),
5757
valueChangeEvent: 'input change keyup',

0 commit comments

Comments
 (0)