1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-03 04:35:31 +00:00

Add new widgets with optimistic update

This commit is contained in:
Petr Stribny 2025-03-17 18:31:42 +00:00 committed by Bram Wiepjes
parent 45f5b00e7c
commit c498966f65

View file

@ -174,19 +174,32 @@ export const actions = {
}
})
},
async createWidget({ dispatch }, { dashboard, widget }) {
const { data } = await WidgetService(this.$client).create(
dashboard.id,
widget
)
async createWidget({ commit, dispatch }, { dashboard, widget }) {
const tempId = Date.now()
commit('ADD_WIDGET', { id: tempId, ...widget })
let widgetData
try {
const { data } = await WidgetService(this.$client).create(
dashboard.id,
widget
)
widgetData = data
} catch (error) {
commit('DELETE_WIDGET', tempId)
throw error
}
return await dispatch('handleNewWidgetCreated', {
...data,
tempWidgetId: tempId,
createdWidget: widgetData,
})
},
async handleNewWidgetCreated({ commit, dispatch }, createdWidget) {
commit('ADD_WIDGET', createdWidget)
await dispatch('fetchNewDataSources', createdWidget.dashboard_id)
async handleNewWidgetCreated(
{ commit, dispatch },
{ tempWidgetId, createdWidget }
) {
commit('UPDATE_WIDGET', { widgetId: tempWidgetId, values: createdWidget })
dispatch('selectWidget', createdWidget.id)
await dispatch('fetchNewDataSources', createdWidget.dashboard_id)
},
async dispatchDataSource({ commit }, dataSourceId) {
commit('UPDATE_DATA', { dataSourceId, values: null })