Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): hide the note menu items quick edit cannot use

Elian Doran0d38fef4c190
diff --git a/apps/client/src/widgets/layout/NoteActions.spec.tsx b/apps/client/src/widgets/layout/NoteActions.spec.tsx
index d70b79a774..efd45bf057 100644
--- a/apps/client/src/widgets/layout/NoteActions.spec.tsx
+++ b/apps/client/src/widgets/layout/NoteActions.spec.tsx
@@ -2,10 +2,13 @@ import { render } from "preact";
import { afterEach, describe, expect, it, vi } from "vitest";
import Component from "../../components/component";
+import FNote from "../../entities/fnote";
+import froca from "../../services/froca";
import NoteContext from "../../components/note_context";
import Dropdown from "../react/Dropdown";
import { NoteContextContext, ParentComponent } from "../react/react_utils";
-import { CommandItem } from "./NoteActions";
+import { buildNote } from "../../test/easy-froca";
+import { CommandItem, NoteContextMenu } from "./NoteActions";
// A dialog's focus trap would pull focus out of a menu portaled over it.
vi.mock("../react/modal_focustrap", () => ({ suspendModalFocusTraps: () => () => {} }));
@@ -66,3 +69,53 @@ describe("CommandItem", () => {
expect(triggerCommand).toHaveBeenCalledExactlyOnceWith("printActiveNote", { ntxId: "_popup-editor" });
});
});
+
+describe("NoteContextMenu", () => {
+ const host = document.createElement("div");
+ document.body.append(host);
+
+ afterEach(() => {
+ render(null, host);
+ });
+
+ it("leaves out of the quick edit popup the actions that act outside it", async () => {
+ const text = buildNote({ title: "Text", type: "text", content: "<p>Hi</p>" });
+ // Only an image with a single parent can be converted into an attachment.
+ const parent = buildNote({ title: "Parent", children: [ { title: "Diagram", type: "image", content: "img" } ] });
+ const image = froca.getNoteFromCache(parent.children[0]);
+ expect(image?.type).toBe("image");
+
+ const shownIn = async (ntxId: string, note: FNote) => {
+ const noteContext = new NoteContext(ntxId);
+ noteContext.noteId = note.noteId;
+ noteContext.viewScope = { viewMode: "default" };
+ render((
+ <ParentComponent.Provider value={new Component()}>
+ <NoteContextContext.Provider value={noteContext}>
+ <NoteContextMenu note={note} noteContext={noteContext} />
+ </NoteContextContext.Provider>
+ </ParentComponent.Provider>
+ ), host);
+ host.querySelector<HTMLButtonElement>("button")?.click();
+ await vi.waitFor(() => expect(document.querySelector(".tn-popup li.dropdown-item")).toBeTruthy());
+ const items = [ ...document.querySelectorAll<HTMLElement>(".tn-popup li.dropdown-item") ];
+ const hasIcon = (icon: string) => items.some((li) => li.querySelector(`.${icon}`));
+ const state = {
+ search: hasIcon("bx-search"),
+ noteMap: hasIcon("bxs-network-chart"),
+ fullWidth: hasIcon("bx-expand-horizontal"),
+ // The attachments item carries the same icon, above the convert item.
+ paperclips: items.filter((li) => li.querySelector(".bx-paperclip")).length
+ };
+ render(null, host);
+ return state;
+ };
+
+ expect(await shownIn("ntx-tab", text)).toEqual({ search: true, noteMap: true, fullWidth: true, paperclips: 1 });
+ expect(await shownIn("_popup-editor", text)).toEqual({ search: false, noteMap: false, fullWidth: false, paperclips: 1 });
+ if (image) {
+ expect((await shownIn("ntx-tab", image)).paperclips).toBe(2);
+ expect((await shownIn("_popup-editor", image)).paperclips).toBe(1);
+ }
+ });
+});
diff --git a/apps/client/src/widgets/layout/NoteActions.tsx b/apps/client/src/widgets/layout/NoteActions.tsx
index 5aad4becf0..7b9c7f7e52 100644
--- a/apps/client/src/widgets/layout/NoteActions.tsx
+++ b/apps/client/src/widgets/layout/NoteActions.tsx
@@ -24,7 +24,7 @@ import { isAlwaysFullWidthByType } from "../note_wrapper";
import Dropdown, { type DropdownHandle } from "../react/Dropdown";
import { FormDropdownDivider, FormDropdownSubmenu, FormListHeader, FormListItem, FormListToggleableItem } from "../react/FormList";
import { useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteLabelOptionalBool, useNoteProperty, useSyncedRef, useTriliumEvent, useTriliumOption } from "../react/hooks";
-import { ParentComponent, useCommandTrigger } from "../react/react_utils";
+import { ParentComponent, POPUP_EDITOR_NTX_ID, useCommandTrigger } from "../react/react_utils";
import NoteActionsCustom from "./NoteActionsCustom";
import { useShareState } from "./NoteBadges";
import { NoteTypeDropdownContent } from "./NoteTypeSwitcher";
@@ -86,6 +86,8 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
const [syncServerHost] = useTriliumOption("syncServerHost");
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
const isNormalViewMode = noteContext?.viewScope?.viewMode === "default";
+ // The quick edit popup has no find bar, and the note map and a converted attachment open in the tab behind it.
+ const isInPopup = !!noteContext?.ntxId?.startsWith(POPUP_EDITOR_NTX_ID);
const itemToFocusRef = useRef<ItemToFocus>(null);
// Keyboard shortcuts.
useTriliumEvent("toggleRibbonTabBasicProperties", () => {
@@ -115,9 +117,9 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
<FormDropdownDivider />
</>}
- <CommandItem command="findInText" icon="bx bx-search" disabled={!isSearchable} text={t("note_actions.search_in_note")} />
+ {!isInPopup && <CommandItem command="findInText" icon="bx bx-search" disabled={!isSearchable} text={t("note_actions.search_in_note")} />}
<CommandItem command="showAttachments" icon="bx bx-paperclip" disabled={isInOptionsOrHelp} text={t("note_actions.note_attachments")} />
- <CommandItem command="toggleRibbonTabNoteMap" icon="bx bxs-network-chart" disabled={isInOptionsOrHelp} text={t("note_actions.note_map")} />
+ {!isInPopup && <CommandItem command="toggleRibbonTabNoteMap" icon="bx bxs-network-chart" disabled={isInOptionsOrHelp} text={t("note_actions.note_map")} />}
{/* The attributes panel is a right pane tab where there is a right pane; on a phone the
menu is where it is reached, and a modal is where it is shown. */}
{isMobile && <CommandItem command="showNoteAttributes" icon="bx bx-list-check" disabled={isInOptionsOrHelp} text={t("note_actions.note_attributes")} />}
@@ -125,7 +127,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
<FormDropdownDivider />
{isNormalViewMode && !isHelpPage && <>
- <NoteBasicProperties note={note} focus={itemToFocusRef} />
+ <NoteBasicProperties note={note} focus={itemToFocusRef} isInPopup={isInPopup} />
<FormDropdownDivider />
</>}
@@ -165,7 +167,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
<FormDropdownDivider />
- {canBeConvertedToAttachment && <ConvertToAttachment note={note} />}
+ {canBeConvertedToAttachment && !isInPopup && <ConvertToAttachment note={note} />}
{note.type === "render" && <CommandItem command="renderActiveNote" icon="bx bx-extension" text={t("note_actions.re_render_note")}
/>}
@@ -223,9 +225,11 @@ function CodeProperties({ note }: { note: FNote }) {
);
}
-function NoteBasicProperties({ note, focus }: {
+function NoteBasicProperties({ note, focus, isInPopup }: {
note: FNote;
focus: RefObject<ItemToFocus | null>;
+ /** Whether the menu is in the quick edit popup, whose width the full content width label does not change. */
+ isInPopup: boolean;
}) {
const itemToFocusRef = useRef<HTMLLIElement>(null);
const [ isBookmarked, setIsBookmarked ] = useNoteBookmarkState(note);
@@ -273,7 +277,7 @@ function NoteBasicProperties({ note, focus }: {
helpPage="KC1HB96bqqHX"
disabled={note?.noteId.startsWith("_options")}
/>
- {!isAlwaysFullWidthByType(note) &&
+ {!isAlwaysFullWidthByType(note) && !isInPopup &&
<FormListToggleableItem
icon="bx bx-expand-horizontal"
title={t("full_content_width_switch.title")}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.html
index 6c47f35e6c..82f6e13089 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.html
@@ -27,6 +27,7 @@
<li>The note's actions and its menu are shown in the header of the popup,
as in the title row of a tab.
<ul>
+ <li>The menu items that only work in a tab are not shown: <em>Search in note</em>, <em>Note map</em>, <em>Full width</em> and <em>Convert into attachment</em>.</li>
<li>A help page opened from the popup, such as through the help button of
the note type, opens in a second popup on top of it. Closing that popup
returns to the note being edited.</li>
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.md
index 307997abb6..c6a771ef17 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Quick edit.md
@@ -14,6 +14,7 @@ This feature is also well integrated with <a class="reference-link" href="../..
* For <a class="reference-link" href="../../Note%20Types/Text.md">Text</a> notes, depending on user preference, both the floating and classic editors are supported. See <a class="reference-link" href="../../Note%20Types/Text/Formatting%20toolbar.md">Formatting toolbar</a>.
* The title and the note and the icon are editable, just like a normal tab.
* The note's actions and its menu are shown in the header of the popup, as in the title row of a tab.
+ * The menu items that only work in a tab are not shown: _Search in note_, _Note map_, _Full width_ and _Convert into attachment_.
* A help page opened from the popup, such as through the help button of the note type, opens in a second popup on top of it. Closing that popup returns to the note being edited.
* The <a class="reference-link" href="../../Advanced%20Usage/Attributes/Promoted%20Attributes.md">Promoted Attributes</a> are also displayed.
* This integrates well with <a class="reference-link" href="../../Collections.md">Collections</a> where there are predefined attributes such as the _Start date_ and _End date_, allowing for easy editing.