Fix bulk deletion triggering on delete keypress after selecting then deselecting a row

This commit is contained in:
Andrew Kingston 2023-05-16 16:42:36 +01:00
parent 0a0e78c314
commit 834202423f
3 changed files with 22 additions and 15 deletions

View File

@ -21,16 +21,7 @@
svelteDispatch("select") svelteDispatch("select")
const id = row?._id const id = row?._id
if (id) { if (id) {
selectedRows.update(state => { selectedRows.actions.toggleRow(id)
let newState = {
...state,
[id]: !state[id],
}
if (!newState[id]) {
delete newState[id]
}
return newState
})
} }
} }

View File

@ -224,10 +224,7 @@
if (!id || id === NewRowID) { if (!id || id === NewRowID) {
return return
} }
selectedRows.update(state => { selectedRows.actions.toggleRow(id)
state[id] = !state[id]
return state
})
} }
onMount(() => { onMount(() => {

View File

@ -25,14 +25,33 @@ export const createStores = () => {
null 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 { return {
focusedCellId, focusedCellId,
focusedCellAPI, focusedCellAPI,
focusedRowId, focusedRowId,
previousFocusedRowId, previousFocusedRowId,
selectedRows,
hoveredRowId, hoveredRowId,
rowHeight, rowHeight,
selectedRows: {
...selectedRows,
actions: {
toggleRow: toggleSelectedRow,
},
},
} }
} }