Skip to content

Commit 6cf79c5

Browse files
committed
fix review remarks
1 parent 1168cf0 commit 6cf79c5

5 files changed

Lines changed: 32 additions & 35 deletions

File tree

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ export class AIAssistantController extends Controller {
3838

3939
private getCustomizedResponseTitle(
4040
status: MessageStatus.Success | MessageStatus.Failure,
41-
commandNames: GridCommand['name'][],
41+
commandNames: string[],
4242
): string {
4343
// TODO: remove type description, it should be got from d.ts
4444
const customizeResponseTitle = this.option('aiAssistant.customizeResponseTitle') as CustomizeResponseTitle | undefined;
4545

46-
// There shouldn't be an empty array here, but we need to handle it anyway.
4746
if (!commandNames.length) {
4847
return messageLocalization.format('dxDataGrid-aiAssistantErrorMessage');
4948
}
@@ -63,7 +62,7 @@ export class AIAssistantController extends Controller {
6362
].join(' and ');
6463
}
6564

66-
private getCommandNames(actions: ExecuteGridAssistantAction[]): GridCommand['name'][] {
65+
private getCommandNames(actions: ExecuteGridAssistantAction[]): string[] {
6766
const commandNames = actions.map(({ name }) => name);
6867
const uniqueCommandNameSet = new Set(commandNames);
6968

@@ -131,7 +130,7 @@ export class AIAssistantController extends Controller {
131130
private completeAIMessage(
132131
messageId: string,
133132
commands: CommandResult[],
134-
commandNames: GridCommand['name'][],
133+
commandNames: string[],
135134
): void {
136135
const messageStatus = hasCommandErrors(commands)
137136
? MessageStatus.Failure
@@ -174,10 +173,16 @@ export class AIAssistantController extends Controller {
174173
});
175174
}
176175

177-
private sendRequestToAICore(aiMessage: AIMessage): Promise<void> {
176+
private withProcessing(promise: Promise<void>): Promise<void> {
178177
this.setProcessing(true);
179178

180-
return new Promise((resolve, reject) => {
179+
return promise.finally(() => {
180+
this.setProcessing(false);
181+
});
182+
}
183+
184+
private sendRequestToAICore(aiMessage: AIMessage): Promise<void> {
185+
return this.withProcessing(new Promise<void>((resolve, reject) => {
181186
const responseSchema = this.gridCommands?.buildResponseSchema();
182187
const extraContext = this.getGridExtraContext();
183188

@@ -186,7 +191,6 @@ export class AIAssistantController extends Controller {
186191
const error = new Error('Grid commands not initialized');
187192

188193
this.failAIMessage(aiMessage.id, error);
189-
this.setProcessing(false);
190194
reject(error);
191195
return;
192196
}
@@ -202,36 +206,32 @@ export class AIAssistantController extends Controller {
202206
const commandNames = this.getCommandNames(response.actions);
203207

204208
this.completeAIMessage(aiMessage.id, commands, commandNames);
205-
this.setProcessing(false);
206209
resolve();
207210
})
208211
.fail((errorMessage) => {
209-
// TODO: Change error message
212+
// TODO: Change error message
210213
const error = errorMessage instanceof Error
211214
? errorMessage
212215
: new Error(String(errorMessage));
213216

214217
this.failAIMessage(aiMessage.id, error);
215-
this.setProcessing(false);
216218
reject(error);
217219
});
218220
},
219221
onError: (error: Error): void => {
220-
// TODO: Change error message
222+
// TODO: Change error message
221223
this.failAIMessage(aiMessage.id, error);
222-
this.setProcessing(false);
223224
reject(error);
224225
},
225226
onAbort: (): void => {
226227
const error = new Error(messageLocalization.format('dxDataGrid-aiAssistantAbortMessage'));
227228

228229
this.failAIMessage(aiMessage.id, error);
229-
this.setProcessing(false);
230230
reject(error);
231231
},
232232
},
233233
);
234-
});
234+
}));
235235
}
236236

237237
protected getGridCommandList(): GridCommand[] {
@@ -243,7 +243,6 @@ export class AIAssistantController extends Controller {
243243
}
244244

245245
public init(): void {
246-
// TODO: initialize default commands list when they are ready
247246
this.gridCommands = new GridCommands(this.component, this.getGridCommandList());
248247
this.messageStore = new ArrayStore<Message, string>({
249248
key: 'id',

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
AIAssistantRequestCallbacks,
1212
GridColumnContext,
1313
GridColumnContextOptional,
14-
GridContext,
1514
GridContextOptional,
1615
GridExtraContextOption,
1716
JsonSchema,
@@ -56,13 +55,8 @@ export class AIAssistantIntegrationController extends Controller {
5655
}
5756

5857
const context = this.buildContext(extraContext);
59-
const args: {
60-
context: Record<string, unknown>;
61-
responseSchema: JsonSchema;
62-
cancel: boolean;
63-
additionalInfo: Record<string, unknown>;
64-
} = {
65-
context: context as unknown as Record<string, unknown>,
58+
const args = {
59+
context,
6660
responseSchema,
6761
cancel: false,
6862
additionalInfo: {},
@@ -126,10 +120,9 @@ export class AIAssistantIntegrationController extends Controller {
126120
this.abort = undefined;
127121
}
128122

129-
public buildContext(extraContext: GridExtraContextOption | null): GridContext {
123+
// TODO: fix return type
124+
public buildContext(extraContext: GridExtraContextOption | null): Record<string, unknown> {
130125
const dataController = this.getController('data');
131-
const selectedRowKeys = (this.option('selectedRowKeys') ?? []) as (string | number)[];
132-
const searchText = this.option('searchPanel.text') ?? '';
133126
const gridExtraContext = this.getGridExtraContext(extraContext?.grid);
134127

135128
return {
@@ -143,10 +136,10 @@ export class AIAssistantIntegrationController extends Controller {
143136
totalCount: dataController.totalCount(),
144137
},
145138
search: {
146-
searchText,
139+
searchText: this.option('searchPanel.text') ?? '',
147140
},
148141
selection: {
149-
selectedRowKeys,
142+
selectedRowKeys: this.option('selectedRowKeys') ?? [],
150143
},
151144
...gridExtraContext,
152145
};
@@ -170,7 +163,6 @@ export class AIAssistantIntegrationController extends Controller {
170163
visible: column.visible !== false,
171164
sortOrder: column.sortOrder,
172165
sortIndex: column.sortIndex,
173-
filterValue: column.filterValue,
174166
fixed: column.fixed,
175167
fixedPosition: column.fixedPosition,
176168
width: column.width,
@@ -195,7 +187,6 @@ export class AIAssistantIntegrationController extends Controller {
195187
context.summary = {
196188
totalItems: this.option('summary.totalItems'),
197189
groupItems: this.option('summary.groupItems'),
198-
skipEmptyValues: this.option('summary.skipEmptyValues'),
199190
};
200191
break;
201192
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export type CustomizeResponseText = (
6666
// TODO: move to d.ts
6767
export type CustomizeResponseTitle = (
6868
status: MessageStatus.Success | MessageStatus.Failure,
69-
commandNames: GridCommand['name'][],
69+
commandNames: string[],
7070
) => string;
7171

7272
export type AIAssistantRequestCallbacks<T> = RequestCallbacks<T> & {
@@ -84,7 +84,6 @@ export interface GridColumnContext extends GridColumnContextOptional {
8484
visible: boolean;
8585
sortOrder: SortOrder | undefined;
8686
sortIndex: number | undefined;
87-
filterValue: string | number | boolean | null | undefined;
8887
fixed: boolean | undefined;
8988
fixedPosition: FixedPosition | undefined;
9089
width: number | string | undefined;
@@ -95,14 +94,13 @@ export interface GridContextOptional {
9594
summary?: {
9695
totalItems: SummaryTotalItem[] | undefined;
9796
groupItems: SummaryGroupItem[] | undefined;
98-
skipEmptyValues: SummaryGroupItem['skipEmptyValues'] | undefined;
9997
};
10098
}
10199

102100
export interface GridContext extends GridContextOptional {
103101
columns: GridColumnContext[];
104102
filtering: {
105-
filterValue: string | unknown[] | Function | null | undefined;
103+
filterValue: unknown
106104
};
107105
paging: {
108106
pageIndex: number;
@@ -113,7 +111,7 @@ export interface GridContext extends GridContextOptional {
113111
searchText: string;
114112
};
115113
selection: {
116-
selectedRowKeys: (string | number)[];
114+
selectedRowKeys: unknown[];
117115
};
118116
}
119117

packages/devextreme/js/common/grids.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ export type AIAssistantRequestCreatingInfo = {
128128
* @type object
129129
*/
130130
responseSchema: Record<string, any>;
131+
/**
132+
* @docid
133+
* @type object
134+
*/
135+
additionalInfo?: Record<string, any>;
131136
};
132137

133138
/**

packages/devextreme/ts/dx.all.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,10 @@ declare module DevExpress.common.grids {
46604660
* [descr:AIAssistantRequestCreatingInfo.responseSchema]
46614661
*/
46624662
responseSchema: Record<string, any>;
4663+
/**
4664+
* [descr:AIAssistantRequestCreatingInfo.additionalInfo]
4665+
*/
4666+
additionalInfo?: Record<string, any>;
46634667
};
46644668
export type AIColumnMode = 'auto' | 'manual';
46654669
/**

0 commit comments

Comments
 (0)