Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix(web): limit comment menus to relevant actions

bluedbird7e3d3c63156c
diff --git a/web/src/components/MemoActionMenu/MemoActionMenu.tsx b/web/src/components/MemoActionMenu/MemoActionMenu.tsx
index d770d2dea..252855b87 100644
--- a/web/src/components/MemoActionMenu/MemoActionMenu.tsx
+++ b/web/src/components/MemoActionMenu/MemoActionMenu.tsx
@@ -22,6 +22,7 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
@@ -135,7 +136,17 @@ const MemoActionMenu = (props: MemoActionMenuProps) => {
</DropdownMenuItem>
)}
- {(canMove || !readonly) && (
+ {isComment && !readonly && (
+ <>
+ {!isArchived && <DropdownMenuSeparator />}
+ <DropdownMenuItem onClick={handleDeleteMemoClick}>
+ <TrashIcon />
+ {t("common.delete")}
+ </DropdownMenuItem>
+ </>
+ )}
+
+ {!isComment && (canMove || !readonly) && (
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<MoreHorizontalIcon />
diff --git a/web/tests/memo-action-menu.test.tsx b/web/tests/memo-action-menu.test.tsx
index bd4fbd753..7b63e16d5 100644
--- a/web/tests/memo-action-menu.test.tsx
+++ b/web/tests/memo-action-menu.test.tsx
@@ -64,6 +64,54 @@ describe("MemoActionMenu", () => {
expect(screen.queryByRole("menuitem", { name: "common.more" })).not.toBeInTheDocument();
});
+ it("shows comment actions with Delete last and no memo organization actions", async () => {
+ render(<MemoActionMenu memo={create(MemoSchema, { name: "memos/2", parent: "memos/1", state: State.NORMAL })} />);
+ fireEvent.click(screen.getByRole("button", { name: "common.more" }));
+ await screen.findByRole("menuitem", { name: "common.edit" });
+
+ expect(screen.getAllByRole("menuitem").map((item) => item.textContent)).toEqual(["common.edit", "common.copy", "common.delete"]);
+ expect(screen.getByRole("separator").nextElementSibling).toBe(screen.getByRole("menuitem", { name: "common.delete" }));
+
+ fireEvent.click(screen.getByRole("menuitem", { name: "common.delete" }));
+ expect(handlers.handleDeleteMemoClick).toHaveBeenCalledOnce();
+ expect(handlers.confirmDeleteMemo).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ ["memo.copy-link", "handleCopyLink"],
+ ["memo.copy-content", "handleCopyContent"],
+ ] as const)("allows %s on a read-only comment", async (label, handler) => {
+ render(<MemoActionMenu memo={create(MemoSchema, { name: "memos/2", parent: "memos/1", state: State.NORMAL })} readonly />);
+ fireEvent.click(screen.getByRole("button", { name: "common.more" }));
+ await screen.findByRole("menuitem", { name: "common.copy" });
+ expect(screen.getAllByRole("menuitem").map((item) => item.textContent)).toEqual(["common.copy"]);
+
+ fireEvent.click(screen.getByRole("menuitem", { name: "common.copy" }));
+ fireEvent.click(await screen.findByRole("menuitem", { name: label }));
+ expect(handlers[handler]).toHaveBeenCalledOnce();
+ });
+
+ it.each([false, true])("only shows task actions on writable task comments (readonly: %s)", async (readonly) => {
+ const memo = create(MemoSchema, {
+ name: "memos/2",
+ parent: "memos/1",
+ state: State.NORMAL,
+ property: { hasTaskList: true, hasIncompleteTasks: true },
+ });
+ render(<MemoActionMenu memo={memo} readonly={readonly} />);
+ fireEvent.click(screen.getByRole("button", { name: "common.more" }));
+ await screen.findByRole("menuitem", { name: "common.copy" });
+
+ if (readonly) {
+ expect(screen.queryByRole("menuitem", { name: "memo.task-actions.title" })).not.toBeInTheDocument();
+ } else {
+ fireEvent.click(screen.getByRole("menuitem", { name: "memo.task-actions.title" }));
+ expect(await screen.findByRole("menuitem", { name: "memo.task-actions.uncheck-all" })).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("menuitem", { name: "memo.task-actions.check-all" }));
+ expect(handlers.handleCheckAllTaskListItemsClick).toHaveBeenCalledOnce();
+ }
+ });
+
it("is a quiet compact control that takes the accent fill while open", async () => {
const memo = create(MemoSchema, { name: "memos/1", state: State.NORMAL, pinned: false });
render(<MemoActionMenu memo={memo} />);