Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/collections/board: add "Customize card templates" to the board context menu
Adorian Dorane64e04f0a0a7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 7ec125e368..9b6e8e3889 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3422,6 +3422,7 @@"expand-all-columns": "Expand all columns","show-inbox-column": "Show inbox column","show-archived-notes": "Show archived notes",+ "customize-templates": "Customize card templates","more-templates": "More templates…","card-template": "Select a card template","templates-title": "Templates offered on this board",diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.tsindex 69ff99a12b..627fb88235 100644--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts@@ -9,8 +9,8 @@ import dialog from "../../../services/dialog";import FNote from "../../../entities/fnote";import { buildNote } from "../../../test/easy-froca";import BoardApi from "./api";-import { DEFAULT_COLUMN_ICON } from "./columns";-import { openColumnContextMenu, openNoteContextMenu } from "./context_menu";+import { DEFAULT_COLUMN_ICON, INBOX_COLUMN_ICON } from "./columns";+import { openBoardContextMenu, openColumnContextMenu, openNoteContextMenu } from "./context_menu";// The card menu opens with the shared link items, which reach for the active note context.vi.mock("../../../menus/link_context_menu", () => ({@@ -711,3 +711,47 @@ describe("Board item context menu", () => {.toEqual([ false, true ]);});});++describe("Board context menu", () => {+ afterEach(() => vi.restoreAllMocks());++ /**+ * What the board itself offers, for a press on the ground the columns stand on. The last entry+ * opens the dialog naming what a card can be made from, which the pill inside the field a card+ * is named in opens as well.+ */+ it("offers what the board holds, and a way to what its cards are made from", () => {+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});+ const board = {+ inboxShown: true,+ archivedShown: false,+ onAddColumn: vi.fn(),+ onCollapseAll: vi.fn(),+ onExpandAll: vi.fn(),+ onShowInbox: vi.fn(),+ onShowArchived: vi.fn(),+ onCustomizeTemplates: vi.fn()+ };++ openBoardContextMenu({+ preventDefault: () => {},+ stopPropagation: () => {},+ pageX: 0,+ pageY: 0+ } as ContextMenuEvent, board);++ const items = show.mock.calls.at(-1)?.[0].items ?? [];+ // A separator stands between what the board shows and what its cards are made from.+ expect(items.map(item => item && "uiIcon" in item ? item.uiIcon : "---")).toEqual([+ "bx bx-columns", "---",+ "bx bx-collapse-alt", "bx bx-expand-alt", "---",+ INBOX_COLUMN_ICON, "bx bx-archive", "---",+ "bx bx-list-ul"+ ]);++ const entry = items.at(-1);+ if (!entry || !("handler" in entry)) throw new Error("expected an entry for the templates");+ entry.handler?.(entry, {} as never);+ expect(board.onCustomizeTemplates).toHaveBeenCalled();+ });+});diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex a22fbec23e..a1a262fb00 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -180,6 +180,8 @@ interface BoardMenuTarget {onExpandAll: () => void;onShowInbox: (shown: boolean) => void;onShowArchived: (shown: boolean) => void;+ /** Opens the dialog naming what a new card can be made from. */+ onCustomizeTemplates: () => void;}/** What the board itself offers, for a press on the ground the columns stand on. */@@ -219,6 +221,12 @@ export function openBoardContextMenu(event: ContextMenuEvent, board: BoardMenuTauiIcon: "bx bx-archive",trailingIcon: board.archivedShown ? "bx bx-check" : undefined,handler: () => board.onShowArchived(!board.archivedShown)+ },+ { kind: "separator" },+ {+ title: t("board_view.customize-templates"),+ uiIcon: "bx bx-list-ul",+ handler: board.onCustomizeTemplates}],selectMenuItemHandler() {}diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 2d4fab7851..28e6244ac2 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -510,7 +510,7 @@ describe("Collapsed board columns", () => {: []);expect(entries.map(entry => entry.icon)).toEqual(["bx bx-columns", "bx bx-collapse-alt", "bx bx-expand-alt",- INBOX_COLUMN_ICON, "bx bx-archive"+ INBOX_COLUMN_ICON, "bx bx-archive", "bx bx-list-ul"]);const entry = (icon: string) => entries.find(item => item.icon === icon)?.handler;diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 1cd0470254..5f3d75fd7a 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -372,9 +372,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveConAddColumn: () => setIsCreatingColumn(true),onShowInbox: (shown) => api.setInboxEnabled(shown),onShowArchived: (shown) => api.setArchivedShown(shown),+ onCustomizeTemplates: () => setIsPickingTemplates(true),onCollapseAll: () => {- // The open column is closed with the rest: it holds the peek that would otherwise- // keep it open against what is being written for it.// The open column is closed with the rest: it holds the peek that would otherwise// keep it open against what is being written for it.selectColumn(undefined);