Skip to content

Commit c05ce5a

Browse files
author
Alyar
committed
Fix emptyText/noDataText in manual mode
1 parent ebe83f4 commit c05ce5a

File tree

3 files changed

+103
-10
lines changed

3 files changed

+103
-10
lines changed

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

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,101 @@ describe('Options', () => {
487487
expect(component.getDataCell(1, 3).getText()).toBe('Test - Empty Data');
488488
});
489489
});
490+
491+
describe('when the noDataText is set and mode = "manual"', () => {
492+
it('should render this text', async () => {
493+
const { component, instance } = await createDataGrid({
494+
dataSource: [
495+
{ id: 1, name: 'Name 1', value: 10 },
496+
{ id: 2, name: 'Name 2', value: 20 },
497+
],
498+
keyExpr: 'id',
499+
columns: [
500+
{ dataField: 'id', caption: 'ID' },
501+
{ dataField: 'name', caption: 'Name' },
502+
{ dataField: 'value', caption: 'Value' },
503+
{
504+
type: 'ai',
505+
caption: 'AI Column',
506+
name: 'myColumn',
507+
cssClass: 'custom-class',
508+
ai: {
509+
prompt: 'Initial Prompt',
510+
noDataText: 'Test - No Data',
511+
mode: 'manual',
512+
aiIntegration: new AIIntegration({
513+
sendRequest(): RequestResult {
514+
return {
515+
promise: new Promise<string>((resolve) => {
516+
resolve('{"1":"","2":""}');
517+
}),
518+
abort: (): void => {},
519+
};
520+
},
521+
}),
522+
},
523+
},
524+
],
525+
});
526+
527+
expect(component.getDataCell(0, 3).getText()).toBe(EMPTY_CELL_TEXT);
528+
expect(component.getDataCell(1, 3).getText()).toBe(EMPTY_CELL_TEXT);
529+
530+
instance.sendAIColumnRequest('myColumn');
531+
await Promise.resolve();
532+
533+
expect(component.getDataCell(0, 3).getText()).toBe('Test - No Data');
534+
expect(component.getDataCell(1, 3).getText()).toBe('Test - No Data');
535+
});
536+
});
537+
538+
describe('when the emptyText is set and mode = "manual"', () => {
539+
it('should render this text', async () => {
540+
const { component, instance } = await createDataGrid({
541+
keyExpr: 'id',
542+
dataSource: [
543+
{ id: 1, name: 'Name 1', value: 10 },
544+
{ id: 2, name: 'Name 2', value: 20 },
545+
],
546+
columns: [
547+
{ dataField: 'id', caption: 'ID' },
548+
{ dataField: 'name', caption: 'Name' },
549+
{ dataField: 'value', caption: 'Value' },
550+
{
551+
type: 'ai',
552+
caption: 'AI Column',
553+
name: 'myColumn',
554+
cssClass: 'custom-class',
555+
ai: {
556+
emptyText: 'Test - Empty Data',
557+
noDataText: 'Test - No Data',
558+
mode: 'manual',
559+
aiIntegration: new AIIntegration({
560+
sendRequest(): RequestResult {
561+
return {
562+
promise: new Promise<string>((resolve) => {
563+
resolve('{"1":"","2":""}');
564+
}),
565+
abort: (): void => {},
566+
};
567+
},
568+
}),
569+
},
570+
},
571+
],
572+
});
573+
574+
expect(component.getDataCell(0, 3).getText()).toBe('Test - Empty Data');
575+
expect(component.getDataCell(1, 3).getText()).toBe('Test - Empty Data');
576+
577+
instance.columnOption('myColumn', 'ai.prompt', 'Updated Prompt');
578+
instance.sendAIColumnRequest('myColumn');
579+
await Promise.resolve();
580+
581+
expect(component.getDataCell(0, 3).getText()).toBe('Test - No Data');
582+
expect(component.getDataCell(1, 3).getText()).toBe('Test - No Data');
583+
});
584+
});
490585
});
491586

492587
describe('columnOption', () => {
@@ -3750,12 +3845,12 @@ describe('Cache', () => {
37503845
instance.sendAIColumnRequest('myColumn');
37513846
await Promise.resolve();
37523847
expect(sendRequestSpy).toHaveBeenCalledTimes(1);
3753-
expect(instance.getAIColumnText('myColumn', 1)).toBeUndefined();
3848+
expect(instance.getAIColumnText('myColumn', 1)).toBe('');
37543849

37553850
instance.sendAIColumnRequest('myColumn');
37563851
await Promise.resolve();
37573852
expect(sendRequestSpy).toHaveBeenCalledTimes(2);
3758-
expect(instance.getAIColumnText('myColumn', 1)).toBeUndefined();
3853+
expect(instance.getAIColumnText('myColumn', 1)).toBe('');
37593854
});
37603855
});
37613856
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export class AIColumnCacheController extends Controller {
2525
data: Record<PropertyKey, string>,
2626
): void {
2727
let columnCache = this.cache[columnName];
28+
2829
if (!columnCache) {
2930
columnCache = {};
3031
this.cache[columnName] = columnCache;
3132
}
33+
3234
Object.entries(data).forEach(([key, value]) => {
33-
if (columnCache && value !== '') {
34-
columnCache[key] = value;
35-
}
35+
columnCache[key] = value;
3636
});
3737
}
3838

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ 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) {
30+
private getDefaultCellValue(column: Column, cellValue: string | undefined): string | null {
31+
if (cellValue === undefined) {
3432
return column.ai?.emptyText ?? null;
3533
}
3634

@@ -46,7 +44,7 @@ export class AIColumnController extends Controller {
4644
calculateCellValue(data: UserData) {
4745
const key = dataController.keyOf(data);
4846
const cellValue = aiColumnIntegrationController.getAIColumnText(this.name, key);
49-
const defaultValue = that.getDefaultCellValue(this);
47+
const defaultValue = that.getDefaultCellValue(this, cellValue);
5048

5149
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5250
return cellValue || defaultValue;

0 commit comments

Comments
 (0)