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 000000000000..528a1bafdd4e Binary files /dev/null and b/e2e/testcafe-devextreme/tests/dataGrid/editing/etalons/T1250405-canceled-rows-hidden.png differ 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 b1fba2ee066f..fd3c348c1475 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 49391db27258..0b4613b1c31b 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 type { GridsEditMode } from '@js/common/grids'; import devices from '@js/core/devices'; @@ -1337,10 +1338,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); + } } }); } @@ -1680,7 +1683,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++) { @@ -1700,6 +1704,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/devextreme/testing/testcafe/model/dataGrid/overlay.ts b/packages/devextreme/testing/testcafe/model/dataGrid/overlay.ts index 663a8745b07c..1fcb1cfd92a0 100644 --- a/packages/devextreme/testing/testcafe/model/dataGrid/overlay.ts +++ b/packages/devextreme/testing/testcafe/model/dataGrid/overlay.ts @@ -1,10 +1,15 @@ +/* eslint-disable @typescript-eslint/no-extra-parens */ +/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ +/* eslint-disable no-nested-ternary */ 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 +18,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 || 0); this.content = this.element.find(`.${CLASS.overlayContent}`); } @@ -30,4 +37,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 || 0)); + } } diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/editing/editingEvents.ts b/packages/devextreme/testing/testcafe/tests/dataGrid/editing/editingEvents.ts index c15527b3e201..dfb526de61e6 100644 --- a/packages/devextreme/testing/testcafe/tests/dataGrid/editing/editingEvents.ts +++ b/packages/devextreme/testing/testcafe/tests/dataGrid/editing/editingEvents.ts @@ -1,5 +1,7 @@ /* eslint-disable @typescript-eslint/no-misused-promises */ -import { ClientFunction } from 'testcafe'; +import { ClientFunction, Selector } from 'testcafe'; +import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; +import { Overlay } from '../../../model/dataGrid/overlay'; import { createWidget } from '../../../helpers/createWidget'; import url from '../../../helpers/getPageUrl'; import DataGrid from '../../../model/dataGrid'; @@ -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)); + }); + }, + }); +});