Changed the webhook id change code placement

This commit is contained in:
Omar Ajoue 2021-08-19 10:51:27 +02:00
parent 86fa3a6b9e
commit 82dbbcd2e0
2 changed files with 11 additions and 14 deletions

View file

@ -44,8 +44,6 @@ import { workflowHelpers } from "@/components/mixins/workflowHelpers";
import { showMessage } from "@/components/mixins/showMessage"; import { showMessage } from "@/components/mixins/showMessage";
import TagsDropdown from "@/components/TagsDropdown.vue"; import TagsDropdown from "@/components/TagsDropdown.vue";
import Modal from "./Modal.vue"; import Modal from "./Modal.vue";
import { v4 as uuidv4} from 'uuid';
import { INodeUi } from "../Interface";
export default mixins(showMessage, workflowHelpers).extend({ export default mixins(showMessage, workflowHelpers).extend({
components: { TagsDropdown, Modal }, components: { TagsDropdown, Modal },
@ -109,16 +107,9 @@ export default mixins(showMessage, workflowHelpers).extend({
return; return;
} }
const allNodes = this.$store.getters.allNodes;
allNodes.forEach((node: INodeUi) => {
if (node.webhookId) {
node.webhookId = uuidv4();
}
});
this.$data.isSaving = true; 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) { if (saved) {
this.closeDialog(); this.closeDialog();

View file

@ -39,6 +39,7 @@ import { showMessage } from '@/components/mixins/showMessage';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import { v4 as uuidv4} from 'uuid';
export const workflowHelpers = mixins( export const workflowHelpers = mixins(
externalHooks, externalHooks,
@ -435,13 +436,20 @@ export const workflowHelpers = mixins(
} }
}, },
async saveAsNewWorkflow ({name, tags}: {name?: string, tags?: string[]} = {}): Promise<boolean> { async saveAsNewWorkflow ({name, tags, updateWebhookUrls}: {name?: string, tags?: string[], updateWebhookUrls?: boolean} = {}): Promise<boolean> {
try { try {
this.$store.commit('addActiveAction', 'workflowSaving'); this.$store.commit('addActiveAction', 'workflowSaving');
const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave(); const workflowDataRequest: IWorkflowDataUpdate = await this.getWorkflowDataToSave();
// make sure that the new ones are not active // make sure that the new ones are not active
workflowDataRequest.active = false; workflowDataRequest.active = false;
if (updateWebhookUrls) {
workflowDataRequest.nodes!.forEach(node => {
if (node.webhookId) {
node.webhookId = uuidv4();
}
});
}
if (name) { if (name) {
workflowDataRequest.name = name.trim(); workflowDataRequest.name = name.trim();
@ -452,10 +460,8 @@ export const workflowHelpers = mixins(
} }
const workflowData = await this.restApi().createNewWorkflow(workflowDataRequest); const workflowData = await this.restApi().createNewWorkflow(workflowDataRequest);
this.$store.commit('setActive', workflowData.active || false); this.$store.commit('setWorkflow', workflowData);
this.$store.commit('setWorkflowId', workflowData.id);
this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false}); this.$store.commit('setWorkflowName', {newName: workflowData.name, setStateDirty: false});
this.$store.commit('setWorkflowSettings', workflowData.settings || {});
this.$store.commit('setStateDirty', false); this.$store.commit('setStateDirty', false);
const createdTags = (workflowData.tags || []) as ITag[]; const createdTags = (workflowData.tags || []) as ITag[];