Handle users tables edges cases when working with grids

This commit is contained in:
Andrew Kingston 2023-05-26 11:39:20 +01:00
parent 25f469dc28
commit 7c2d15be8d
2 changed files with 13 additions and 5 deletions

View File

@ -33,9 +33,12 @@ export const createGridWebsocket = context => {
})
// Row events
socket.on("row-change", data => {
socket.on("row-change", async data => {
if (data.id) {
rows.actions.replaceRow(data.id, data.row)
} else if (data.row.id) {
// Handle users table edge case
await rows.actions.refreshRow(data.row.id)
}
})

View File

@ -345,10 +345,15 @@ export const deriveStores = context => {
const saved = await API.saveRow({ ...row, ...get(rowChangeCache)[rowId] })
// Update state after a successful change
rows.update(state => {
state[index] = saved
return state.slice()
})
if (saved?._id) {
rows.update(state => {
state[index] = saved
return state.slice()
})
} else if (saved?.id) {
// Handle users table edge case
await refreshRow(saved.id)
}
rowChangeCache.update(state => {
delete state[rowId]
return state