Skip to content

Commit

Permalink
Fixes for mapping workflow labels to markdown selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Feb 6, 2024
1 parent e5dc724 commit 7c1174c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 34 deletions.
28 changes: 23 additions & 5 deletions client/src/components/Markdown/MarkdownDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { jobsFetcher } from "@/api/jobs";
import { workflowsFetcher } from "@/api/workflows";
import { useHistoryStore } from "@/stores/historyStore";
import { WorkflowLabels } from "./labels";
import MarkdownSelector from "./MarkdownSelector.vue";
import MarkdownVisualization from "./MarkdownVisualization.vue";
import DataDialog from "@/components/DataDialog/DataDialog.vue";
Expand All @@ -21,7 +23,7 @@ interface MarkdownDialogProps {
argumentName?: string;
argumentType?: string;
argumentPayload?: object;
labels?: string[];
labels?: WorkflowLabels;
useLabels: boolean;
}
Expand All @@ -42,6 +44,22 @@ interface SelectTitles {
type SelectType = "job_id" | "invocation_id" | "history_dataset_id" | "history_dataset_collection_id";
const effectiveLabels = computed(() => {
if (!props.labels) {
return [] as string[];
}
const selectSteps = props.argumentType == "job_id";
const filteredLabels: string[] = [];
for (const label of props.labels) {
if (selectSteps && label.type == "step") {
filteredLabels.push(label.label);
} else if (!selectSteps && label.type != "step") {
filteredLabels.push(label.label);
}
}
return filteredLabels;
});
const selectorConfig = {
job_id: {
labelTitle: "Step",
Expand All @@ -50,10 +68,10 @@ const selectorConfig = {
labelTitle: "Step",
},
history_dataset_id: {
labelTitle: "Output",
labelTitle: "Dataset (Input/Output)",
},
history_dataset_collection_id: {
labelTitle: "Output",
labelTitle: "Dataset Collection (Input/Output)",
},
};
Expand Down Expand Up @@ -207,15 +225,15 @@ if (props.argumentType == "workflow_id") {
v-if="selectedShow"
:initial-value="argumentType"
:argument-name="argumentName"
:labels="labels"
:labels="effectiveLabels"
:label-title="selectedLabelTitle"
@onOk="onOk"
@onCancel="onCancel" />
<MarkdownVisualization
v-else-if="visualizationShow"
:argument-name="argumentName"
:argument-payload="argumentPayload"
:labels="labels"
:labels="effectiveLabels"
:use-labels="useLabels"
:history="currentHistoryId"
@onOk="onVisualization"
Expand Down
34 changes: 5 additions & 29 deletions client/src/components/Markdown/MarkdownToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
:argument-type="selectedType"
:argument-name="selectedArgumentName"
:argument-payload="selectedPayload"
:labels="selectedLabels"
:labels="workflowLabels"
:use-labels="isWorkflow"
@onInsert="onInsert"
@onCancel="onCancel" />
Expand All @@ -48,6 +48,7 @@ import { getAppRoot } from "onload/loadConfig";
import Vue from "vue";
import { directiveEntry } from "./directives.ts";
import { fromSteps } from "./labels.ts";
import MarkdownDialog from "./MarkdownDialog";
Vue.use(BootstrapVue);
Expand Down Expand Up @@ -105,7 +106,6 @@ export default {
return {
selectedArgumentName: null,
selectedType: null,
selectedLabels: undefined,
selectedShow: false,
selectedPayload: null,
visualizationIndex: {},
Expand Down Expand Up @@ -244,33 +244,14 @@ export default {
],
};
},
workflowLabels() {
return fromSteps(this.steps);
},
},
created() {
this.getVisualizations();
},
methods: {
getSteps() {
const steps = [];
this.steps &&
Object.values(this.steps).forEach((step) => {
if (step.label) {
steps.push(step.label);
}
});
return steps;
},
getOutputs() {
const outputLabels = [];
this.steps &&
Object.values(this.steps).forEach((step) => {
step.workflow_outputs.forEach((workflowOutput) => {
if (workflowOutput.label) {
outputLabels.push(workflowOutput.label);
}
});
});
return outputLabels;
},
getArgumentTitle(argumentName) {
return (
argumentName[0].toUpperCase() +
Expand Down Expand Up @@ -320,7 +301,6 @@ export default {
this.selectedArgumentName = argumentName;
this.selectedType = "visualization_id";
this.selectedPayload = this.visualizationIndex[argumentName];
this.selectedLabels = this.getOutputs();
this.selectedShow = true;
},
onHistoryId(argumentName) {
Expand All @@ -331,13 +311,11 @@ export default {
onHistoryDatasetId(argumentName) {
this.selectedArgumentName = argumentName;
this.selectedType = "history_dataset_id";
this.selectedLabels = this.getOutputs();
this.selectedShow = true;
},
onHistoryCollectionId(argumentName) {
this.selectedArgumentName = argumentName;
this.selectedType = "history_dataset_collection_id";
this.selectedLabels = this.getOutputs();
this.selectedShow = true;
},
onWorkflowId(argumentName) {
Expand All @@ -348,13 +326,11 @@ export default {
onJobId(argumentName) {
this.selectedArgumentName = argumentName;
this.selectedType = "job_id";
this.selectedLabels = this.getSteps();
this.selectedShow = true;
},
onInvocationId(argumentName) {
this.selectedArgumentName = argumentName;
this.selectedType = "invocation_id";
this.selectedLabels = this.getSteps();
this.selectedShow = true;
},
async getVisualizations() {
Expand Down
48 changes: 48 additions & 0 deletions client/src/components/Markdown/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// abstractions for dealing with workflows labels and
// connecting them to the Markdown editor

type WorkflowLabelKind = "input" | "output" | "step";

interface WorkflowLabel {
label: string;
type: WorkflowLabelKind;
}

interface StepOutput {
label?: string;
}

interface Step {
label?: string;
type: string;
workflow_outputs: StepOutput[];
}

export type WorkflowLabels = WorkflowLabel[];

export function fromSteps(steps?: Step[]): WorkflowLabels {
const labels: WorkflowLabels = [];

if (!steps) {
return labels;
}

Object.values(steps).forEach((step) => {
const stepType = step.type;
if (step.label) {
const isInput = ["data_input", "data_collection_input", "parameter_input"].indexOf(stepType) >= 0;
if (isInput) {
labels.push({ type: "input", label: step.label });
} else {
labels.push({ type: "step", label: step.label });
}
}
step.workflow_outputs.forEach((workflowOutput) => {
if (workflowOutput.label) {
labels.push({ type: "output", label: workflowOutput.label });
}
});
});

return labels;
}

0 comments on commit 7c1174c

Please sign in to comment.