From 49f1508cf7ea090a90aa89c6c17f710d7c266be4 Mon Sep 17 00:00:00 2001 From: Joshua Barbosa <44610149+tongsonbarbs@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:16:59 +0800 Subject: [PATCH] DataGrid - Canceled rows are hidden when multiple rows are added in batch mode (T1250405) (#28501) --- .../tests/dataGrid/editing/editingEvents.ts | 53 +++++++++++++++++- .../etalons/T1250405-canceled-rows-hidden.png | Bin 0 -> 4174 bytes .../data_controller/m_data_controller.ts | 1 + .../grids/grid_core/editing/m_editing.ts | 15 +++-- packages/testcafe-models/dataGrid/overlay.ts | 12 +++- 5 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 e2e/testcafe-devextreme/tests/dataGrid/editing/etalons/T1250405-canceled-rows-hidden.png diff --git a/e2e/testcafe-devextreme/tests/dataGrid/editing/editingEvents.ts b/e2e/testcafe-devextreme/tests/dataGrid/editing/editingEvents.ts index dcfe2120266d..6823bab89087 100644 --- a/e2e/testcafe-devextreme/tests/dataGrid/editing/editingEvents.ts +++ b/e2e/testcafe-devextreme/tests/dataGrid/editing/editingEvents.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-misused-promises */ -import { ClientFunction } from 'testcafe'; +import { ClientFunction, Selector } from 'testcafe'; import DataGrid from 'devextreme-testcafe-models/dataGrid'; +import { Overlay } from 'devextreme-testcafe-models/dataGrid/overlay'; +import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; import { createWidget } from '../../../helpers/createWidget'; import url from '../../../helpers/getPageUrl'; @@ -172,3 +174,52 @@ testCases.forEach(({ caseName, expected, onRowRemoving }) => { }); }); }); + +// T1250405 +test('DataGrid - Canceled rows are hidden when multiple rows are added in batch mode', async (t) => { + const dataGrid = new DataGrid('#container'); + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); + const addBtn = dataGrid.getToolbar().getItem(); + const saveBtn = dataGrid.getToolbar().getItem(1); + await t.expect(dataGrid.isReady()).ok(); + await t + .click(addBtn) + .pressKey('1') + .click(addBtn) + .pressKey('2') + .click(saveBtn); + + const overlay1 = new Overlay(Selector('.dx-overlay-wrapper'), 0); + const overlay2 = new Overlay(Selector('.dx-overlay-wrapper'), 1); + const cancelBtn = overlay2.getToolbar(1).getItem(1); + const saveBtnPopup = overlay1.getToolbar(1).getItem(0); + await t + .click(cancelBtn) + .click(saveBtnPopup); + await t + .expect(await takeScreenshot('T1250405-canceled-rows-hidden.png', dataGrid.element)) + .ok() + .expect(compareResults.isValid()) + .ok(compareResults.errorMessages()); +}).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [ + { ID: 1, Text: 'Item 1' }, + ], + keyExpr: 'ID', + columns: ['Text'], + editing: { + mode: 'batch', + allowAdding: true, + }, + onRowInserting(e: any) { + e.cancel = new Promise((resolve) => { + const dialog = (window as any).DevExpress.ui.dialog.confirm( + 'Are you sure?', + 'Confirm changes', + ); + dialog.done((confirm) => resolve(!confirm)); + }); + }, + }); +}); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/editing/etalons/T1250405-canceled-rows-hidden.png b/e2e/testcafe-devextreme/tests/dataGrid/editing/etalons/T1250405-canceled-rows-hidden.png new file mode 100644 index 0000000000000000000000000000000000000000..528a1bafdd4e90cc8a53864b7114e56097a9d1bb GIT binary patch literal 4174 zcmcIn2~bnl8m6^MtqAQ@OGSiQDpWyHRxvEC6%hrZXo#%QLK2oB$P(5NtyXOn&;r2_ z7A;FEC}^T$2&+^O$Wk^TvIJ!_5VnNH5C}ad;(OD1Gw;3W^UW}v+VZ`Oyaz<*u7!vYxIcii{wvFP{2S_v&GDj%!Dr?DE+ zCE>~!s*`iJ!U;U1C#s{eG!YTDxe=MS&(Y>O7I$@T;C*c4Hq9e@x1~;hkd(Q1WS`@j zExOMoXSMVk3#6OnxuF(lqv8wqR@vs6I}v*cu?Z6o$NPirG!ps^Oy=@(f_WXI<^lB^ z-vj$0X<-Rf^9A=cH`n_63Ey3kV!3&Xxh!&2Rf z(#FTf&9oBBv!^G z8XZ04PO-X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ny zXaNsAsDJpIxvsMZ6sS!7i(AyFzDs&ZPwBQZx4NVI6Jro5`p%6s=M1y0(7AH*x)@d4 z>6;pZ0(=gaRsn=T2J)~G&Rsw3r@QI&@1F=Bo%RJ^QjqQmz2#Pb)uJ8-cTqq)zAN3E z=$b)3x`VbA;)cn$MPTI5J0zzb_5H90bV7_)pt`ix$<~qspqW?!JgUAK^8X>pcSE&* zJ*AD~bG#~n^x1Zg)D5P%0np#Sp|d-<*%MEGUJvy+42S>@G*&R%ca47*f4f|&3sd!~ z@ZBuRG;SvlQ~0}D@$cH0K%55n9$}E=v;Vw-$3SL43#Oz3b}L86E3{^%C}NL51Zb9f z-a#kktBQ&WB@Ook;52~Xt%r6xG4F^Q;9>tDnx!?)x`OXN`fxxg*^c%u`-=CT_~B2e CM*a@~ literal 0 HcmV?d00001 diff --git a/packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts index ce924bf71a0e..58ffb026ab32 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/data_controller/m_data_controller.ts @@ -80,6 +80,7 @@ interface Item { values?: unknown[]; visible?: boolean; isExpanded?: boolean; + isNewRow?: boolean; summaryCells?: unknown[]; rowIndex?: number; cells?: unknown[]; diff --git a/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts b/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts index f2b311cfa752..1e6fcbf1f082 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/prefer-for-of */ /* eslint-disable @typescript-eslint/no-unused-vars, max-classes-per-file */ import { name as clickEventName } from '@js/common/core/events/click'; import eventsEngine from '@js/common/core/events/core/events_engine'; @@ -1336,10 +1337,12 @@ class EditingControllerImpl extends modules.ViewController { const removeChange = changes[index]; changes.forEach((change) => { - const insertAfterOrBeforeKey = this._getInsertAfterOrBeforeKey(change); + if (change.type === DATA_EDIT_DATA_INSERT_TYPE) { + const insertAfterOrBeforeKey = this._getInsertAfterOrBeforeKey(change); - if (equalByValue(insertAfterOrBeforeKey, removeChange.key)) { - change[isDefined(change.insertAfterKey) ? 'insertAfterKey' : 'insertBeforeKey'] = this._getInsertAfterOrBeforeKey(removeChange); + if (equalByValue(insertAfterOrBeforeKey, removeChange.key)) { + change[isDefined(change.insertAfterKey) ? 'insertAfterKey' : 'insertBeforeKey'] = this._getInsertAfterOrBeforeKey(removeChange); + } } }); } @@ -1679,7 +1682,8 @@ class EditingControllerImpl extends modules.ViewController { private _processSaveEditDataResult(results) { let hasSavedData = false; - const changes = [...this.getChanges()]; + const originalChanges = this.getChanges(); + const changes = [...originalChanges]; const changesLength = changes.length; for (let i = 0; i < results.length; i++) { @@ -1699,6 +1703,9 @@ class EditingControllerImpl extends modules.ViewController { } } else if (this._processRemove(changes, editIndex, cancel)) { hasSavedData = !cancel; + const removedChangeIndex = gridCoreUtils.getIndexByKey(results[i].key, originalChanges); + + this._updateInsertAfterOrBeforeKeys(originalChanges, removedChangeIndex); } } diff --git a/packages/testcafe-models/dataGrid/overlay.ts b/packages/testcafe-models/dataGrid/overlay.ts index 663a8745b07c..b593fe0b6203 100644 --- a/packages/testcafe-models/dataGrid/overlay.ts +++ b/packages/testcafe-models/dataGrid/overlay.ts @@ -1,10 +1,12 @@ import { Selector } from 'testcafe'; +import Toolbar from '../toolbar'; const CLASS = { overlayWrapper: 'dx-overlay-wrapper', overlayContent: 'dx-overlay-content', invalidMessage: 'dx-invalid-message', revertTooltip: 'dx-datagrid-revert-tooltip', + toolbar: 'dx-toolbar', checkbox: 'dx-checkbox', }; @@ -13,8 +15,10 @@ export class Overlay { content: Selector; - constructor(id?: Selector) { - this.element = id ?? Selector(`.${CLASS.overlayWrapper}`); + constructor(id?: Selector, index?: number) { + this.element = id + ? (index ? id.nth(index) : id) + : Selector(`.${CLASS.overlayWrapper}`).nth(index ? index : 0); this.content = this.element.find(`.${CLASS.overlayContent}`); } @@ -30,4 +34,8 @@ export class Overlay { getPopupCheckbox(): Selector { return this.element.find(`.${CLASS.overlayContent} .${CLASS.checkbox}`); } + + getToolbar(idx?: number): Toolbar { + return new Toolbar(this.element.find(`.${CLASS.toolbar}`).nth(idx ? idx : 0)); + } }