From ad6af8d1b299dcf8f4d58dba43fe530c182ff160 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 4 Apr 2024 15:33:55 -0500 Subject: [PATCH] [24.0] Do not save workflow on Run without user confirmation This adds a modal when the user runs a workflow with changes, that asks for user confirmation on whether to proceed without saving changes or to save changes and then proceed. Currently, we _always_ save the workflow when it is run (even if there are no changes at all). Fixes https://github.com/galaxyproject/galaxy/issues/17903 --- .../src/components/Workflow/Editor/Index.vue | 20 +++- .../Workflow/Editor/SaveChangesModal.vue | 97 +++++++++++++++++++ 2 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 client/src/components/Workflow/Editor/SaveChangesModal.vue diff --git a/client/src/components/Workflow/Editor/Index.vue b/client/src/components/Workflow/Editor/Index.vue index a283e5b863b2..ffb147416fc1 100644 --- a/client/src/components/Workflow/Editor/Index.vue +++ b/client/src/components/Workflow/Editor/Index.vue @@ -13,6 +13,7 @@ @onRefactor="onRefactor" @onShow="hideModal" /> + import { Toast } from "composables/toast"; import { storeToRefs } from "pinia"; -import Vue, { computed, onUnmounted, ref, unref } from "vue"; +import Vue, { computed, nextTick, onUnmounted, ref, unref } from "vue"; import { getUntypedWorkflowParameters } from "@/components/Workflow/Editor/modules/parameters"; import { ConfirmDialog } from "@/composables/confirmDialog"; @@ -192,6 +193,7 @@ import WorkflowLint from "./Lint.vue"; import MessagesModal from "./MessagesModal.vue"; import WorkflowOptions from "./Options.vue"; import RefactorConfirmationModal from "./RefactorConfirmationModal.vue"; +import SaveChangesModal from "./SaveChangesModal.vue"; import StateUpgradeModal from "./StateUpgradeModal.vue"; import WorkflowGraph from "./WorkflowGraph.vue"; import MarkdownEditor from "@/components/Markdown/MarkdownEditor.vue"; @@ -204,6 +206,7 @@ export default { components: { MarkdownEditor, FlexPanel, + SaveChangesModal, StateUpgradeModal, ToolPanel, FormDefault, @@ -337,6 +340,8 @@ export default { showSaveAsModal: false, transform: { x: 0, y: 0, k: 1 }, graphOffset: { left: 0, top: 0, width: 0, height: 0 }, + showSaveChangesModal: false, + navUrl: "", }; }, computed: { @@ -677,14 +682,21 @@ export default { const runUrl = `/workflows/run?id=${this.id}`; this.onNavigate(runUrl); }, - async onNavigate(url) { + async onNavigate(url, forceSave = false, ignoreChanges = false) { if (this.isNewTempWorkflow) { await this.onCreate(); - } else { - await this.onSave(true); + } else if (this.hasChanges && !forceSave && !ignoreChanges) { + // if there are changes, prompt user to save or discard or cancel + this.navUrl = url; + this.showSaveChangesModal = true; + return; + } else if (forceSave) { + // when forceSave is true, save the workflow before navigating + await this.onSave(); } this.hasChanges = false; + await nextTick(); this.$router.push(url); }, onSave(hideProgress = false) { diff --git a/client/src/components/Workflow/Editor/SaveChangesModal.vue b/client/src/components/Workflow/Editor/SaveChangesModal.vue new file mode 100644 index 000000000000..9a2b5bbda2d0 --- /dev/null +++ b/client/src/components/Workflow/Editor/SaveChangesModal.vue @@ -0,0 +1,97 @@ + + +