From 834202423f920d0ab1b4ad982b6e1f3a93a785f6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 May 2023 16:42:36 +0100 Subject: [PATCH] Fix bulk deletion triggering on delete keypress after selecting then deselecting a row --- .../components/grid/cells/GutterCell.svelte | 11 +--------- .../grid/overlays/KeyboardManager.svelte | 5 +---- .../src/components/grid/stores/ui.js | 21 ++++++++++++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/frontend-core/src/components/grid/cells/GutterCell.svelte b/packages/frontend-core/src/components/grid/cells/GutterCell.svelte index 00b99c0711..588818f10d 100644 --- a/packages/frontend-core/src/components/grid/cells/GutterCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/GutterCell.svelte @@ -21,16 +21,7 @@ svelteDispatch("select") const id = row?._id if (id) { - selectedRows.update(state => { - let newState = { - ...state, - [id]: !state[id], - } - if (!newState[id]) { - delete newState[id] - } - return newState - }) + selectedRows.actions.toggleRow(id) } } diff --git a/packages/frontend-core/src/components/grid/overlays/KeyboardManager.svelte b/packages/frontend-core/src/components/grid/overlays/KeyboardManager.svelte index c7fa0a5cb7..6d16acc7c5 100644 --- a/packages/frontend-core/src/components/grid/overlays/KeyboardManager.svelte +++ b/packages/frontend-core/src/components/grid/overlays/KeyboardManager.svelte @@ -224,10 +224,7 @@ if (!id || id === NewRowID) { return } - selectedRows.update(state => { - state[id] = !state[id] - return state - }) + selectedRows.actions.toggleRow(id) } onMount(() => { diff --git a/packages/frontend-core/src/components/grid/stores/ui.js b/packages/frontend-core/src/components/grid/stores/ui.js index 85afad8a90..b62e883437 100644 --- a/packages/frontend-core/src/components/grid/stores/ui.js +++ b/packages/frontend-core/src/components/grid/stores/ui.js @@ -25,14 +25,33 @@ export const createStores = () => { null ) + // Toggles whether a certain row ID is selected or not + const toggleSelectedRow = id => { + selectedRows.update(state => { + let newState = { + ...state, + [id]: !state[id], + } + if (!newState[id]) { + delete newState[id] + } + return newState + }) + } + return { focusedCellId, focusedCellAPI, focusedRowId, previousFocusedRowId, - selectedRows, hoveredRowId, rowHeight, + selectedRows: { + ...selectedRows, + actions: { + toggleRow: toggleSelectedRow, + }, + }, } }