From cad066c6681e101716ea8c0ebce2ff8470d6e77d Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 30 Jul 2024 10:03:24 +0100 Subject: [PATCH] Reduced the number of unnecessary calls to update the automation store or fetch automations. The contant updates appeared to cause issues with routify --- .../builder/src/stores/builder/automations.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 57c823da9b..cab8090424 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -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 => { @@ -98,14 +96,13 @@ 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 => { @@ -113,18 +110,22 @@ const automationActions = store => ({ 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 @@ -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]