From 15fbd8fcae8baca55aad4e3f09d1d23f7528002b Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 7 Jul 2022 23:39:16 +0200 Subject: [PATCH] 6512 - duplicate automation --- .../src/builderStore/store/automation/index.js | 14 +++++++++++++- .../AutomationPanel/EditAutomationPopover.svelte | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index cf42492c05..93e9cb97b0 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -56,7 +56,19 @@ const automationActions = store => ({ return state }) }, - + duplicate: async automation => { + const response = await API.createAutomation({ + ...automation, + name: `${automation.name} - copy`, + _id: undefined, + _ref: undefined, + }) + store.update(state => { + state.automations = [...state.automations, response.automation] + store.actions.select(response.automation) + return state + }) + }, save: async automation => { const response = await API.updateAutomation(automation) store.update(state => { diff --git a/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte index 0d858d7a19..30892882bf 100644 --- a/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte @@ -19,12 +19,23 @@ notifications.error("Error deleting automation") } } + + async function duplicateAutomation() { + try { + await automationStore.actions.duplicate(automation) + notifications.success("Automation has been duplicated successfully") + $goto(`./${$automationStore.selectedAutomation.automation._id}`) + } catch (error) { + notifications.error("Error duplicating automation") + } + }
+ Duplicate Edit Delete