Skip to content

Commit

Permalink
Merge pull request #18473 from ElectronicBlueberry/fix-workflow-relab…
Browse files Browse the repository at this point in the history
…el-noop

[24.1] fix no-op workflow "relabel" shouldn't result in a notification
  • Loading branch information
mvdbeek authored Jul 3, 2024
2 parents 922e2c8 + 43bbe77 commit 9c2b8ec
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions client/src/components/Workflow/Editor/Actions/stepActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ export class LazyMutateStepAction<K extends keyof Step> extends LazyUndoRedoActi
}
}

function onLabelSet(
classInstance: LazySetLabelAction | LazySetOutputLabelAction,
from: string | null | undefined,
to: string | null | undefined
) {
const markdown = classInstance.stateStore.report.markdown ?? "";
const newMarkdown = replaceLabel(markdown, classInstance.labelType, from, to);

if (markdown !== newMarkdown) {
classInstance.stateStore.report.markdown = newMarkdown;
classInstance.success(
`${classInstance.labelTypeTitle} label updated from "${from}" to "${to}" in workflow report.`
);
}
}

export class LazySetLabelAction extends LazyMutateStepAction<"label"> {
labelType: "input" | "step";
labelTypeTitle: "Input" | "Step";
Expand All @@ -80,24 +96,13 @@ export class LazySetLabelAction extends LazyMutateStepAction<"label"> {
this.success = useToast().success;
}

private toast(from: string, to: string) {
this.success(`${this.labelTypeTitle} label updated from "${from}" to "${to}" in workflow report.`);
}

run() {
const markdown = this.stateStore.report.markdown ?? "";
const newMarkdown = replaceLabel(markdown, this.labelType, this.fromValue as string, this.toValue as string);
this.stateStore.report.markdown = newMarkdown;
this.toast(this.fromValue ?? "", this.toValue ?? "");
onLabelSet(this, this.fromValue, this.toValue);
}

undo() {
super.undo();

const markdown = this.stateStore.report.markdown ?? "";
const newMarkdown = replaceLabel(markdown, this.labelType, this.toValue as string, this.fromValue as string);
this.stateStore.report.markdown = newMarkdown;
this.toast(this.toValue ?? "", this.fromValue ?? "");
onLabelSet(this, this.toValue, this.fromValue);
}

redo() {
Expand All @@ -111,6 +116,8 @@ export class LazySetOutputLabelAction extends LazyMutateStepAction<"workflow_out
fromLabel;
toLabel;
stateStore;
labelType = "output" as const;
labelTypeTitle = "Output" as const;

constructor(
stepStore: WorkflowStepStore,
Expand All @@ -132,25 +139,13 @@ export class LazySetOutputLabelAction extends LazyMutateStepAction<"workflow_out
this.success = useToast().success;
}

private toast(from: string, to: string) {
this.success(`Output label updated from "${from}" to "${to}" in workflow report.`);
}

run() {
const markdown = this.stateStore.report.markdown ?? "";
const newMarkdown = replaceLabel(markdown, "output", this.fromLabel, this.toLabel);
this.stateStore.report.markdown = newMarkdown;
this.toast(this.fromLabel ?? "", this.toLabel ?? "");
onLabelSet(this, this.fromLabel, this.toLabel);
}

undo() {
super.undo();

const markdown = this.stateStore.report.markdown ?? "";
const newMarkdown = replaceLabel(markdown, "output", this.toLabel, this.fromLabel);
this.stateStore.report.markdown = newMarkdown;

this.toast(this.toLabel ?? "", this.fromLabel ?? "");
onLabelSet(this, this.toLabel, this.fromLabel);
}

redo() {
Expand Down

0 comments on commit 9c2b8ec

Please sign in to comment.