Skip to content

Commit c33fe9e

Browse files
author
Alyar
committed
Rename AIPrompEditor.value -> AIPrompEditor.prompt
1 parent 758fde1 commit c33fe9e

6 files changed

Lines changed: 42 additions & 42 deletions

File tree

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('AiPromptEditor', () => {
175175
const onRefreshMock = jest.fn();
176176

177177
const { POM } = createAiPromptEditor({
178-
value: 'test',
178+
prompt: 'test',
179179
popupOptions: { visible: true },
180180
onRefresh: onRefreshMock,
181181
});
@@ -243,7 +243,7 @@ describe('Regenerate Data button', () => {
243243
describe('when initial value is empty string', () => {
244244
it('should be disabled', () => {
245245
const { POM } = createAiPromptEditor({
246-
value: '',
246+
prompt: '',
247247
popupOptions: { visible: true },
248248
});
249249

@@ -254,7 +254,7 @@ describe('Regenerate Data button', () => {
254254
describe('when initial value is provided', () => {
255255
it('should be enabled', () => {
256256
const { POM } = createAiPromptEditor({
257-
value: 'initial text',
257+
prompt: 'initial text',
258258
popupOptions: { visible: true },
259259
});
260260

@@ -280,7 +280,7 @@ describe('Apply button', () => {
280280
describe('when initial value is provided', () => {
281281
it('should be disabled', () => {
282282
const { POM } = createAiPromptEditor({
283-
value: 'initial text',
283+
prompt: 'initial text',
284284
popupOptions: { visible: true },
285285
});
286286

@@ -305,7 +305,7 @@ describe('Apply button', () => {
305305
describe('when text area value changes from non-empty', () => {
306306
it('should be enabled', () => {
307307
const { POM } = createAiPromptEditor({
308-
value: 'initial text',
308+
prompt: 'initial text',
309309
popupOptions: { visible: true },
310310
});
311311

@@ -320,7 +320,7 @@ describe('Apply button', () => {
320320
describe('when text area value is changed back to initial value', () => {
321321
it('should be disabled', () => {
322322
const { POM } = createAiPromptEditor({
323-
value: 'initial text',
323+
prompt: 'initial text',
324324
popupOptions: { visible: true },
325325
});
326326

@@ -642,24 +642,24 @@ describe('Public Methods', () => {
642642
});
643643
});
644644

645-
describe('when updateValue is called', () => {
645+
describe('when updatePrompt is called', () => {
646646
it('should update internal value and enable Regenerate Data button', () => {
647647
const { instance, POM } = createAiPromptEditor({
648648
popupOptions: { visible: true },
649649
});
650650

651-
instance.updateValue('new value');
651+
instance.updatePrompt('new value');
652652

653653
expect(POM.getTextArea().value).toBe('new value');
654654
});
655655

656656
it('should update internal value and disable Regenerate Data button', () => {
657657
const { instance, POM } = createAiPromptEditor({
658-
value: 'initial text',
658+
prompt: 'initial text',
659659
popupOptions: { visible: true },
660660
});
661661

662-
instance.updateValue('');
662+
instance.updatePrompt('');
663663

664664
expect(POM.getTextArea().value).toBe('');
665665
});
@@ -692,7 +692,7 @@ describe('Public Methods', () => {
692692
describe('when updateOptions is called', () => {
693693
it('should update the prompt editor options', async () => {
694694
const { container, instance, POM } = createAiPromptEditor({
695-
value: 'updated prompt',
695+
prompt: 'updated prompt',
696696
popupOptions: { visible: true },
697697
});
698698

@@ -705,7 +705,7 @@ describe('Public Methods', () => {
705705

706706
instance.updateOptions({
707707
container,
708-
value: '',
708+
prompt: '',
709709
createComponent: createComponentMock,
710710
popupOptions: { visible: true },
711711
});
@@ -747,7 +747,7 @@ describe('Public Methods', () => {
747747
describe('with apply action', () => {
748748
it('should set loading, disable controls and hide apply button', () => {
749749
const { instance, POM } = createAiPromptEditor({
750-
value: 'initial text',
750+
prompt: 'initial text',
751751
popupOptions: { visible: true },
752752
});
753753

@@ -778,7 +778,7 @@ describe('Public Methods', () => {
778778
describe('with regenerate action', () => {
779779
it('should set loading and disable controls', () => {
780780
const { instance, POM } = createAiPromptEditor({
781-
value: 'initial text',
781+
prompt: 'initial text',
782782
popupOptions: { visible: true },
783783
});
784784

@@ -808,7 +808,7 @@ describe('Public Methods', () => {
808808
describe('without action parameter', () => {
809809
it('should clear loading, enable controls and show apply button', () => {
810810
const { instance, POM } = createAiPromptEditor({
811-
value: 'initial text',
811+
prompt: 'initial text',
812812
popupOptions: { visible: true },
813813
});
814814

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import TextArea from '@js/ui/text_area';
99

1010
import { CLASSES, DEFAULT_POPUP_OPTIONS } from './const';
1111
import type { AiPromptEditorAction, AiPromptEditorOptions } from './types';
12-
import { getValue, isValueChanged } from './utils';
12+
import { getPrompt, isPromptChanged } from './utils';
1313

1414
export class AiPromptEditor {
1515
private readonly popupInstance: Popup;
@@ -18,15 +18,15 @@ export class AiPromptEditor {
1818

1919
private progressBar!: ProgressBar;
2020

21-
private value: string;
21+
private prompt: string;
2222

2323
constructor(
2424
private options: AiPromptEditorOptions,
2525
) {
2626
const { container, createComponent } = options;
2727

2828
container.addClass(CLASSES.aiPromptEditor);
29-
this.value = getValue(options.value);
29+
this.prompt = getPrompt(options.prompt);
3030
this.popupInstance = createComponent(container, Popup, this.getPopupConfig());
3131
}
3232

@@ -40,11 +40,11 @@ export class AiPromptEditor {
4040

4141
private getTextAreaConfig(): TextAreaProperties {
4242
return {
43-
value: this.value,
43+
value: this.prompt,
4444
minHeight: 80,
4545
height: '100%',
4646
onValueChanged: (e): void => {
47-
this.updateButtonOption(1, 'disabled', !isValueChanged(this.value, e.value)); // Update the disable state of the Apply button
47+
this.updateButtonOption(1, 'disabled', !isPromptChanged(this.prompt, e.value)); // Update the disable state of the Apply button
4848
},
4949
placeholder: messageLocalization.format('dxDataGrid-aiPromptEditorPlaceholder'),
5050
valueChangeEvent: 'input change keyup',
@@ -117,7 +117,7 @@ export class AiPromptEditor {
117117
icon: 'arrowright',
118118
stylingMode: 'contained',
119119
text: messageLocalization.format('dxDataGrid-applyButton'),
120-
disabled: !this.editorInstance || !isValueChanged(this.value, this.editorInstance.option('value')),
120+
disabled: !this.editorInstance || !isPromptChanged(this.prompt, this.editorInstance.option('value')),
121121
elementAttr: {
122122
class: CLASSES.aiPromptEditorApplyButton,
123123
},
@@ -130,7 +130,7 @@ export class AiPromptEditor {
130130
icon: 'refresh',
131131
stylingMode: 'outlined',
132132
text: messageLocalization.format('dxDataGrid-regenerateDataButton'),
133-
disabled: !this.value,
133+
disabled: !this.prompt,
134134
elementAttr: {
135135
class: CLASSES.aiPromptEditorRefreshButton,
136136
},
@@ -151,16 +151,16 @@ export class AiPromptEditor {
151151
};
152152
}
153153

154-
private setValue(value: string): void {
155-
this.value = getValue(value);
154+
private setPrompt(prompt: string): void {
155+
this.prompt = getPrompt(prompt);
156156
}
157157

158158
private toggleDisableState(disabled: boolean): void {
159-
this.updateButtonOption(0, 'disabled', disabled ? true : !this.value); // Update the disable state of the Regenerate data button
159+
this.updateButtonOption(0, 'disabled', disabled ? true : !this.prompt); // Update the disable state of the Regenerate data button
160160
this.updateButtonOption(
161161
1,
162162
'disabled',
163-
disabled ? true : !isValueChanged(this.value, this.editorInstance.option('value')),
163+
disabled ? true : !isPromptChanged(this.prompt, this.editorInstance.option('value')),
164164
); // Update the disable state of the Apply button
165165
this.editorInstance.option('disabled', disabled); // Update TextArea disable state
166166
this.popupInstance.option('shading', disabled);
@@ -192,9 +192,9 @@ export class AiPromptEditor {
192192
this.progressBar.option('visible', isLoading);
193193
}
194194

195-
public updateValue(value: string): void {
196-
this.setValue(value);
197-
this.editorInstance.option('value', value);
195+
public updatePrompt(prompt: string): void {
196+
this.setPrompt(prompt);
197+
this.editorInstance.option('value', prompt);
198198
}
199199

200200
/**
@@ -221,7 +221,7 @@ export class AiPromptEditor {
221221

222222
public updateOptions(options: AiPromptEditorOptions): void {
223223
this.options = options;
224-
this.updateValue(getValue(options.value));
224+
this.updatePrompt(getPrompt(options.prompt));
225225
this.popupInstance.option(this.getPopupConfig());
226226
}
227227
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface AiPromptEditorOptions {
88
container: dxElementWrapper;
99
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1010
createComponent: CreateComponent<any>;
11-
value?: string;
11+
prompt?: string;
1212
onSubmit?: () => void;
1313
onRefresh?: () => void;
1414
onStop?: () => void;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export const getValue = (value: string | undefined): string => value ?? '';
1+
export const getPrompt = (prompt: string | undefined): string => prompt ?? '';
22

3-
export const isValueChanged = (
4-
initialValue: string | undefined,
5-
currentValue: string | undefined,
6-
): boolean => getValue(initialValue) !== getValue(currentValue);
3+
export const isPromptChanged = (
4+
initialPrompt: string | undefined,
5+
currentPrompt: string | undefined,
6+
): boolean => getPrompt(initialPrompt) !== getPrompt(currentPrompt);

packages/devextreme/js/__internal/grids/grid_core/ai_column/m_ai_column_view.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('AiColumnView', () => {
147147

148148
expect(AiPromptEditor).toHaveBeenCalledTimes(1);
149149
expect(AiPromptEditor).toHaveBeenCalledWith({
150-
value: '',
150+
prompt: '',
151151
container: aiColumnView.element(),
152152
createComponent: expect.any(Function),
153153
onStop: expect.any(Function),
@@ -496,7 +496,7 @@ describe('AiColumnView', () => {
496496
value: 'new prompt value',
497497
});
498498

499-
expect(promptEditorInstance.updateValue).toHaveBeenCalledWith('new prompt value');
499+
expect(promptEditorInstance.updatePrompt).toHaveBeenCalledWith('new prompt value');
500500
expect(mockAiColumnController.sendAIColumnRequest).toHaveBeenCalledWith('aiColumn');
501501
});
502502

@@ -523,7 +523,7 @@ describe('AiColumnView', () => {
523523

524524
const promptEditorInstance = aiColumnView.getPromptEditorInstance();
525525

526-
expect(promptEditorInstance.updateValue).toHaveBeenCalledWith('new prompt value');
526+
expect(promptEditorInstance.updatePrompt).toHaveBeenCalledWith('new prompt value');
527527
expect(promptEditorInstance.updateStateOnAction).toHaveBeenCalledTimes(1);
528528
});
529529

@@ -550,7 +550,7 @@ describe('AiColumnView', () => {
550550

551551
const promptEditorInstance = aiColumnView.getPromptEditorInstance();
552552

553-
expect(promptEditorInstance.updateValue).toHaveBeenCalledWith('new prompt value');
553+
expect(promptEditorInstance.updatePrompt).toHaveBeenCalledWith('new prompt value');
554554
expect(promptEditorInstance.updateStateOnAction).toHaveBeenCalledTimes(1);
555555
expect(promptEditorInstance.updateStateOnAction).toHaveBeenCalledWith();
556556
});

packages/devextreme/js/__internal/grids/grid_core/ai_column/m_ai_column_view.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class AiColumnView extends View {
2828
const alignment = column.alignment === 'right' ? 'left' : 'right';
2929

3030
return {
31-
value: column.ai?.prompt ?? '',
31+
prompt: column.ai?.prompt ?? '',
3232
container: this.element(),
3333
createComponent: this._createComponent.bind(this),
3434
onSubmit: (): void => {
@@ -80,7 +80,7 @@ export class AiColumnView extends View {
8080
const columnOptionName = this.columnsController.getColumnOptionNameByFullName(args.fullName);
8181

8282
if (columnOptionName === 'ai.prompt') {
83-
this.promptEditorInstance?.updateValue(args.value);
83+
this.promptEditorInstance?.updatePrompt(args.value);
8484
this.aiColumnController.sendAIColumnRequest(column.name as string);
8585
}
8686
}

0 commit comments

Comments
 (0)