Don't attempt to save unsaved changes when changing cells if the row also changes
This commit is contained in:
parent
67863da655
commit
9a03729e49
|
@ -523,6 +523,7 @@ export const initialise = context => {
|
||||||
previousFocusedCellId,
|
previousFocusedCellId,
|
||||||
rows,
|
rows,
|
||||||
validation,
|
validation,
|
||||||
|
focusedCellId,
|
||||||
} = context
|
} = context
|
||||||
|
|
||||||
// Wipe the row change cache when changing row
|
// Wipe the row change cache when changing row
|
||||||
|
@ -537,12 +538,22 @@ export const initialise = context => {
|
||||||
|
|
||||||
// Ensure any unsaved changes are saved when changing cell
|
// Ensure any unsaved changes are saved when changing cell
|
||||||
previousFocusedCellId.subscribe(async id => {
|
previousFocusedCellId.subscribe(async id => {
|
||||||
const rowId = id?.split("-")[0]
|
if (!id) {
|
||||||
const hasErrors = validation.actions.rowHasErrors(rowId)
|
return
|
||||||
const hasChanges = Object.keys(get(rowChangeCache)[rowId] || {}).length > 0
|
}
|
||||||
const isSavingChanges = get(inProgressChanges)[rowId]
|
// Stop if we changed row
|
||||||
if (rowId && !hasErrors && hasChanges && !isSavingChanges) {
|
const oldRowId = id.split("-")[0]
|
||||||
await rows.actions.applyRowChanges(rowId)
|
const oldColumn = id.split("-")[1]
|
||||||
|
const newRowId = get(focusedCellId)?.split("-")[0]
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue