Skip to content

Commit

Permalink
Merge pull request #18557 from ElectronicBlueberry/fix-remove-freehan…
Browse files Browse the repository at this point in the history
…d-comments-undo

[24.1] Fix undo removing all freehand comments
  • Loading branch information
mvdbeek authored Jul 17, 2024
2 parents 76f0690 + 2984eaf commit e4a5eef
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
18 changes: 17 additions & 1 deletion client/src/components/Workflow/Editor/Actions/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
LazyChangeDataAction,
LazyChangePositionAction,
LazyChangeSizeAction,
RemoveAllFreehandCommentsAction,
ToggleCommentSelectedAction,
} from "./commentActions";
import { mockComment, mockToolStep, mockWorkflow } from "./mockData";
import { mockComment, mockFreehandComment, mockToolStep, mockWorkflow } from "./mockData";
import {
CopyStepAction,
InsertStepAction,
Expand Down Expand Up @@ -90,6 +91,12 @@ describe("Workflow Undo Redo Actions", () => {
return comment;
}

function addFreehandComment() {
const comment = mockFreehandComment(commentStore.highestCommentId + 1);
commentStore.addComments([comment]);
return comment;
}

function addStep() {
const step = mockToolStep(stepStore.getStepIndex + 1);
stepStore.addStep(step);
Expand Down Expand Up @@ -141,6 +148,15 @@ describe("Workflow Undo Redo Actions", () => {
const action = new ToggleCommentSelectedAction(commentStore, comment);
testUndoRedo(action);
});

it("RemoveAllFreehandCommentsAction", () => {
addFreehandComment();
addFreehandComment();
addFreehandComment();

const action = new RemoveAllFreehandCommentsAction(commentStore);
testUndoRedo(action);
});
});

describe("Workflow Actions", () => {
Expand Down
25 changes: 25 additions & 0 deletions client/src/components/Workflow/Editor/Actions/commentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,28 @@ export class ToggleCommentSelectedAction extends UndoRedoAction {
this.store.setCommentMultiSelected(this.commentId, !this.toggleTo);
}
}

export class RemoveAllFreehandCommentsAction extends UndoRedoAction {
store;
comments;

constructor(store: WorkflowCommentStore) {
super();

this.store = store;
const freehandComments = store.comments.filter((comment) => comment.type === "freehand");
this.comments = structuredClone(freehandComments);
}

get name() {
return "remove all freehand comments";
}

run() {
this.store.deleteFreehandComments();
}

undo() {
this.store.addComments(structuredClone(this.comments));
}
}
20 changes: 19 additions & 1 deletion client/src/components/Workflow/Editor/Actions/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WorkflowComment } from "@/stores/workflowEditorCommentStore";
import { FreehandWorkflowComment, WorkflowComment } from "@/stores/workflowEditorCommentStore";
import type { Step } from "@/stores/workflowStepStore";

import type { Workflow } from "../modules/model";
Expand Down Expand Up @@ -227,3 +227,21 @@ export function mockComment(id: number): WorkflowComment {
data: { size: 2, text: "Enter Text" },
};
}

export function mockFreehandComment(id: number): FreehandWorkflowComment {
return {
id,
position: [0, 0],
size: [100, 200],
type: "freehand",
color: "none",
data: {
thickness: 1,
line: [
[0, 0],
[10, 20],
[100, 200],
],
},
};
}
5 changes: 3 additions & 2 deletions client/src/components/Workflow/Editor/Tools/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { BoxSelect } from "lucide-vue";
import { storeToRefs } from "pinia";
import { computed, toRefs, watch } from "vue";
import { RemoveAllFreehandCommentsAction } from "@/components/Workflow/Editor/Actions/commentActions";
import { useUid } from "@/composables/utils/uid";
import { useWorkflowStores } from "@/composables/workflowStores";
import { type CommentTool } from "@/stores/workflowEditorToolbarStore";
Expand All @@ -45,7 +46,7 @@ library.add(
faTrash
);
const { toolbarStore, commentStore } = useWorkflowStores();
const { toolbarStore, undoRedoStore, commentStore } = useWorkflowStores();
const { snapActive, currentTool } = toRefs(toolbarStore);
const { commentOptions } = toolbarStore;
Expand Down Expand Up @@ -122,7 +123,7 @@ const thicknessId = useUid("thickness-");
const smoothingId = useUid("smoothing-");
function onRemoveAllFreehand() {
commentStore.deleteFreehandComments();
undoRedoStore.applyAction(new RemoveAllFreehandCommentsAction(commentStore));
}
useToolLogic();
Expand Down

0 comments on commit e4a5eef

Please sign in to comment.