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: improve the board properties dialog
Adorian Doranf915fe24cea2
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 522f197e18..0e4bce7c62 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3446,12 +3446,14 @@"collapse-all-columns": "Collapse all columns","expand-all-columns": "Expand all columns","show-inbox-column": "Show inbox column",- "show-archived-notes": "Show archived notes",+ "show-archived-notes": "Show archived cards/columns",+ "general": "General",+ "show-archived": "Show archived cards and columns","properties": "Board properties","properties-title": "Board properties","card-templates": "Card templates","card-templates-hint": "Choose what note types and note templates you would like to use when creating new board cards.",- "promoted-attributes": "Promoted attributes",+ "promoted-attributes": "Card attributes","promoted-attributes-hint": "Choose which attributes the cards show, and drag them into the order they appear in.","new-template-name": "New card template","more-templates": "More templates…",diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.tsindex fef52527af..d10bb5aed2 100644--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts@@ -9,7 +9,7 @@ import dialog from "../../../services/dialog";import FNote from "../../../entities/fnote";import { buildNote } from "../../../test/easy-froca";import BoardApi from "./api";-import { DEFAULT_COLUMN_ICON, INBOX_COLUMN_ICON } from "./columns";+import { DEFAULT_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.@@ -723,12 +723,10 @@ describe("Board context menu", () => {it("offers what the board holds, and a way to how it is set up", () => {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(),onOpenProperties: vi.fn()};@@ -741,11 +739,12 @@ describe("Board context menu", () => {} as ContextMenuEvent, board);const items = show.mock.calls.at(-1)?.[0].items ?? [];- // A separator stands between what the board shows and how it is set up.+ // A separator stands between what the board shows and how it is set up. The inbox column+ // is turned on in the properties dialog, which the last entry opens.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-archive", "---","bx bx-cog"]);diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex 6fb90fc9ec..9ea79778c6 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -12,7 +12,7 @@ import { t } from "../../../services/i18n";import { escapeHtml } from "../../../services/utils";import ColorPicker from "../../react/ColorPicker";import Api from "./api";-import { INBOX_COLUMN, INBOX_COLUMN_ICON } from "./columns";+import { INBOX_COLUMN } from "./columns";/** What the column menu is opened for: the column itself, and what it can be asked to do. */interface ColumnMenuTarget {@@ -170,15 +170,12 @@ const LISTED_COLUMNS = 7;/** What the board is, and what it can be asked to do, for a press on the ground its columns stand on. */interface BoardMenuTarget {- /** Whether the board keeps an inbox column. The entry shows it and toggles it. */- inboxShown: boolean;/** Whether the board renders notes labelled `archived`. */archivedShown: boolean;/** Opens the column name editor, the same one the button at the end opens. */onAddColumn: () => void;onCollapseAll: () => void;onExpandAll: () => void;- onShowInbox: (shown: boolean) => void;onShowArchived: (shown: boolean) => void;/** Opens `BoardProperties`, which configures the card templates. */onOpenProperties: () => void;@@ -210,12 +207,6 @@ export function openBoardContextMenu(event: ContextMenuEvent, board: BoardMenuTahandler: board.onExpandAll},{ kind: "separator" },- {- title: t("board_view.show-inbox-column"),- uiIcon: INBOX_COLUMN_ICON,- trailingIcon: board.inboxShown ? "bx bx-check" : undefined,- handler: () => board.onShowInbox(!board.inboxShown)- },{title: t("board_view.show-archived-notes"),uiIcon: "bx bx-archive",diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 5bea539a2e..0c6a14798a 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -26,7 +26,7 @@ import BoardView, { BoardViewData } from ".";import { getNoteTypeOptions, type NoteTypeOption } from "../../../services/note_types";import { collectShortcutHints } from "../../../services/shortcut_hints";import BoardApi, { getPendingWrites } from "./api";-import { DEFAULT_COLUMN_ICON, INBOX_COLUMN_ICON } from "./columns";+import { DEFAULT_COLUMN_ICON } from "./columns";// Stands in for the server: by the time the bulk action resolves, the notes carry the new value,// which is what makes the old column empty rather than merely renamed.@@ -513,7 +513,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", "bx bx-cog"+ "bx bx-archive", "bx bx-cog"]);const entry = (icon: string) => entries.find(item => item.icon === icon)?.handler;@@ -588,7 +588,6 @@ describe("Collapsed board columns", () => {it("opens the column editor and toggles what the board shows, from its menu", async () => {const { mountPoint } = await setup();const board = mountPoint.querySelector<HTMLElement>(".board-view-container");- const inbox = vi.spyOn(BoardApi.prototype, "setInboxEnabled").mockResolvedValue(undefined);const archived = vi.spyOn(BoardApi.prototype, "setArchivedShown").mockResolvedValue(undefined);const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});@@ -601,12 +600,11 @@ describe("Collapsed board columns", () => {return found;};- // Neither is on, so neither is ticked, and pressing them asks for them.- expect("trailingIcon" in entry(INBOX_COLUMN_ICON) && entry(INBOX_COLUMN_ICON).trailingIcon)+ // Archived notes are not shown, so the entry is not ticked, and pressing it asks for them.+ // The inbox column is turned on in the properties dialog rather than here.+ expect("trailingIcon" in entry("bx bx-archive") && entry("bx bx-archive").trailingIcon).toBeUndefined();- entry(INBOX_COLUMN_ICON).handler?.(entry(INBOX_COLUMN_ICON), {} as never);entry("bx bx-archive").handler?.(entry("bx bx-archive"), {} as never);- expect(inbox).toHaveBeenCalledWith(true);expect(archived).toHaveBeenCalledWith(true);// The same editor the slot at the end of the board opens.@@ -618,7 +616,6 @@ describe("Collapsed board columns", () => {expect(mountPoint.querySelector(".board-add-column input")).toBeTruthy();show.mockRestore();- inbox.mockRestore();archived.mockRestore();});diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 443c5e9110..56a68ada08 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -351,10 +351,8 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC}openBoardContextMenu(event, {- inboxShown: inboxEnabled,archivedShown: includeArchived,onAddColumn: () => setIsCreatingColumn(true),- onShowInbox: (shown) => api.setInboxEnabled(shown),onShowArchived: (shown) => api.setArchivedShown(shown),onOpenProperties: () => setIsEditingProperties(true),onCollapseAll: () => {diff --git a/apps/client/src/widgets/collections/board/properties.css b/apps/client/src/widgets/collections/board/properties.cssnew file mode 100644index 0000000000..b72a16d9a5--- /dev/null+++ b/apps/client/src/widgets/collections/board/properties.css@@ -0,0 +1,8 @@+/* The dialog stacks its cards, so the space between them is the dialog's rather than each card's. */+.modal.board-properties-dialog .modal-body {+ display: flex;+ flex-direction: column;+ gap: 24px;+ padding-inline: 25px;+ padding-block-end: 25px;+}diff --git a/apps/client/src/widgets/collections/board/properties.spec.tsx b/apps/client/src/widgets/collections/board/properties.spec.tsxindex 65f67507a5..e40af958db 100644--- a/apps/client/src/widgets/collections/board/properties.spec.tsx+++ b/apps/client/src/widgets/collections/board/properties.spec.tsx@@ -55,14 +55,29 @@ describe("Board properties", () => {let container: HTMLElement;let stored: string[][];let storedAttributes: PromotedAttribute[][];+ let toggled: [ string, boolean ][];+ /** What the board shows, which the General card reads from the note's own labels. */+ let shownOnBoard: Record<string, boolean>;beforeEach(() => {stored = [];storedAttributes = [];+ toggled = [];+ shownOnBoard = { enableInboxColumn: false, includeArchived: true };container = document.createElement("div");document.body.appendChild(container);+ const board = {+ noteId: "board1",+ isLabelTruthy: (name: string) => !!shownOnBoard[name],+ getLabelValue: (name: string) => shownOnBoard[name] ? "true" : "false",+ getLabel: () => undefined,+ hasLabel: (name: string) => name in shownOnBoard+ } as unknown as FNote;+const api = {+ setInboxEnabled: async (enabled: boolean) => { toggled.push([ "inbox", enabled ]); },+ setArchivedShown: async (shown: boolean) => { toggled.push([ "archived", shown ]); },getCardTemplateIds: () => [ "type:text:text/html" ],setCardTemplateIds: async (ids: string[]) => { stored.push(ids); },getStoredPromotedAttributes: () => [ { name: "dueDate" }, { name: "owner" } ],@@ -75,7 +90,7 @@ describe("Board properties", () => {render(<BoardPropertiesapi={api}- note={{ noteId: "board1" } as FNote}+ note={board}shownonClose={() => {}}/>,@@ -113,6 +128,32 @@ describe("Board properties", () => {expect(card?.dataset.templates).toBe("type:text:text/html");});+ describe("what the board shows", () => {+ /** Both were on the board's own menu; the inbox column is now offered only here. */+ it("draws a segment for each, reading what the board's labels say", () => {+ const rows = general()?.querySelectorAll(".tn-card-section") ?? [];++ expect(rows.length).toBe(2);+ expect(toggleAt(0)?.classList.contains("on")).toBe(false);+ expect(toggleAt(1)?.classList.contains("on")).toBe(true);+ });++ it("asks the board to show each of them", () => {+ act(() => { toggleAt(0)?.click(); });+ act(() => { toggleAt(1)?.click(); });++ expect(toggled).toEqual([ [ "inbox", true ], [ "archived", false ] ]);+ });++ function general() {+ return dialog()?.querySelector<HTMLElement>(".board-properties-general");+ }++ function toggleAt(index: number) {+ return general()?.querySelectorAll<HTMLElement>(".switch-button")[index];+ }+ });+it("holds the promoted attributes, in the board's own words and from its own config", () => {const card = dialog()?.querySelector<HTMLElement>(".attributes-stub");diff --git a/apps/client/src/widgets/collections/board/properties.tsx b/apps/client/src/widgets/collections/board/properties.tsxindex 564fd69096..08d9b18502 100644--- a/apps/client/src/widgets/collections/board/properties.tsx+++ b/apps/client/src/widgets/collections/board/properties.tsx@@ -1,7 +1,12 @@+import "./properties.css";+import { useCallback } from "preact/hooks";import type FNote from "../../../entities/fnote";import { t } from "../../../services/i18n";+import { Card, OptionCardSection } from "../../react/Card";+import FormToggle from "../../react/FormToggle";+import { useNoteLabelBoolean } from "../../react/hooks";import Modal from "../../react/Modal";import PromotedAttributesCard from "../../react/PromotedAttributesCard";import TemplateSelectionCard from "../../react/TemplateSelectionCard";@@ -30,14 +35,7 @@ export default function BoardProperties({ api, note, shown, onClose }: {show={shown}onHidden={onClose}>- <TemplateSelectionCard- heading={t("board_view.card-templates")}- instruction={t("board_view.card-templates-hint")}- note={note}- newTemplateName={t("board_view.new-template-name")}- templates={api.getCardTemplateIds()}- onChange={store}- />+ <General api={api} note={note} /><PromotedAttributesCardheading={t("board_view.promoted-attributes")}@@ -47,6 +45,46 @@ export default function BoardProperties({ api, note, shown, onClose }: {ignored={[ api.statusAttribute ]}onChange={storeAttributes}/>++ <TemplateSelectionCard+ heading={t("board_view.card-templates")}+ instruction={t("board_view.card-templates-hint")}+ note={note}+ newTemplateName={t("board_view.new-template-name")}+ templates={api.getCardTemplateIds()}+ onChange={store}+ /></Modal>);}++/** What the board draws besides its own cards: the inbox column and what is filed as archived. */+function General({ api, note }: { api: BoardApi, note: FNote }) {+ const [ inboxShown ] = useNoteLabelBoolean(note, "enableInboxColumn");+ const [ archivedShown ] = useNoteLabelBoolean(note, "includeArchived");++ return (+ <Card className="board-properties-general" heading={t("board_view.general")}>+ <OptionCardSection+ name="board-show-inbox"+ label={t("board_view.show-inbox-column")}+ description={t("book_properties_config.board-inbox-column-help")}+ >+ <FormToggle+ currentValue={inboxShown}+ onChange={(shown) => api.setInboxEnabled(shown)}+ />+ </OptionCardSection>++ <OptionCardSection+ name="board-show-archived"+ label={t("board_view.show-archived")}+ >+ <FormToggle+ currentValue={archivedShown}+ onChange={(shown) => api.setArchivedShown(shown)}+ />+ </OptionCardSection>+ </Card>+ );+}diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.css b/apps/client/src/widgets/react/PromotedAttributesCard.cssindex aa2ae89d5f..3c93351d61 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.css+++ b/apps/client/src/widgets/react/PromotedAttributesCard.css@@ -1,7 +1,4 @@.tn-card.promoted-attributes-card {- /* Clears the card above it in the dialogs that stack the two. */- margin-block-start: 24px;-/* The name takes the free space, pushing the edit button and the toggle to the trailing edge. */.promoted-attribute-name {flex-grow: 1;diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsxindex eac07ef62e..96bb4b2806 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx@@ -10,8 +10,12 @@ import type { PromotedAttribute, PromotedAttributeSetting } from "../collectionsimport PromotedAttributesCard from "./PromotedAttributesCard";import { ParentComponent } from "./react_utils";-// i18next is never initialised under test, so every label would read as undefined.-vi.mock("../../services/i18n", () => ({ t: (key: string) => key }));+// i18next is never initialised under test, so every label would read as undefined. The command+// registry, reached through the attribute editor, waits on the translations before it builds.+vi.mock("../../services/i18n", () => ({+ t: (key: string) => key,+ translationsInitializedPromise: Promise.resolve()+}));const mocks = vi.hoisted(() => ({setLabel: vi.fn(),