Only clear change cache for keys which have been saved and haven't been further altered since the request started!
This commit is contained in:
parent
35842525c5
commit
e1ee233aaf
|
@ -404,8 +404,11 @@ export const createActions = context => {
|
||||||
|
|
||||||
// Save change
|
// Save change
|
||||||
try {
|
try {
|
||||||
// Mark as in progress
|
// Incremenet change count for this row
|
||||||
inProgressChanges.update(state => ({ ...state, [rowId]: true }))
|
inProgressChanges.update(state => ({
|
||||||
|
...state,
|
||||||
|
[rowId]: (state[rowId] || 0) + 1,
|
||||||
|
}))
|
||||||
|
|
||||||
// Update row
|
// Update row
|
||||||
const changes = get(rowChangeCache)[rowId]
|
const changes = get(rowChangeCache)[rowId]
|
||||||
|
@ -423,17 +426,25 @@ export const createActions = context => {
|
||||||
await refreshRow(saved.id)
|
await refreshRow(saved.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wipe row change cache now that we've saved the row
|
// Wipe row change cache for any values which have been saved
|
||||||
|
const liveChanges = get(rowChangeCache)[rowId]
|
||||||
rowChangeCache.update(state => {
|
rowChangeCache.update(state => {
|
||||||
delete state[rowId]
|
Object.keys(changes || {}).forEach(key => {
|
||||||
|
if (changes[key] === liveChanges?.[key]) {
|
||||||
|
delete state[rowId][key]
|
||||||
|
}
|
||||||
|
})
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleValidationError(rowId, error)
|
handleValidationError(rowId, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as completed
|
// Decrement change count for this row
|
||||||
inProgressChanges.update(state => ({ ...state, [rowId]: false }))
|
inProgressChanges.update(state => ({
|
||||||
|
...state,
|
||||||
|
[rowId]: (state[rowId] || 1) - 1,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates a value of a row
|
// Updates a value of a row
|
||||||
|
|
Loading…
Reference in New Issue