1
0
Fork 0
mirror of synced 2024-09-18 10:20:11 +12:00

Merge pull request #13808 from Budibase/grid-conflict-improvements

Grid conflict improvements
This commit is contained in:
Andrew Kingston 2024-05-30 09:49:27 +01:00 committed by GitHub
commit 8e7560e3e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -404,8 +404,11 @@ export const createActions = context => {
// Save change // Save change
try { try {
// Mark as in progress // Increment 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
@ -553,7 +564,6 @@ 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
@ -571,20 +581,12 @@ export const initialise = context => {
if (!id) { if (!id) {
return return
} }
// Stop if we changed row const { id: rowId, field } = parseCellID(id)
const split = parseCellID(id) const hasChanges = field in (get(rowChangeCache)[rowId] || {})
const oldRowId = split.id const hasErrors = validation.actions.rowHasErrors(rowId)
const oldColumn = split.field const isSavingChanges = get(inProgressChanges)[rowId]
const { id: newRowId } = parseCellID(get(focusedCellId)) if (rowId && !hasErrors && hasChanges && !isSavingChanges) {
if (oldRowId !== newRowId) { await rows.actions.applyRowChanges(rowId)
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)
} }
}) })
} }