diff --git a/packages/editor-ui/src/components/MainSidebar.vue b/packages/editor-ui/src/components/MainSidebar.vue index 92645942b2..863d028e1d 100644 --- a/packages/editor-ui/src/components/MainSidebar.vue +++ b/packages/editor-ui/src/components/MainSidebar.vue @@ -398,7 +398,7 @@ export default mixins( return; } - this.$store.commit('setWorkflowName', {newName: workflowName, setStateDirty: true}); + this.$store.commit('setWorkflowName', {newName: workflowName, setStateDirty: false}); this.$showMessage({ title: 'Workflow renamed', @@ -452,6 +452,7 @@ export default mixins( if(result) { const importConfirm = await this.confirmMessage(`When you switch workflows your current workflow changes will be lost.`, 'Save your Changes?', 'warning', 'Yes, switch workflows and forget changes'); if (importConfirm === true) { + this.$store.commit('setStateDirty', false); this.$router.push({ name: 'NodeViewNew' }); this.$showMessage({ diff --git a/packages/editor-ui/src/components/WorkflowOpen.vue b/packages/editor-ui/src/components/WorkflowOpen.vue index 5ef981ef5b..3f82f80a66 100644 --- a/packages/editor-ui/src/components/WorkflowOpen.vue +++ b/packages/editor-ui/src/components/WorkflowOpen.vue @@ -92,12 +92,28 @@ export default mixins( }, async openWorkflow (data: IWorkflowShortResponse, column: any) { // tslint:disable-line:no-any if (column.label !== 'Active') { + + const currentWorkflowId = this.$store.getters.workflowId; + + if (data.id === currentWorkflowId) { + this.$showMessage({ + title: 'Already open', + message: 'This is the current workflow', + type: 'error', + duration: 800, + }); + // Do nothing if current workflow is the one user chose to open + return; + } + const result = this.$store.getters.getStateIsDirty; if(result) { const importConfirm = await this.confirmMessage(`When you switch workflows your current workflow changes will be lost.`, 'Save your Changes?', 'warning', 'Yes, switch workflows and forget changes'); if (importConfirm === false) { return; } else { + // This is used to avoid duplicating the message + this.$store.commit('setStateDirty', false); this.$emit('openWorkflow', data.id); } } else { diff --git a/packages/editor-ui/src/components/mixins/workflowSave.ts b/packages/editor-ui/src/components/mixins/workflowSave.ts index c4d4001047..60dd135fe4 100644 --- a/packages/editor-ui/src/components/mixins/workflowSave.ts +++ b/packages/editor-ui/src/components/mixins/workflowSave.ts @@ -80,6 +80,8 @@ export const workflowSave = mixins( // Workflow exists already so update it await this.restApi().updateWorkflow(currentWorkflow, workflowData); } + // Set dirty = false before pushing route so unsaved changes message doesnt trigger. + this.$store.commit('setStateDirty', false); if (this.$route.params.name !== workflowData.id) { this.$router.push({ @@ -89,7 +91,6 @@ export const workflowSave = mixins( } this.$store.commit('removeActiveAction', 'workflowSaving'); - this.$store.commit('setStateDirty', false); this.$showMessage({ title: 'Workflow saved', message: `The workflow "${workflowData.name}" got saved!`, diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index 8c82de22f1..a41aa2f919 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -214,6 +214,21 @@ export default mixins( deep: true, }, }, + async beforeRouteLeave(to, from, next) { + const result = this.$store.getters.getStateIsDirty; + if(result) { + const importConfirm = await this.confirmMessage(`When you switch workflows your current workflow changes will be lost.`, 'Save your Changes?', 'warning', 'Yes, switch workflows and forget changes'); + if (importConfirm === false) { + next(false); + } else { + // Prevent other popups from displaying + this.$store.commit('setStateDirty', false); + next(); + } + } else { + next(); + } + }, computed: { activeNode (): INodeUi | null { return this.$store.getters.activeNode; @@ -358,6 +373,8 @@ export default mixins( await this.addNodes(data.nodes, data.connections); + this.$store.commit('setStateDirty', false); + return data; }, touchTap (e: MouseEvent | TouchEvent) { @@ -1339,6 +1356,8 @@ export default mixins( ]; await this.addNodes(defaultNodes); + this.$store.commit('setStateDirty', false); + }, async initView (): Promise { if (this.$route.params.action === 'workflowSave') { @@ -1351,9 +1370,17 @@ export default mixins( if (this.$route.name === 'ExecutionById') { // Load an execution const executionId = this.$route.params.id; - await this.openExecution(executionId); } else { + + const result = this.$store.getters.getStateIsDirty; + if(result) { + const importConfirm = await this.confirmMessage(`When you switch workflows your current workflow changes will be lost.`, 'Save your Changes?', 'warning', 'Yes, switch workflows and forget changes'); + if (importConfirm === false) { + return Promise.resolve(); + } + } + // Load a workflow let workflowId = null as string | null; if (this.$route.params.name) {