From 9e4e81cec5b280135dc937fde0c6f322da520cf1 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 1 Feb 2024 10:24:23 -0600 Subject: [PATCH 01/17] fix request handling on client for WorkflowEditor create/save as --- .../src/components/Workflow/Editor/Index.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/client/src/components/Workflow/Editor/Index.vue b/client/src/components/Workflow/Editor/Index.vue index 122285db6b0..fd94a48c053 100644 --- a/client/src/components/Workflow/Editor/Index.vue +++ b/client/src/components/Workflow/Editor/Index.vue @@ -178,6 +178,7 @@ import { hide_modal } from "@/layout/modal"; import { getAppRoot } from "@/onload/loadConfig"; import { useScopePointerStore } from "@/stores/scopePointerStore"; import { LastQueue } from "@/utils/promise-queue"; +import { errorMessageAsString } from "@/utils/simple-error"; import { defaultPosition } from "./composables/useDefaultStepPosition"; import { fromSimple, toSimple } from "./modules/model"; @@ -555,7 +556,15 @@ export default { this.hasChanges = false; await this.routeToWorkflow(newId); } catch (e) { - this.onWorkflowError("Saving workflow failed, please contact an administrator."); + if (create) { + throw e; + } + const errorHeading = `Saving workflow as '${rename_name}' failed`; + this.onWorkflowError(errorHeading, errorMessageAsString(e) || "Please contact an administrator.", { + Ok: () => { + this.hideModal(); + }, + }); } }, onSaveAs() { @@ -617,13 +626,15 @@ export default { ); } } catch (e) { - this.onWorkflowError("Creating workflow failed"), - e || "Please contact an administrator.", + this.onWorkflowError( + "Creating workflow failed", + errorMessageAsString(e) || "Please contact an administrator.", { Ok: () => { this.hideModal(); }, - }; + } + ); } }, nameValidate() { From 194f6bdecbdc8b291bc24a6eec69f1d34a820660 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 1 Feb 2024 10:15:42 -0600 Subject: [PATCH 02/17] use `api/workflows` endpoint instead of `save_workflow_as` controller --- .../src/components/Workflow/Editor/Index.vue | 44 +++++-------------- client/src/components/Workflow/services.js | 12 +++++ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/client/src/components/Workflow/Editor/Index.vue b/client/src/components/Workflow/Editor/Index.vue index fd94a48c053..4772e9554c5 100644 --- a/client/src/components/Workflow/Editor/Index.vue +++ b/client/src/components/Workflow/Editor/Index.vue @@ -180,6 +180,7 @@ import { useScopePointerStore } from "@/stores/scopePointerStore"; import { LastQueue } from "@/utils/promise-queue"; import { errorMessageAsString } from "@/utils/simple-error"; +import { Services } from "../services"; import { defaultPosition } from "./composables/useDefaultStepPosition"; import { fromSimple, toSimple } from "./modules/model"; import { getModule, getVersions, loadWorkflow, saveWorkflow } from "./modules/services"; @@ -275,6 +276,7 @@ export default { }); function resetStores() { + hasChanges.value = false; connectionStore.$reset(); stepStore.$reset(); stateStore.$reset(); @@ -319,6 +321,7 @@ export default { annotation: null, name: "Unnamed Workflow", tags: this.workflowTags, + services: null, stateMessages: [], insertedStateMessages: [], refactorActions: [], @@ -382,6 +385,7 @@ export default { }, }, async created() { + this.services = new Services(); this.lastQueue = new LastQueue(); await this._loadCurrent(this.id, this.version); hide_modal(); @@ -533,9 +537,9 @@ export default { onDownload() { window.location = `${getAppRoot()}api/workflows/${this.id}/download?format=json-download`; }, - async doSaveAs(create = false) { - const rename_name = create ? this.name : this.saveAsName ?? `SavedAs_${this.name}`; - const rename_annotation = create ? this.annotation || "" : this.saveAsAnnotation ?? ""; + async doSaveAs() { + const rename_name = this.saveAsName ?? `SavedAs_${this.name}`; + const rename_annotation = this.saveAsAnnotation ?? ""; // This is an old web controller endpoint that wants form data posted... const formData = new FormData(); @@ -547,18 +551,9 @@ export default { try { const response = await axios.post(`${getAppRoot()}workflow/save_workflow_as`, formData); const newId = response.data; - - if (!create) { - this.name = rename_name; - this.annotation = rename_annotation; - } - this.hasChanges = false; await this.routeToWorkflow(newId); } catch (e) { - if (create) { - throw e; - } const errorHeading = `Saving workflow as '${rename_name}' failed`; this.onWorkflowError(errorHeading, errorMessageAsString(e) || "Please contact an administrator.", { Ok: () => { @@ -605,26 +600,11 @@ export default { return; } try { - // if nothing other than payload vars changed, just use `create` endpoint - if (!this.hasChanges) { - const payload = { - workflow_name: this.name, - workflow_annotation: this.annotation || "", - workflow_tags: this.tags, - }; - const { data } = await axios.put(`${getAppRoot()}workflow/create`, payload); - const { id, message } = data; - - await this.routeToWorkflow(id); - Toast.success(message); - } else { - // otherwise, use `save_as` endpoint to include steps, etc. - await this.doSaveAs(true); - const stepCount = Object.keys(this.steps).length; - Toast.success( - `Created workflow ${this.name} with ${stepCount} ${stepCount === 1 ? "step" : "steps"}.` - ); - } + const { id, name, number_of_steps } = await this.services.createWorkflow(this); + const message = `Created new workflow '${name}' with ${number_of_steps} steps.`; + this.hasChanges = false; + await this.routeToWorkflow(id); + Toast.success(message); } catch (e) { this.onWorkflowError( "Creating workflow failed", diff --git a/client/src/components/Workflow/services.js b/client/src/components/Workflow/services.js index e7a0f0fcaa3..d354fda8182 100644 --- a/client/src/components/Workflow/services.js +++ b/client/src/components/Workflow/services.js @@ -3,6 +3,8 @@ import axios from "axios"; import { withPrefix } from "utils/redirect"; import { rethrowSimple } from "utils/simple-error"; +import { toSimple } from "./Editor/modules/model"; + /** Workflow data request helper **/ export class Services { async copyWorkflow(workflow) { @@ -27,6 +29,16 @@ export class Services { } } + async createWorkflow(workflow) { + const url = withPrefix("/api/workflows"); + try { + const { data } = await axios.post(url, { workflow: toSimple(workflow.id, workflow) }); + return data; + } catch (e) { + rethrowSimple(e); + } + } + async deleteWorkflow(id) { const url = withPrefix(`/api/workflows/${id}`); try { From 5f6090291cb6acf68004f61059d5d21845797e5c Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 1 Feb 2024 10:16:58 -0600 Subject: [PATCH 03/17] fix workflow editor creater bugs Prevent the "expected Object got Array" error message. Ensure `CreatorEditor` is loaded with existing creator(s). --- client/src/components/SchemaOrg/CreatorEditor.vue | 8 ++++++-- client/src/components/Workflow/Editor/Attributes.vue | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/components/SchemaOrg/CreatorEditor.vue b/client/src/components/SchemaOrg/CreatorEditor.vue index 0a0e1d0066d..1310a1a2dfa 100644 --- a/client/src/components/SchemaOrg/CreatorEditor.vue +++ b/client/src/components/SchemaOrg/CreatorEditor.vue @@ -52,6 +52,7 @@ export default { props: { creators: { type: Array, + default: () => [], }, }, data() { @@ -61,8 +62,11 @@ export default { }; }, watch: { - creators() { - this.creatorsCurrent = this.creators; + creators: { + handler(newCreators) { + this.creatorsCurrent = newCreators; + }, + immediate: true, }, }, methods: { diff --git a/client/src/components/Workflow/Editor/Attributes.vue b/client/src/components/Workflow/Editor/Attributes.vue index 2247b4dcad4..062635e6567 100644 --- a/client/src/components/Workflow/Editor/Attributes.vue +++ b/client/src/components/Workflow/Editor/Attributes.vue @@ -97,7 +97,7 @@ export default { default: "", }, creator: { - type: Object, + type: Array, default: null, }, version: { From 93e0725f0ee96a405c8b9d677da6e9326c7de340 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 1 Feb 2024 10:57:51 -0600 Subject: [PATCH 04/17] use POST api/workflows instead of `save_workflow_as` controller --- .../src/components/Workflow/Editor/Index.vue | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/client/src/components/Workflow/Editor/Index.vue b/client/src/components/Workflow/Editor/Index.vue index 4772e9554c5..84b079f6f53 100644 --- a/client/src/components/Workflow/Editor/Index.vue +++ b/client/src/components/Workflow/Editor/Index.vue @@ -164,7 +164,6 @@