From 3da65773480c7f57150e820a310ae185e3bfa216 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 26 Aug 2021 08:53:58 +0200 Subject: [PATCH] rename automation --- .../builderStore/store/automation/index.js | 17 +++-- .../EditAutomationPopover.svelte | 15 ++-- .../UpdateAutomationModal.svelte | 76 +++++++++++++++++++ 3 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 packages/builder/src/components/automation/AutomationPanel/UpdateAutomationModal.svelte diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index c372f27bb7..f522c7bba1 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -46,21 +46,24 @@ const automationActions = store => ({ return state }) }, - save: async ({ automation }) => { + save: async automation => { const UPDATE_AUTOMATION_URL = `/api/automations` const response = await api.put(UPDATE_AUTOMATION_URL, automation) const json = await response.json() store.update(state => { + const newAutomation = json.automation const existingIdx = state.automations.findIndex( existing => existing._id === automation._id ) - state.automations.splice(existingIdx, 1, json.automation) - state.automations = state.automations - store.actions.select(json.automation) - return state + if (existingIdx !== -1) { + state.automations.splice(existingIdx, 1, newAutomation) + state.automations = [...state.automations] + store.actions.select(newAutomation) + return state + } }) }, - delete: async ({ automation }) => { + delete: async automation => { const { _id, _rev } = automation const DELETE_AUTOMATION_URL = `/api/automations/${_id}/${_rev}` await api.delete(DELETE_AUTOMATION_URL) @@ -70,7 +73,7 @@ const automationActions = store => ({ existing => existing._id === _id ) state.automations.splice(existingIdx, 1) - state.automations = state.automations + state.automations = [...state.automations] state.selectedAutomation = null state.selectedBlock = null return state diff --git a/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte index a99c11e9e1..fc12b60676 100644 --- a/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte @@ -1,20 +1,17 @@ + + + + + + + Learn about automations + + + + +