Handle crash when other user deletes a row that is either the source or target of cell selection
This commit is contained in:
parent
5c6cb0a73a
commit
e0c38d7fbe
|
@ -638,14 +638,6 @@ export const createActions = context => {
|
||||||
get(fetch)?.nextPage()
|
get(fetch)?.nextPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if we have a row with a certain ID
|
|
||||||
const hasRow = id => {
|
|
||||||
if (id === NewRowID) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return get(rowLookupMap)[id] != null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleans a row by removing any internal grid metadata from it.
|
// Cleans a row by removing any internal grid metadata from it.
|
||||||
// Call this before passing a row to any sort of external flow.
|
// Call this before passing a row to any sort of external flow.
|
||||||
const cleanRow = row => {
|
const cleanRow = row => {
|
||||||
|
@ -667,7 +659,6 @@ export const createActions = context => {
|
||||||
updateValue,
|
updateValue,
|
||||||
applyRowChanges,
|
applyRowChanges,
|
||||||
deleteRows,
|
deleteRows,
|
||||||
hasRow,
|
|
||||||
loadNextPage,
|
loadNextPage,
|
||||||
refreshRow,
|
refreshRow,
|
||||||
replaceRow,
|
replaceRow,
|
||||||
|
|
|
@ -117,8 +117,11 @@ export const deriveStores = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Row indices
|
// Row indices
|
||||||
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId].__idx
|
const sourceRowIndex = $rowLookupMap[sourceInfo.rowId]?.__idx
|
||||||
const targetRowIndex = $rowLookupMap[targetInfo.rowId].__idx
|
const targetRowIndex = $rowLookupMap[targetInfo.rowId]?.__idx
|
||||||
|
if (sourceRowIndex == null || targetRowIndex == null) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
const lowerRowIndex = Math.min(sourceRowIndex, targetRowIndex)
|
const lowerRowIndex = Math.min(sourceRowIndex, targetRowIndex)
|
||||||
const upperRowIndex = Math.max(sourceRowIndex, targetRowIndex)
|
const upperRowIndex = Math.max(sourceRowIndex, targetRowIndex)
|
||||||
|
|
||||||
|
@ -305,7 +308,7 @@ export const initialise = context => {
|
||||||
focusedRowId,
|
focusedRowId,
|
||||||
previousFocusedRowId,
|
previousFocusedRowId,
|
||||||
previousFocusedCellId,
|
previousFocusedCellId,
|
||||||
rows,
|
rowLookupMap,
|
||||||
focusedCellId,
|
focusedCellId,
|
||||||
selectedRows,
|
selectedRows,
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
|
@ -320,18 +323,17 @@ export const initialise = context => {
|
||||||
} = context
|
} = context
|
||||||
|
|
||||||
// Ensure we clear invalid rows from state if they disappear
|
// Ensure we clear invalid rows from state if they disappear
|
||||||
rows.subscribe(async () => {
|
rowLookupMap.subscribe(async $rowLookupMap => {
|
||||||
// We tick here to ensure other derived stores have properly updated.
|
// We tick here to ensure other derived stores have properly updated.
|
||||||
// We depend on the row lookup map which is a derived store,
|
// We depend on the row lookup map which is a derived store,
|
||||||
await tick()
|
await tick()
|
||||||
const $focusedCellId = get(focusedCellId)
|
const $focusedRowId = get(focusedRowId)
|
||||||
const $selectedRows = get(selectedRows)
|
const $selectedRows = get(selectedRows)
|
||||||
const $hoveredRowId = get(hoveredRowId)
|
const $hoveredRowId = get(hoveredRowId)
|
||||||
const hasRow = rows.actions.hasRow
|
const hasRow = id => $rowLookupMap[id] != null
|
||||||
|
|
||||||
// Check selected cell
|
// Check focused cell
|
||||||
const selectedRowId = parseCellID($focusedCellId).rowId
|
if ($focusedRowId && !hasRow($focusedRowId)) {
|
||||||
if (selectedRowId && !hasRow(selectedRowId)) {
|
|
||||||
focusedCellId.set(null)
|
focusedCellId.set(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,9 +343,10 @@ export const initialise = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check selected rows
|
// Check selected rows
|
||||||
|
const selectedIds = Object.keys($selectedRows)
|
||||||
|
if (selectedIds.length) {
|
||||||
let newSelectedRows = { ...$selectedRows }
|
let newSelectedRows = { ...$selectedRows }
|
||||||
let selectedRowsNeedsUpdate = false
|
let selectedRowsNeedsUpdate = false
|
||||||
const selectedIds = Object.keys($selectedRows)
|
|
||||||
for (let i = 0; i < selectedIds.length; i++) {
|
for (let i = 0; i < selectedIds.length; i++) {
|
||||||
if (!hasRow(selectedIds[i])) {
|
if (!hasRow(selectedIds[i])) {
|
||||||
delete newSelectedRows[selectedIds[i]]
|
delete newSelectedRows[selectedIds[i]]
|
||||||
|
@ -353,6 +356,7 @@ export const initialise = context => {
|
||||||
if (selectedRowsNeedsUpdate) {
|
if (selectedRowsNeedsUpdate) {
|
||||||
selectedRows.set(newSelectedRows)
|
selectedRows.set(newSelectedRows)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remember the last focused row ID so that we can store the previous one
|
// Remember the last focused row ID so that we can store the previous one
|
||||||
|
|
Loading…
Reference in New Issue