From edb81e257412bffada3335e6b98e8b8d23b3c080 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:09:27 +0200 Subject: [PATCH 1/2] detect markdown changes before notifying --- .../Workflow/Editor/Actions/stepActions.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/client/src/components/Workflow/Editor/Actions/stepActions.ts b/client/src/components/Workflow/Editor/Actions/stepActions.ts index d8035b0ea171..42877b2651d4 100644 --- a/client/src/components/Workflow/Editor/Actions/stepActions.ts +++ b/client/src/components/Workflow/Editor/Actions/stepActions.ts @@ -87,8 +87,11 @@ export class LazySetLabelAction extends LazyMutateStepAction<"label"> { 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 ?? ""); + + if (markdown !== newMarkdown) { + this.stateStore.report.markdown = newMarkdown; + this.toast(this.fromValue ?? "", this.toValue ?? ""); + } } undo() { @@ -96,8 +99,11 @@ export class LazySetLabelAction extends LazyMutateStepAction<"label"> { 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 ?? ""); + + if (markdown !== newMarkdown) { + this.stateStore.report.markdown = newMarkdown; + this.toast(this.toValue ?? "", this.fromValue ?? ""); + } } redo() { @@ -139,8 +145,11 @@ export class LazySetOutputLabelAction extends LazyMutateStepAction<"workflow_out 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 ?? ""); + + if (newMarkdown !== markdown) { + this.stateStore.report.markdown = newMarkdown; + this.toast(this.fromLabel ?? "", this.toLabel ?? ""); + } } undo() { @@ -148,9 +157,11 @@ export class LazySetOutputLabelAction extends LazyMutateStepAction<"workflow_out 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 ?? ""); + if (newMarkdown !== markdown) { + this.stateStore.report.markdown = newMarkdown; + this.toast(this.toLabel ?? "", this.fromLabel ?? ""); + } } redo() { From 43bbe77eb7bbc5a001e98b3f46a7d91c041c0b71 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:46:44 +0200 Subject: [PATCH 2/2] refactor out repeated functionality --- .../Workflow/Editor/Actions/stepActions.ts | 60 +++++++------------ 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/client/src/components/Workflow/Editor/Actions/stepActions.ts b/client/src/components/Workflow/Editor/Actions/stepActions.ts index 42877b2651d4..9e29437040ab 100644 --- a/client/src/components/Workflow/Editor/Actions/stepActions.ts +++ b/client/src/components/Workflow/Editor/Actions/stepActions.ts @@ -54,6 +54,22 @@ export class LazyMutateStepAction 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"; @@ -80,30 +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); - - if (markdown !== newMarkdown) { - 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); - - if (markdown !== newMarkdown) { - this.stateStore.report.markdown = newMarkdown; - this.toast(this.toValue ?? "", this.fromValue ?? ""); - } + onLabelSet(this, this.toValue, this.fromValue); } redo() { @@ -117,6 +116,8 @@ export class LazySetOutputLabelAction extends LazyMutateStepAction<"workflow_out fromLabel; toLabel; stateStore; + labelType = "output" as const; + labelTypeTitle = "Output" as const; constructor( stepStore: WorkflowStepStore, @@ -138,30 +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); - - if (newMarkdown !== markdown) { - 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); - - if (newMarkdown !== markdown) { - this.stateStore.report.markdown = newMarkdown; - this.toast(this.toLabel ?? "", this.fromLabel ?? ""); - } + onLabelSet(this, this.toLabel, this.fromLabel); } redo() {