From 86fa3a6b9e58ae7c17d03929ab55e161dcddabcb Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Wed, 18 Aug 2021 16:25:05 +0200 Subject: [PATCH 1/3] Updates webhook UUIDs to a new one when duplicating --- .../editor-ui/src/components/DuplicateWorkflowDialog.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue index 839e00efac..d24776a60e 100644 --- a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue +++ b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue @@ -44,6 +44,8 @@ import { workflowHelpers } from "@/components/mixins/workflowHelpers"; import { showMessage } from "@/components/mixins/showMessage"; import TagsDropdown from "@/components/TagsDropdown.vue"; import Modal from "./Modal.vue"; +import { v4 as uuidv4} from 'uuid'; +import { INodeUi } from "../Interface"; export default mixins(showMessage, workflowHelpers).extend({ components: { TagsDropdown, Modal }, @@ -107,6 +109,13 @@ export default mixins(showMessage, workflowHelpers).extend({ return; } + const allNodes = this.$store.getters.allNodes; + allNodes.forEach((node: INodeUi) => { + if (node.webhookId) { + node.webhookId = uuidv4(); + } + }); + this.$data.isSaving = true; const saved = await this.saveAsNewWorkflow({name, tags: this.currentTagIds}); From 82dbbcd2e0e19861d720bc5a3ffa7326844188b0 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 19 Aug 2021 10:51:27 +0200 Subject: [PATCH 2/3] Changed the webhook id change code placement --- .../src/components/DuplicateWorkflowDialog.vue | 11 +---------- .../src/components/mixins/workflowHelpers.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue index d24776a60e..2f570c4ea7 100644 --- a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue +++ b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue @@ -44,8 +44,6 @@ import { workflowHelpers } from "@/components/mixins/workflowHelpers"; import { showMessage } from "@/components/mixins/showMessage"; import TagsDropdown from "@/components/TagsDropdown.vue"; import Modal from "./Modal.vue"; -import { v4 as uuidv4} from 'uuid'; -import { INodeUi } from "../Interface"; export default mixins(showMessage, workflowHelpers).extend({ components: { TagsDropdown, Modal }, @@ -109,16 +107,9 @@ export default mixins(showMessage, workflowHelpers).extend({ return; } - const allNodes = this.$store.getters.allNodes; - allNodes.forEach((node: INodeUi) => { - if (node.webhookId) { - node.webhookId = uuidv4(); - } - }); - this.$data.isSaving = true; - const saved = await this.saveAsNewWorkflow({name, tags: this.currentTagIds}); + const saved = await this.saveAsNewWorkflow({name, tags: this.currentTagIds, updateWebhookUrls: true}); if (saved) { this.closeDialog(); diff --git a/packages/editor-ui/src/components/mixins/workflowHelpers.ts b/packages/editor-ui/src/components/mixins/workflowHelpers.ts index ec4acf820c..4521523c69 100644 --- a/packages/editor-ui/src/components/mixins/workflowHelpers.ts +++ b/packages/editor-ui/src/components/mixins/workflowHelpers.ts @@ -39,6 +39,7 @@ import { showMessage } from '@/components/mixins/showMessage'; import { isEqual } from 'lodash'; import mixins from 'vue-typed-mixins'; +import { v4 as uuidv4} from 'uuid'; export const workflowHelpers = mixins( externalHooks, @@ -435,13 +436,20 @@ export const workflowHelpers = mixins( } }, - async saveAsNewWorkflow ({name, tags}: {name?: string, tags?: string[]} = {}): Promise { + async saveAsNewWorkflow ({name, tags, updateWebhookUrls}: {name?: string, tags?: string[], updateWebhookUrls?: boolean} = {}): Promise { try { this.$store.commit('addActiveAction', 'workflowSaving'); const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave(); // make sure that the new ones are not active workflowDataRequest.active = false; + if (updateWebhookUrls) { + workflowDataRequest.nodes!.forEach(node => { + if (node.webhookId) { + node.webhookId = uuidv4(); + } + }); + } if (name) { workflowDataRequest.name = name.trim(); @@ -452,10 +460,8 @@ export const workflowHelpers = mixins( } const workflowData = await this.restApi().createNewWorkflow(workflowDataRequest); - this.$store.commit('setActive', workflowData.active || false); - this.$store.commit('setWorkflowId', workflowData.id); + this.$store.commit('setWorkflow', workflowData); this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false}); - this.$store.commit('setWorkflowSettings', workflowData.settings || {}); this.$store.commit('setStateDirty', false); const createdTags = (workflowData.tags || []) as ITag[]; From 3b73cb6a564c9a0d5c0714d988dccd347e9fe8a8 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 19 Aug 2021 15:26:38 +0200 Subject: [PATCH 3/3] Adjustments suggested by @mutdmour --- .../editor-ui/src/components/DuplicateWorkflowDialog.vue | 2 +- .../editor-ui/src/components/mixins/workflowHelpers.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue index 2f570c4ea7..be8375b51d 100644 --- a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue +++ b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue @@ -109,7 +109,7 @@ export default mixins(showMessage, workflowHelpers).extend({ this.$data.isSaving = true; - const saved = await this.saveAsNewWorkflow({name, tags: this.currentTagIds, updateWebhookUrls: true}); + const saved = await this.saveAsNewWorkflow({name, tags: this.currentTagIds, resetWebhookUrls: true}); if (saved) { this.closeDialog(); diff --git a/packages/editor-ui/src/components/mixins/workflowHelpers.ts b/packages/editor-ui/src/components/mixins/workflowHelpers.ts index 4521523c69..656737358a 100644 --- a/packages/editor-ui/src/components/mixins/workflowHelpers.ts +++ b/packages/editor-ui/src/components/mixins/workflowHelpers.ts @@ -436,18 +436,19 @@ export const workflowHelpers = mixins( } }, - async saveAsNewWorkflow ({name, tags, updateWebhookUrls}: {name?: string, tags?: string[], updateWebhookUrls?: boolean} = {}): Promise { + async saveAsNewWorkflow ({name, tags, resetWebhookUrls}: {name?: string, tags?: string[], resetWebhookUrls?: boolean} = {}): Promise { try { this.$store.commit('addActiveAction', 'workflowSaving'); const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave(); // make sure that the new ones are not active workflowDataRequest.active = false; - if (updateWebhookUrls) { - workflowDataRequest.nodes!.forEach(node => { + if (resetWebhookUrls) { + workflowDataRequest.nodes = workflowDataRequest.nodes!.map(node => { if (node.webhookId) { node.webhookId = uuidv4(); } + return node; }); }