Skip to content

Commit

Permalink
create uuid composable and...
Browse files Browse the repository at this point in the history
handle errors caused by wf creation without annotation
  • Loading branch information
ahmedhamidawan committed Oct 31, 2023
1 parent 44b2c86 commit b00879a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
3 changes: 2 additions & 1 deletion client/src/components/Workflow/Editor/Attributes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import LicenseSelector from "components/License/LicenseSelector";
import CreatorEditor from "components/SchemaOrg/CreatorEditor";
import StatelessTags from "components/TagsMultiselect/StatelessTags";
import { Services } from "components/Workflow/services";
import { hasUuid } from "composables/uuid";
import { format, parseISO } from "date-fns";
import Vue from "vue";
Expand Down Expand Up @@ -204,7 +205,7 @@ export default {
this.messageVariant = "danger";
},
onAttributes(data) {
if (this.id !== "new_temp_workflow") {
if (!hasUuid("workflow_editor", this.id)) {
this.services.updateWorkflow(this.id, data).catch((error) => {
this.onError(error);
});
Expand Down
20 changes: 11 additions & 9 deletions client/src/components/Workflow/Editor/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ import Vue, { computed, onUnmounted, ref } from "vue";
import { getUntypedWorkflowParameters } from "@/components/Workflow/Editor/modules/parameters";
import { ConfirmDialog } from "@/composables/confirmDialog";
import { useDatatypesMapper } from "@/composables/datatypesMapper";
import { useUuid } from "@/composables/uuid";
import { provideScopedWorkflowStores } from "@/composables/workflowStores";
import { hide_modal } from "@/layout/modal";
import { getAppRoot } from "@/onload/loadConfig";
Expand All @@ -196,8 +197,6 @@ import ToolPanel from "@/components/Panels/ToolPanel.vue";
import FormDefault from "@/components/Workflow/Editor/Forms/FormDefault.vue";
import FormTool from "@/components/Workflow/Editor/Forms/FormTool.vue";
const NEW_TEMP_ID = "new_temp_workflow";
export default {
components: {
MarkdownEditor,
Expand All @@ -216,7 +215,7 @@ export default {
props: {
workflowId: {
type: String,
default: NEW_TEMP_ID,
default: undefined,
},
initialVersion: {
type: Number,
Expand All @@ -242,7 +241,10 @@ export default {
setup(props, { emit }) {
const { datatypes, datatypesMapper, datatypesMapperLoading } = useDatatypesMapper();
const { connectionStore, stepStore, stateStore, commentStore } = provideScopedWorkflowStores(props.id);
const { uuid, destroyUuid } = useUuid("workflow_editor");
const id = ref(props.workflowId || uuid.value);
const { connectionStore, stepStore, stateStore, commentStore } = provideScopedWorkflowStores(id.value);
const { comments } = storeToRefs(commentStore);
const { getStepIndex, steps } = storeToRefs(stepStore);
Expand Down Expand Up @@ -273,11 +275,13 @@ export default {
}
onUnmounted(() => {
destroyUuid();
resetStores();
emit("update:confirmation", false);
});
return {
id,
connectionStore,
hasChanges,
hasInvalidConnections,
Expand All @@ -296,7 +300,6 @@ export default {
},
data() {
return {
id: this.workflowId,
isCanvas: true,
markdownConfig: null,
markdownText: null,
Expand Down Expand Up @@ -343,12 +346,12 @@ export default {
return this.activeStep?.type == "tool";
},
isNewTempWorkflow() {
return this.id === NEW_TEMP_ID;
return !this.workflowId;
},
},
watch: {
id(newId, oldId) {
if (oldId && oldId !== NEW_TEMP_ID) {
if (oldId && !this.isNewTempWorkflow) {
this._loadCurrent(newId);
}
},
Expand Down Expand Up @@ -577,8 +580,7 @@ export default {
}
const payload = {
workflow_name: this.name,
workflow_annotation: this.annotation,
workflow_tags: this.tags,
workflow_annotation: this.annotation || "",
};
try {
Expand Down
10 changes: 8 additions & 2 deletions client/src/components/Workflow/Editor/modules/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ export async function loadWorkflow({ id, version = null }) {
export async function saveWorkflow(workflow) {
if (workflow.hasChanges) {
try {
const requestData = { workflow: toSimple(workflow.id, workflow), from_tool_form: true, tags: workflow.tags };
const requestData = {
workflow: toSimple(workflow.id, workflow),
from_tool_form: true,
tags: workflow.tags,
};
const { data } = await axios.put(`${getAppRoot()}api/workflows/${workflow.id}`, requestData);
workflow.name = data.name;
workflow.hasChanges = false;
workflow.stored = true;
workflow.version = data.version;
workflow.annotation = data.annotation;
if (workflow.annotation || data.annotation) {
workflow.annotation = data.annotation;
}
return data;
} catch (e) {
rethrowSimple(e);
Expand Down
35 changes: 35 additions & 0 deletions client/src/composables/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Vue, { ref } from "vue";

const uuidCounter = ref<number>(0);
const uuidRef = ref<Record<string, string[]>>({});

/**
* @param identifier What is this uuid for? default: "generic"
* @returns uuid and destroy function
*/
export function useUuid(identifier = "generic") {
const uuid = ref(String(`_${identifier}_uuid_${uuidCounter.value++}`));
if (!uuidRef.value[identifier]) {
Vue.set(uuidRef.value, identifier, [uuid.value]);
} else {
uuidRef.value[identifier]?.push(uuid.value);
}

/** Destroy the current uuid */
const destroyUuid = () => {
const uuids = uuidRef.value[identifier];
if (uuids) {
const index = uuids.indexOf(uuid.value);
if (index && index > -1) {
uuids.splice(index, 1);
}
} else {
Vue.delete(uuidRef.value, identifier);
}
};
return { uuid, destroyUuid };
}

export function hasUuid(identifier = "generic", uuid: string) {
return uuidRef.value[identifier]?.includes(uuid);
}
2 changes: 1 addition & 1 deletion lib/galaxy/managers/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def update_workflow_from_raw_description(
sanitized_name = sanitize_html(update_dict["name"])
workflow.name = sanitized_name
stored_workflow.name = sanitized_name
if "annotation" in update_dict:
if update_dict.get("annotation") is not None:
newAnnotation = sanitize_html(update_dict["annotation"])
sa_session = None if dry_run else trans.sa_session
self.add_item_annotation(sa_session, stored_workflow.user, stored_workflow, newAnnotation)
Expand Down

0 comments on commit b00879a

Please sign in to comment.