Skip to content

Commit b768d5f

Browse files
dmlvrCopilot
andauthored
DataGrid - AI Column is empty in the adaptive row (#31909)
Signed-off-by: Dmitry Lavrinovich <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 21c86f3 commit b768d5f

File tree

4 files changed

+122
-5
lines changed

4 files changed

+122
-5
lines changed

e2e/testcafe-devextreme/tests/dataGrid/common/aiColumn/adaptivity.functional.ts

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import DataGrid from 'devextreme-testcafe-models/dataGrid';
2+
import { ClientFunction } from 'testcafe';
23
import url from '../../../../helpers/getPageUrl';
34
import { createWidget } from '../../../../helpers/createWidget';
45

5-
fixture.disablePageReloads`Ai Column.Adaptivity`
6-
.page(url(__dirname, '../../../container.html'));
6+
fixture`Ai Column.Adaptivity`
7+
.page(url(__dirname, './pages/containerWithAIIntegration.html'));
78

89
const DATA_GRID_SELECTOR = '#container';
910

11+
const resolveAIRequest = ClientFunction((): void => {
12+
const { aiResponseData } = (window as any);
13+
const { aiResolve } = (window as any);
14+
15+
if (aiResponseData && aiResolve) {
16+
aiResolve(aiResponseData);
17+
18+
(window as any).aiResponseData = null;
19+
(window as any).aiResolve = null;
20+
}
21+
});
22+
23+
const deleteGlobalVariables = ClientFunction((): void => {
24+
delete (window as any).aiResponseData;
25+
delete (window as any).aiResolve;
26+
});
27+
1028
test('The AI column should be hidden when columnHidingEnabled is true', async (t) => {
1129
// arrange, act
1230
const dataGrid = new DataGrid(DATA_GRID_SELECTOR);
@@ -129,3 +147,79 @@ test('The AI column should not be hidden when there is a second AI column with a
129147
{ dataField: 'value', caption: 'Value' },
130148
],
131149
}));
150+
151+
test('The AI column should have value in the adaptive detail row', async (t) => {
152+
const dataGrid = new DataGrid(DATA_GRID_SELECTOR);
153+
154+
// act
155+
await resolveAIRequest();
156+
157+
// assert
158+
await t.expect(dataGrid.isReady()).ok();
159+
160+
const adaptiveButton = dataGrid.getAdaptiveButton();
161+
162+
await t.expect(adaptiveButton.exists).ok();
163+
164+
await t.click(adaptiveButton);
165+
166+
const adaptiveRow = dataGrid.getAdaptiveRow(0);
167+
168+
await t.expect(adaptiveRow.element.exists).ok();
169+
170+
const aiFormItem = adaptiveRow.getAdaptiveCellByText('AI Column');
171+
172+
await t.expect(aiFormItem.element.exists).ok();
173+
174+
await t.expect(aiFormItem.getAdaptiveCellValue()).contains('Response 1');
175+
}).before(async () => createWidget('dxDataGrid', () => ({
176+
dataSource: [
177+
{ id: 1, name: 'Name 1', value: 10 },
178+
{ id: 2, name: 'Name 2', value: 20 },
179+
{ id: 3, name: 'Name 3', value: 30 },
180+
],
181+
keyExpr: 'id',
182+
width: 400,
183+
columnHidingEnabled: true,
184+
showBorders: true,
185+
columns: [
186+
{
187+
dataField: 'id', caption: 'ID', width: 150, hidingPriority: 3,
188+
},
189+
{
190+
dataField: 'name', caption: 'Name', width: 150, hidingPriority: 2,
191+
},
192+
{
193+
dataField: 'value', caption: 'Value', width: 100, hidingPriority: 1,
194+
},
195+
{
196+
name: 'AIcolumn',
197+
caption: 'AI Column',
198+
type: 'ai',
199+
ai: {
200+
prompt: 'Send me nothing',
201+
// eslint-disable-next-line new-cap
202+
aiIntegration: new (window as any).DevExpress.aiIntegration({
203+
sendRequest({ data }) {
204+
return {
205+
promise: new Promise<string>((resolve) => {
206+
const obj = {};
207+
Object.entries(data?.data).forEach(([key, value]) => {
208+
obj[key] = `Response ${(value as any).id}`;
209+
});
210+
211+
(window as any).aiResponseData = JSON.stringify(obj);
212+
(window as any).aiResolve = resolve;
213+
}),
214+
abort: (): void => {},
215+
};
216+
},
217+
}),
218+
},
219+
width: 200,
220+
hidingPriority: 0,
221+
},
222+
],
223+
}))).after(async () => {
224+
await deleteGlobalVariables();
225+
});

packages/devextreme/js/__internal/grids/grid_core/adaptivity/m_adaptivity.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { isMaterial } from '@js/ui/themes';
1919
import type { ResizingController } from '@ts/grids/grid_core/views/m_grid_view';
2020

2121
import type { ExportController } from '../../data_grid/export/m_export';
22+
import { AI_COLUMN_NAME } from '../ai_column/const';
2223
import type { Column, ColumnsController } from '../columns_controller/m_columns_controller';
2324
import type { ColumnsResizerViewController, DraggingHeaderViewController } from '../columns_resizing_reordering/m_columns_resizing_reordering';
2425
import type { DataController } from '../data_controller/m_data_controller';
@@ -160,6 +161,10 @@ export class AdaptiveColumnsController extends modules.ViewController {
160161
return ['isAdaptiveDetailRowExpanded', 'expandAdaptiveDetailRow', 'collapseAdaptiveDetailRow'];
161162
}
162163

164+
private _getValueFromCellOptions(columnIndex: number, cellOptions: any) {
165+
return cellOptions.row.values[columnIndex];
166+
}
167+
163168
private _isRowEditMode() {
164169
const editMode = this._getEditMode();
165170
return editMode === EDIT_MODE_ROW;
@@ -183,7 +188,12 @@ export class AdaptiveColumnsController extends modules.ViewController {
183188
}
184189
});
185190
const rowData = cellOptions.row.data;
186-
const value = column.calculateCellValue(rowData);
191+
const columnIndex = that._columnsController.getVisibleIndex(column.index);
192+
193+
const value = column.type === AI_COLUMN_NAME
194+
? this._getValueFromCellOptions(columnIndex, cellOptions)
195+
: column.calculateCellValue(rowData);
196+
187197
const displayValue = gridCoreUtils.getDisplayValue(column, value, rowData, cellOptions.rowType);
188198
const text = gridCoreUtils.formatValue(displayValue, column);
189199
const isCellOrBatchEditMode = this._editingController.isCellOrBatchEditMode();
@@ -242,7 +252,7 @@ export class AdaptiveColumnsController extends modules.ViewController {
242252

243253
const renderFormTemplate = function () {
244254
const isItemEdited = that._isItemEdited(item);
245-
templateOptions.value = cellOptions.row.values[columnIndex];
255+
templateOptions.value = that._getValueFromCellOptions(columnIndex, cellOptions);
246256
if (isItemEdited || column.showEditorAlways) {
247257
editingController.renderFormEditorTemplate(templateOptions, item, options, $container, !isItemEdited);
248258
} else {
@@ -257,7 +267,7 @@ export class AdaptiveColumnsController extends modules.ViewController {
257267
if (templateOptions.watch) {
258268
const dispose = templateOptions.watch(() => ({
259269
isItemEdited: that._isItemEdited(item),
260-
value: cellOptions.row.values[columnIndex],
270+
value: that._getValueFromCellOptions(columnIndex, cellOptions),
261271
}), () => {
262272
$container.contents().remove();
263273
$container.removeClass(ADAPTIVE_ITEM_TEXT_CLASS);

packages/testcafe-models/dataGrid/adaptiveDetailRow.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// eslint-disable-next-line import/no-cycle
22
import AdaptiveCell from './data/adaptiveCell';
33

4+
const SELECTORS = {
5+
ADAPTIVE_CELL_CLASS: 'dx-field-item'
6+
};
7+
48
export default class AdaptiveDetailRow {
59
element: Selector;
610

@@ -11,4 +15,9 @@ export default class AdaptiveDetailRow {
1115
getAdaptiveCell(index: number): AdaptiveCell {
1216
return new AdaptiveCell(this.element, index);
1317
}
18+
19+
getAdaptiveCellByText(text: string): AdaptiveCell {
20+
const cellElement = this.element.find(`.${SELECTORS.ADAPTIVE_CELL_CLASS}`).withText(text);
21+
return new AdaptiveCell(cellElement, 0);
22+
}
1423
}

packages/testcafe-models/dataGrid/data/adaptiveCell.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ export default class AdaptiveCell extends FocusableElement {
1616
this.isFocused = this.element.hasClass(CLASS.focused);
1717
this.isEditCell = this.element.child(`.${CLASS.textBox}`).exists;
1818
}
19+
20+
getAdaptiveCellValue(): Promise<string> {
21+
return this.element.textContent;
22+
}
1923
}

0 commit comments

Comments
 (0)