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")
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)
}
}

View File

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

View File

@ -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,
},
},
}
}