mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-14 09:08:32 +00:00
Add new widgets with optimistic update
This commit is contained in:
parent
45f5b00e7c
commit
c498966f65
1 changed files with 22 additions and 9 deletions
|
@ -174,19 +174,32 @@ export const actions = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async createWidget({ dispatch }, { dashboard, widget }) {
|
async createWidget({ commit, dispatch }, { dashboard, widget }) {
|
||||||
const { data } = await WidgetService(this.$client).create(
|
const tempId = Date.now()
|
||||||
dashboard.id,
|
commit('ADD_WIDGET', { id: tempId, ...widget })
|
||||||
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', {
|
return await dispatch('handleNewWidgetCreated', {
|
||||||
...data,
|
tempWidgetId: tempId,
|
||||||
|
createdWidget: widgetData,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async handleNewWidgetCreated({ commit, dispatch }, createdWidget) {
|
async handleNewWidgetCreated(
|
||||||
commit('ADD_WIDGET', createdWidget)
|
{ commit, dispatch },
|
||||||
await dispatch('fetchNewDataSources', createdWidget.dashboard_id)
|
{ tempWidgetId, createdWidget }
|
||||||
|
) {
|
||||||
|
commit('UPDATE_WIDGET', { widgetId: tempWidgetId, values: createdWidget })
|
||||||
dispatch('selectWidget', createdWidget.id)
|
dispatch('selectWidget', createdWidget.id)
|
||||||
|
await dispatch('fetchNewDataSources', createdWidget.dashboard_id)
|
||||||
},
|
},
|
||||||
async dispatchDataSource({ commit }, dataSourceId) {
|
async dispatchDataSource({ commit }, dataSourceId) {
|
||||||
commit('UPDATE_DATA', { dataSourceId, values: null })
|
commit('UPDATE_DATA', { dataSourceId, values: null })
|
||||||
|
|
Loading…
Add table
Reference in a new issue