Skip to content

Commit

Permalink
Merge pull request #14271 from Budibase/dean-fixes
Browse files Browse the repository at this point in the history
Reduce automation store updates and API fetches
  • Loading branch information
aptkingston authored Jul 30, 2024
2 parents 17c96f7 + 32ba04c commit d1d0eae
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/builder/src/stores/builder/automations.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ const automationActions = store => ({
disabled: false,
}
const response = await store.actions.save(automation)
await store.actions.fetch()
store.actions.select(response._id)
return response
},
duplicate: async automation => {
Expand All @@ -98,33 +96,36 @@ const automationActions = store => ({
_id: undefined,
_ref: undefined,
})
await store.actions.fetch()
store.actions.select(response._id)
return response
},
save: async automation => {
const response = await API.updateAutomation(automation)

await store.actions.fetch()
store.actions.select(response._id)
return response.automation
},
delete: async automation => {
await API.deleteAutomation({
automationId: automation?._id,
automationRev: automation?._rev,
})

store.update(state => {
// Remove the automation
state.automations = state.automations.filter(
x => x._id !== automation._id
)

// Select a new automation if required
if (automation._id === state.selectedAutomationId) {
store.actions.select(state.automations[0]?._id)
state.selectedAutomationId = state.automations[0]?._id || null
}

// Clear out automationDisplayData for the automation
delete state.automationDisplayData[automation._id]
return state
})
await store.actions.fetch()
},
toggleDisabled: async automationId => {
let automation
Expand Down Expand Up @@ -381,7 +382,7 @@ export const selectedAutomation = derived(automationStore, $automationStore => {
export const selectedAutomationDisplayData = derived(
[automationStore, selectedAutomation],
([$automationStore, $selectedAutomation]) => {
if (!$selectedAutomation._id) {
if (!$selectedAutomation?._id) {
return null
}
return $automationStore.automationDisplayData[$selectedAutomation._id]
Expand Down

0 comments on commit d1d0eae

Please sign in to comment.