Skip to content

Commit

Permalink
Include output labels when updating report markdown for label changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Mar 28, 2024
1 parent fdcce9d commit df340f5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
15 changes: 13 additions & 2 deletions client/src/components/Workflow/Editor/Forms/FormDefault.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
:key="index"
:name="output.name"
:step="step"
:show-details="true" />
:show-details="true"
@onOutputLabel="onOutputLabel" />
</div>
</template>
</FormCard>
Expand All @@ -78,7 +79,14 @@ const props = defineProps<{
step: Step;
datatypes: DatatypesMapperModel["datatypes"];
}>();
const emit = defineEmits(["onAnnotation", "onLabel", "onAttemptRefactor", "onEditSubworkflow", "onSetData"]);
const emit = defineEmits([
"onAnnotation",
"onLabel",
"onAttemptRefactor",
"onEditSubworkflow",
"onSetData",
"onOutputLabel",
]);
const stepRef = toRef(props, "step");
const { stepId, contentId, annotation, label, name, type, configForm } = useStepProps(stepRef);
const { stepStore } = useWorkflowStores();
Expand Down Expand Up @@ -117,4 +125,7 @@ function onChange(values: any) {
inputs: values,
});
}
function onOutputLabel(oldValue: string | null, newValue: string | null) {
emit("onOutputLabel", oldValue, newValue);
}
</script>
5 changes: 4 additions & 1 deletion client/src/components/Workflow/Editor/Forms/FormOutput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<FormCard :title="outputTitle" collapsible :expanded.sync="expanded">
<template v-slot:body>
<FormOutputLabel :name="outputName" :step="step" />
<FormOutputLabel :name="outputName" :step="step" @onOutputLabel="onOutputLabel" />
<FormElement
:id="actionNames.RenameDatasetAction__newname"
:value="formData[actionNames.RenameDatasetAction__newname]"
Expand Down Expand Up @@ -204,6 +204,9 @@ export default {
onInput(value, pjaKey) {
this.$emit("onInput", value, pjaKey);
},
onOutputLabel(oldValue, newValue) {
this.$emit("onOutputLabel", oldValue, newValue);
},
onDatatype(newDatatype) {
this.$emit("onDatatype", this.actionNames.ChangeDatatypeAction__newtype, this.outputName, newDatatype);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const props = withDefaults(
}
);
const emit = defineEmits<{
(e: "onOutputLabel", oldValue: string | null, newValue: string | null): void;
}>();
const { stepStore } = useWorkflowStores();
const error: Ref<string | undefined> = ref(undefined);
Expand All @@ -54,12 +58,14 @@ function onInput(newLabel: string | undefined | null) {
}
if (newLabel === "") {
const oldLabel = label.value || null;
// user deleted existing label, we inactivate this as output
const strippedWorkflowOutputs = (props.step.workflow_outputs || []).filter(
(workflowOutput) => workflowOutput.output_name !== props.name
);
stepStore.updateStep({ ...props.step, workflow_outputs: strippedWorkflowOutputs });
error.value = undefined;
emit("onOutputLabel", oldLabel, null);
return;
}
Expand All @@ -74,6 +80,8 @@ function onInput(newLabel: string | undefined | null) {
output_name: props.name,
});
stepStore.updateStep({ ...props.step, workflow_outputs: newWorkflowOutputs });
const oldLabel = label.value || null;
emit("onOutputLabel", oldLabel, newLabel || null);
error.value = undefined;
} else if (existingWorkflowOutput.stepId !== props.step.id) {
error.value = `Duplicate output label '${newLabel}' will be ignored.`;
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/Workflow/Editor/Forms/FormSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:datatypes="datatypes"
:form-data="formData"
@onInput="onInput"
@onOutputLabel="onOutputLabel"
@onDatatype="onDatatype" />
</div>
</template>
Expand Down Expand Up @@ -148,6 +149,9 @@ export default {
delete pjas[this.emailPayloadKey];
}
},
onOutputLabel(oldValue, newValue) {
this.$emit("onOutputLabel", oldValue, newValue);
},
onInput(value, pjaKey) {
let changed = false;
const exists = pjaKey in this.formData;
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/Workflow/Editor/Forms/FormTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
:step="step"
:datatypes="datatypes"
:post-job-actions="postJobActions"
@onOutputLabel="onOutputLabel"
@onChange="onChangePostJobActions" />
</div>
</template>
Expand Down Expand Up @@ -88,7 +89,7 @@ export default {
required: true,
},
},
emits: ["onSetData", "onUpdateStep", "onChangePostJobActions", "onAnnotation", "onLabel"],
emits: ["onSetData", "onUpdateStep", "onChangePostJobActions", "onAnnotation", "onLabel", "onOutputLabel"],
setup(props, { emit }) {
const { stepId, annotation, label, stepInputs, stepOutputs, configForm, postJobActions } = useStepProps(
toRef(props, "step")
Expand Down Expand Up @@ -163,6 +164,9 @@ export default {
onLabel(newLabel) {
this.$emit("onLabel", this.stepId, newLabel);
},
onOutputLabel(oldValue, newValue) {
this.$emit("onOutputLabel", oldValue, newValue);
},
/**
* Change event is triggered on component creation and input changes.
* @param { Object } values contains flat key-value pairs `prefixed-name=value`
Expand Down
12 changes: 11 additions & 1 deletion client/src/components/Workflow/Editor/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
@onChangePostJobActions="onChangePostJobActions"
@onAnnotation="onAnnotation"
@onLabel="onLabel"
@onOutputLabel="onOutputLabel"
@onUpdateStep="onUpdateStep"
@onSetData="onSetData" />
<FormDefault
Expand All @@ -105,6 +106,7 @@
@onLabel="onLabel"
@onEditSubworkflow="onEditSubworkflow"
@onAttemptRefactor="onAttemptRefactor"
@onOutputLabel="onOutputLabel"
@onUpdateStep="onUpdateStep"
@onSetData="onSetData" />
<WorkflowAttributes
Expand Down Expand Up @@ -642,16 +644,24 @@ export default {
this.onUpdateStep(step);
});
},
onOutputLabel(oldValue, newValue) {
const newMarkdown = replaceLabel(this.markdownText, "output", oldValue, newValue);
if (newMarkdown !== this.markdownText) {
this.debouncedToast("Output label updated in workflow report.", 1500);
}
this.onReportUpdate(newMarkdown);
},
onLabel(nodeId, newLabel) {
const step = { ...this.steps[nodeId], label: newLabel };
const oldLabel = this.steps[nodeId].label;
this.onUpdateStep(step);
const stepType = this.steps[nodeId].type;
const isInput = ["data_input", "data_collection_input", "parameter_input"].indexOf(stepType) >= 0;
const labelType = isInput ? "input" : "step";
const labelTypeTitle = isInput ? "Input" : "Step";
const newMarkdown = replaceLabel(this.markdownText, labelType, oldLabel, newLabel);
if (newMarkdown !== this.markdownText) {
this.debouncedToast("Label updated in workflow report.", 1500);
this.debouncedToast(`${labelTypeTitle} label updated in workflow report.`, 1500);
}
this.onReportUpdate(newMarkdown);
},
Expand Down

0 comments on commit df340f5

Please sign in to comment.