Skip to content

Commit

Permalink
Extract and typescript-ify datatype selection in wfeditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Dec 10, 2024
1 parent 43095e2 commit f30d133
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
58 changes: 58 additions & 0 deletions client/src/components/Workflow/Editor/Forms/FormDatatype.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { computed } from "vue";
import type { DatatypesMapperModel } from "@/components/Datatypes/model";
import FormElement from "@/components/Form/FormElement.vue";
const props = withDefaults(
defineProps<{
id: string;
value?: string;
title: string;
help: string;
datatypes: DatatypesMapperModel["datatypes"];
}>(),
{
value: null,
}
);
const emit = defineEmits(["onChange"]);
const datatypeExtensions = computed(() => {
const extensions = [];
for (const key in props.datatypes) {
extensions.push({ 0: props.datatypes[key] || "", 1: props.datatypes[key] || "" });
}
extensions.sort((a, b) => (a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0));
extensions.unshift({
0: "Sequences",
1: "Sequences",
});
extensions.unshift({
0: "Roadmaps",
1: "Roadmaps",
});
extensions.unshift({
0: "Leave unchanged",
1: "",
});
return extensions;
});
function onChange(newDatatype: unknown) {
emit("onChange", newDatatype);
}
</script>

<template>
<FormElement
:id="id"
:value="value"
:attributes="{ options: datatypeExtensions }"
:title="title"
type="select"
:help="help"
@input="onChange" />
</template>
29 changes: 5 additions & 24 deletions client/src/components/Workflow/Editor/Forms/FormOutput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
title="Rename dataset"
type="text"
@input="onInput" />
<FormElement
<FormDatatype
:id="actionNames.ChangeDatatypeAction__newtype"
:value="formData[actionNames.ChangeDatatypeAction__newtype]"
:attributes="{ options: datatypeExtensions }"
:datatypes="datatypes"
title="Change datatype"
type="select"
help="This action will change the datatype of the output to the indicated datatype."
@input="onDatatype" />
@onChange="onDatatype" />
<FormElement
:id="actionNames.TagDatasetAction__tags"
:value="formData[actionNames.TagDatasetAction__tags]"
Expand Down Expand Up @@ -79,6 +78,7 @@
<script>
import FormCard from "@/components/Form/FormCard";
import FormElement from "@/components/Form/FormElement";
import FormDatatype from "@/components/Workflow/Editor/Forms/FormDatatype";
import FormOutputLabel from "@/components/Workflow/Editor/Forms/FormOutputLabel";
const actions = [
Expand All @@ -101,6 +101,7 @@ export default {
FormCard,
FormElement,
FormOutputLabel,
FormDatatype,
},
props: {
outputName: {
Expand Down Expand Up @@ -148,26 +149,6 @@ export default {
});
return index;
},
datatypeExtensions() {
const extensions = [];
for (const key in this.datatypes) {
extensions.push({ 0: this.datatypes[key], 1: this.datatypes[key] });
}
extensions.sort((a, b) => (a.label > b.label ? 1 : a.label < b.label ? -1 : 0));
extensions.unshift({
0: "Sequences",
1: "Sequences",
});
extensions.unshift({
0: "Roadmaps",
1: "Roadmaps",
});
extensions.unshift({
0: "Leave unchanged",
1: "",
});
return extensions;
},
renameHelp() {
/* TODO: FormElement should provide a slot for custom help templating instead. */
const helpLink = `<a href="${this.renameHelpUrl}">here</a>`;
Expand Down

0 comments on commit f30d133

Please sign in to comment.