Skip to content

Commit d73dc77

Browse files
author
Alyar
committed
Add new options - noDataText and emptyText
1 parent 7acc438 commit d73dc77

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,83 @@ describe('Options', () => {
408408
expect(headerCell.getDropDownButton().getElement()).toBeNull();
409409
});
410410
});
411+
412+
describe('when the noDataText is set', () => {
413+
it('should render this text', async () => {
414+
const { component } = await createDataGrid({
415+
dataSource: [
416+
{ id: 1, name: 'Name 1', value: 10 },
417+
{ id: 2, name: 'Name 2', value: 20 },
418+
],
419+
columns: [
420+
{ dataField: 'id', caption: 'ID' },
421+
{ dataField: 'name', caption: 'Name' },
422+
{ dataField: 'value', caption: 'Value' },
423+
{
424+
type: 'ai',
425+
caption: 'AI Column',
426+
name: 'myColumn',
427+
cssClass: 'custom-class',
428+
ai: {
429+
prompt: 'Initial Prompt',
430+
noDataText: 'Test - No Data',
431+
aiIntegration: new AIIntegration({
432+
sendRequest(): RequestResult {
433+
return {
434+
promise: new Promise<string>((resolve) => {
435+
resolve('');
436+
}),
437+
abort: (): void => {},
438+
};
439+
},
440+
}),
441+
},
442+
},
443+
],
444+
});
445+
446+
expect(component.getDataCell(0, 3).getText()).toBe('Test - No Data');
447+
expect(component.getDataCell(1, 3).getText()).toBe('Test - No Data');
448+
});
449+
});
450+
451+
describe('when the emptyText is set', () => {
452+
it('should render this text', async () => {
453+
const { component } = await createDataGrid({
454+
dataSource: [
455+
{ id: 1, name: 'Name 1', value: 10 },
456+
{ id: 2, name: 'Name 2', value: 20 },
457+
],
458+
columns: [
459+
{ dataField: 'id', caption: 'ID' },
460+
{ dataField: 'name', caption: 'Name' },
461+
{ dataField: 'value', caption: 'Value' },
462+
{
463+
type: 'ai',
464+
caption: 'AI Column',
465+
name: 'myColumn',
466+
cssClass: 'custom-class',
467+
ai: {
468+
emptyText: 'Test - Empty Data',
469+
aiIntegration: new AIIntegration({
470+
sendRequest(): RequestResult {
471+
return {
472+
promise: new Promise<string>((resolve) => {
473+
resolve('');
474+
}),
475+
abort: (): void => {},
476+
};
477+
},
478+
}),
479+
},
480+
},
481+
],
482+
});
483+
484+
expect(component.getDataCell(0, 3).getText()).toBe('Test - Empty Data');
485+
expect(component.getDataCell(1, 3).getText()).toBe('Test - Empty Data');
486+
});
487+
});
411488
});
412489

413490
describe('columnOption', () => {

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { GenerateGridColumnCommandResult, RequestCallbacks } from '@js/comm
33
import type { Callback } from '@js/core/utils/callbacks';
44

55
import type { Column, ColumnsController } from '../columns_controller/m_columns_controller';
6-
import type { DataController, HandleDataChangedArguments } from '../data_controller/m_data_controller';
6+
import type { DataController, HandleDataChangedArguments, UserData } from '../data_controller/m_data_controller';
77
import { Controller } from '../m_modules';
88
import { AIColumnIntegrationController } from './m_ai_column_integration_controller';
99
import { getAICommandColumnDefaultOptions, isAIColumnAutoMode, isPromptOption } from './utils';
@@ -27,16 +27,29 @@ export class AIColumnController extends Controller {
2727

2828
public aiRequestRejected!: Callback;
2929

30+
private getDefaultCellValue(column: Column): string | null {
31+
const prompt = column.ai?.prompt;
32+
33+
if (!prompt) {
34+
return column.ai?.emptyText ?? null;
35+
}
36+
37+
return column.ai?.noDataText ?? null;
38+
}
39+
3040
private addAICommandColumn(): void {
41+
const that = this;
3142
const { dataController, aiColumnIntegrationController } = this;
3243

3344
this.columnsController.addCommandColumn({
3445
...getAICommandColumnDefaultOptions(),
35-
calculateCellValue(data) {
46+
calculateCellValue(data: UserData) {
3647
const key = dataController.keyOf(data);
3748
const cellValue = aiColumnIntegrationController.getAIColumnText(this.name, key);
49+
const defaultValue = that.getDefaultCellValue(this);
3850

39-
return cellValue ?? null;
51+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
52+
return cellValue || defaultValue;
4053
},
4154
});
4255
}

0 commit comments

Comments
 (0)