Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: add "Board properties" to the note menu

Adorian Dorandaa8e344b5b1
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts
index 1d3e2833ad..e0ce352d3f 100644
--- a/apps/client/src/components/app_context.ts
+++ b/apps/client/src/components/app_context.ts
@@ -569,6 +569,8 @@ type EventMappings = {
geoMapCreateChildNote: {
ntxId: string | null | undefined; // TODO: deduplicate ntxId
};
+ /** Opens the board's properties dialog, which only the board itself can show. */
+ showBoardProperties: { ntxId: string | null | undefined; };
tabReorder: {
ntxIdsInOrder: string[];
};
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index f6bd0a61d3..094fadc513 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -3974,3 +3974,84 @@ describe("Switchable board grouping", () => {
expect(columnIcons(mountPoint)).toEqual([ "bx bx-down-arrow", DEFAULT_COLUMN_ICON ]);
});
});
+
+describe("Board properties from the note menu", () => {
+ let container: HTMLElement | undefined;
+
+ afterEach(() => {
+ if (container) {
+ render(null, container);
+ container.remove();
+ container = undefined;
+ }
+
+ // A modal Bootstrap still believes is shown traps the focus of every later test, and its
+ // teardown waits on a transition happy-dom never runs.
+ const modal = document.querySelector<HTMLElement>(".board-properties-dialog");
+ if (modal) {
+ BootstrapModal.getInstance(modal)?.dispose();
+ modal.remove();
+ }
+ document.querySelector(".modal-backdrop")?.remove();
+ document.body.classList.remove("modal-open");
+ });
+
+ /**
+ * The menu is drawn outside the board, so it asks for the dialog by event. Each open board
+ * hears it, and only the one in the tab the menu was opened from answers.
+ */
+ it("opens the dialog for its own tab, and not for another one", async () => {
+ const host = await renderBoardInContext("ntx-1");
+ const isOpen = () => !!document.querySelector(".board-properties-dialog .modal-dialog");
+
+ expect(isOpen()).toBe(false);
+
+ await act(async () => {
+ await host.handleEvent("showBoardProperties", { ntxId: "ntx-2" });
+ await flush();
+ });
+ expect(isOpen()).toBe(false);
+
+ await act(async () => {
+ await host.handleEvent("showBoardProperties", { ntxId: "ntx-1" });
+ await flush();
+ });
+ expect(isOpen()).toBe(true);
+ });
+
+ /** Mounts a board belonging to the given tab, returning what events reach it through. */
+ async function renderBoardInContext(ntxId: string) {
+ const note = buildNote({
+ title: "Board",
+ "#collection": "",
+ "#viewType": "board",
+ children: [
+ { title: "First", "#status": "To Do" },
+ { title: "Second", "#status": "Done" }
+ ]
+ });
+
+ const host = new Component();
+ Object.assign(host, { noteContext: { ntxId, isActive: () => true } });
+
+ const mountPoint = document.createElement("div");
+ container = mountPoint;
+ document.body.appendChild(mountPoint);
+
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={host}>
+ <Harness
+ note={note}
+ noteIds={[ ...note.getChildNoteIds() ]}
+ initialConfig={{ columns: [ { value: "To Do" }, { value: "Done" } ] }}
+ />
+ </ParentComponent.Provider>,
+ mountPoint
+ );
+ });
+ await act(async () => { await flush(); });
+
+ return host;
+ }
+});
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index dff41f4e17..e742f2dceb 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -1111,6 +1111,13 @@ export default function BoardView({
handleBoardKeys(e);
}, [ selection, handleBoardKeys ]);
+ // The note actions menu offers the properties dialog, which lives here rather than in the menu.
+ useTriliumEvent("showBoardProperties", ({ ntxId }) => {
+ if (ntxId === noteContext?.ntxId) {
+ setIsEditingProperties(true);
+ }
+ });
+
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
// The column list is read off the definition, which may be edited from the attribute panel,
// another split, or a synced instance. Re-reading it re-runs the refresh through the effect.
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index 093b6ce74d..47b6dd1533 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -98,6 +98,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
const isMobile = getIsMobile();
const hasSource = ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "spreadsheet", "llmChat"].includes(noteType) || note.isSvg();
const isSearchOrBook = ["search", "book"].includes(noteType);
+ const isBoard = noteType === "book" && viewType === "board";
const isHelpPage = note.noteId.startsWith("_help");
const [syncServerHost] = useTriliumOption("syncServerHost");
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
@@ -188,6 +189,9 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
{note.type === "render" && <CommandItem command="renderActiveNote" icon="bx bx-extension" text={t("note_actions.re_render_note")}
/>}
+ {isBoard && <CommandItem icon="bx bx-cog" text={t("board_view.properties")}
+ command={() => parentComponent?.triggerEvent("showBoardProperties", { ntxId: noteContext?.ntxId })} />}
+
<FormDropdownSubmenu icon="bx bx-wrench" title={t("note_actions.advanced")} dropStart>
<CommandItem command="openNoteExternally" icon="bx bx-file-find" disabled={isSearchOrBook || !isElectron} text={t("note_actions.open_note_externally")} title={t("note_actions.open_note_externally_title")} />
<CommandItem command="openNoteCustom" icon="bx bx-customize" disabled={isSearchOrBook || isMac || !isElectron} text={t("note_actions.open_note_custom")} />