From e1ee233aaf421c1825b54416a4789dd66817738a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 29 May 2024 09:51:01 +0100 Subject: [PATCH 1/3] Only clear change cache for keys which have been saved and haven't been further altered since the request started! --- .../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 c73dae8991..08e43eef32 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -404,8 +404,11 @@ export const createActions = context => { // Save change try { - // Mark as in progress - inProgressChanges.update(state => ({ ...state, [rowId]: true })) + // Incremenet change count for this row + inProgressChanges.update(state => ({ + ...state, + [rowId]: (state[rowId] || 0) + 1, + })) // Update row const changes = get(rowChangeCache)[rowId] @@ -423,17 +426,25 @@ export const createActions = context => { await refreshRow(saved.id) } - // Wipe row change cache now that we've saved the row + // Wipe row change cache for any values which have been saved + const liveChanges = get(rowChangeCache)[rowId] rowChangeCache.update(state => { - delete state[rowId] + Object.keys(changes || {}).forEach(key => { + if (changes[key] === liveChanges?.[key]) { + delete state[rowId][key] + } + }) return state }) } catch (error) { handleValidationError(rowId, error) } - // Mark as completed - inProgressChanges.update(state => ({ ...state, [rowId]: false })) + // Decrement change count for this row + inProgressChanges.update(state => ({ + ...state, + [rowId]: (state[rowId] || 1) - 1, + })) } // Updates a value of a row From 38c405ff6ff4747d0e21bc74693514393df2c7cd Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 29 May 2024 09:59:54 +0100 Subject: [PATCH 2/3] Ensure single character changes to non-focused fields are properly persisted when changing focused row --- .../src/components/grid/stores/rows.js | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index 08e43eef32..5140a7da8b 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -564,7 +564,6 @@ export const initialise = context => { previousFocusedCellId, rows, validation, - focusedCellId, } = context // Wipe the row change cache when changing row @@ -582,20 +581,12 @@ export const initialise = context => { if (!id) { return } - // Stop if we changed row - const split = parseCellID(id) - const oldRowId = split.id - const oldColumn = split.field - const { id: newRowId } = parseCellID(get(focusedCellId)) - 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) + const { id: rowId, field } = parseCellID(id) + const hasChanges = field in (get(rowChangeCache)[rowId] || {}) + const hasErrors = validation.actions.rowHasErrors(rowId) + const isSavingChanges = get(inProgressChanges)[rowId] + if (rowId && !hasErrors && hasChanges && !isSavingChanges) { + await rows.actions.applyRowChanges(rowId) } }) } From 19a422ca1ccf7accf621728aeb1995a3dd8b28fc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 30 May 2024 09:14:56 +0100 Subject: [PATCH 3/3] Typo --- packages/frontend-core/src/components/grid/stores/rows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index 5140a7da8b..d354dfd9b3 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -404,7 +404,7 @@ export const createActions = context => { // Save change try { - // Incremenet change count for this row + // Increment change count for this row inProgressChanges.update(state => ({ ...state, [rowId]: (state[rowId] || 0) + 1,