mirror of
https://github.com/beekeeper-studio/beekeeper-studio.git
synced 2026-03-13 10:12:54 +08:00
updated with proper error handling for moves
This commit is contained in:
@@ -72,14 +72,26 @@ export const UtilConnectionModule: DataStore<IConnection, State> = {
|
||||
position: idx + 1
|
||||
}))
|
||||
|
||||
// Snapshot affected items before mutation (upsert mutates in-place via Object.assign)
|
||||
const affectedIds = new Set(updates.map(c => c.id))
|
||||
const snapshot = context.state.items
|
||||
.filter(c => affectedIds.has(c.id))
|
||||
.map(c => ({ ...c }))
|
||||
|
||||
// Optimistic update
|
||||
context.commit('upsert', updates)
|
||||
|
||||
// Save all items
|
||||
const saved = await Promise.all(
|
||||
updates.map(c => Vue.prototype.$util.send('appdb/saved/save', { obj: c }))
|
||||
)
|
||||
context.commit('upsert', saved)
|
||||
try {
|
||||
// Save all items
|
||||
const saved = await Promise.all(
|
||||
updates.map(c => Vue.prototype.$util.send('appdb/saved/save', { obj: c }))
|
||||
)
|
||||
context.commit('upsert', saved)
|
||||
} catch (e) {
|
||||
// Revert optimistic update using pre-mutation snapshots
|
||||
context.commit('upsert', snapshot)
|
||||
throw e
|
||||
}
|
||||
|
||||
return item.id
|
||||
}
|
||||
|
||||
@@ -71,14 +71,26 @@ export const UtilQueryModule: DataStore<TransportFavoriteQuery, DataState<Transp
|
||||
position: idx + 1
|
||||
}))
|
||||
|
||||
// Snapshot affected items before mutation (upsert mutates in-place via Object.assign)
|
||||
const affectedIds = new Set(updates.map(q => q.id))
|
||||
const snapshot = context.state.items
|
||||
.filter(q => affectedIds.has(q.id))
|
||||
.map(q => ({ ...q }))
|
||||
|
||||
// Optimistic update
|
||||
context.commit('upsert', updates)
|
||||
|
||||
// Save all items
|
||||
const saved = await Promise.all(
|
||||
updates.map(q => Vue.prototype.$util.send('appdb/query/save', { obj: q }))
|
||||
)
|
||||
context.commit('upsert', saved)
|
||||
try {
|
||||
// Save all items
|
||||
const saved = await Promise.all(
|
||||
updates.map(q => Vue.prototype.$util.send('appdb/query/save', { obj: q }))
|
||||
)
|
||||
context.commit('upsert', saved)
|
||||
} catch (e) {
|
||||
// Revert optimistic update using pre-mutation snapshots
|
||||
context.commit('upsert', snapshot)
|
||||
throw e
|
||||
}
|
||||
|
||||
return item.id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user