From 9a03729e498f4f929308e6983ca90c88e2d66b58 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 26 Apr 2024 13:04:15 +0100 Subject: [PATCH] Don't attempt to save unsaved changes when changing cells if the row also changes --- .../src/components/grid/stores/rows.js | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index 5dc9413ccd..0ac923fede 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -523,6 +523,7 @@ export const initialise = context => { previousFocusedCellId, rows, validation, + focusedCellId, } = context // Wipe the row change cache when changing row @@ -537,12 +538,22 @@ export const initialise = context => { // Ensure any unsaved changes are saved when changing cell previousFocusedCellId.subscribe(async id => { - const rowId = id?.split("-")[0] - const hasErrors = validation.actions.rowHasErrors(rowId) - const hasChanges = Object.keys(get(rowChangeCache)[rowId] || {}).length > 0 - const isSavingChanges = get(inProgressChanges)[rowId] - if (rowId && !hasErrors && hasChanges && !isSavingChanges) { - await rows.actions.applyRowChanges(rowId) + if (!id) { + return + } + // Stop if we changed row + const oldRowId = id.split("-")[0] + const oldColumn = id.split("-")[1] + const newRowId = get(focusedCellId)?.split("-")[0] + if (oldRowId !== newRowId) { + return + } + // Otherwise we just changed cell in the same row + const hasChanges = oldColumn in (get(rowChangeCache)[oldRowId] || {}) + const hasErrors = validation.actions.rowHasErrors(oldRowId) + const isSavingChanges = get(inProgressChanges)[oldRowId] + if (oldRowId && !hasErrors && hasChanges && !isSavingChanges) { + await rows.actions.applyRowChanges(oldRowId) } }) }