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
feat(board): limit the cards to #maxNestingDepth
Elian Doran6460a6bdae05
diff --git a/apps/client/src/widgets/collections/NoteList.spec.tsx b/apps/client/src/widgets/collections/NoteList.spec.tsxindex b58d93f103..d3cab02dcd 100644--- a/apps/client/src/widgets/collections/NoteList.spec.tsx+++ b/apps/client/src/widgets/collections/NoteList.spec.tsx@@ -230,8 +230,8 @@ describe("useNoteIds nesting depth", () => {return currentNoteIds;}- it("limits the calendar and geo map subtree to #maxNestingDepth", async () => {- for (const viewType of [ "calendar", "geoMap" ] as const) {+ it("limits the calendar, geo map and board subtree to #maxNestingDepth", async () => {+ for (const viewType of [ "calendar", "geoMap", "board" ] as const) {expect(await renderNoteIds(viewType)).toEqual([ "nested-0", "nested-1", "nested-2" ]);expect(await renderNoteIds(viewType, { "#maxNestingDepth": "0" })).toEqual([ "nested-0" ]);expect(await renderNoteIds(viewType, { "#maxNestingDepth": "1" }))diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsxindex ecac573186..419080e351 100644--- a/apps/client/src/widgets/collections/NoteList.tsx+++ b/apps/client/src/widgets/collections/NoteList.tsx@@ -190,10 +190,9 @@ export function useNoteIds(note: FNote | null | undefined, viewType: ViewTypeOptconst [ noteIds, setNoteIds ] = useState<string[]>([]);const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");const directChildrenOnly = (viewType === "list" || viewType === "grid" || viewType === "table" || viewType === "dashboard" || note?.type === "search");- // The board walks the subtree itself in `getBoardData()`, so its note IDs stay unlimited to- // match the cards it draws.const [ labelMaxDepth ] = useNoteLabelInt(note, "maxNestingDepth");- const maxDepth = (viewType === "calendar" || viewType === "geoMap") ? labelMaxDepth : undefined;+ const maxDepth = (viewType === "calendar" || viewType === "geoMap" || viewType === "board")+ ? labelMaxDepth : undefined;// getNoteIds can do a server round-trip (archive filtering), so concurrent refreshes may resolve// out of order. Track the latest issued refresh so a stale one can't clobber a newer result.const refreshSeqRef = useRef(0);diff --git a/apps/client/src/widgets/collections/board/data.spec.ts b/apps/client/src/widgets/collections/board/data.spec.tsindex 5800b96b07..60c3b4ea9a 100644--- a/apps/client/src/widgets/collections/board/data.spec.ts+++ b/apps/client/src/widgets/collections/board/data.spec.ts@@ -199,6 +199,32 @@ describe("Board data", () => {expect(titles("")).toEqual([ "Unassigned" ]);});+ it("collects cards only as deep as #maxNestingDepth says", async () => {+ const board = buildNote({+ title: "Board",+ "#collection": "",+ "#viewType": "board",+ children: [+ { title: "Child", "#status": "To Do", children: [+ { title: "Grandchild", "#status": "To Do", children: [+ { title: "Great-grandchild", "#status": "To Do" }+ ] }+ ] }+ ]+ });++ async function titlesAt(maxDepth: number | undefined) {+ const data = await getBoardData(+ board, "status", {}, false, [], new Map(), false, maxDepth);+ return (data.byColumn.get("To Do") ?? []).map((item) => item.note.title).sort();+ }++ expect(await titlesAt(0)).toEqual([ "Child" ]);+ expect(await titlesAt(1)).toEqual([ "Child", "Grandchild" ]);+ expect(await titlesAt(undefined)).toEqual([ "Child", "Grandchild", "Great-grandchild" ]);+ expect(await titlesAt(-1)).toEqual([ "Child", "Grandchild", "Great-grandchild" ]);+ });+/*** A column inserted or dragged is written to the attachment at once and to the definition a* round trip later. The refresh in between must not put it back where the definition says.diff --git a/apps/client/src/widgets/collections/board/data.ts b/apps/client/src/widgets/collections/board/data.tsindex c9b16497c4..9ce3f5104f 100644--- a/apps/client/src/widgets/collections/board/data.ts+++ b/apps/client/src/widgets/collections/board/data.ts@@ -253,7 +253,9 @@ export async function getBoardData(definitionOptions: string[] = [],pendingRenames: ReadonlyMap<string, string | undefined> = new Map(),/** Whether the board keeps an inbox, which decides whether unassigned notes are collected. */- inboxEnabled = false+ inboxEnabled = false,+ /** How many levels below its children the board collects cards from, unlimited if absent. */+ maxDepth?: number) {const byColumn: ColumnMap = new Map();const storedColumns = readColumns(persistedData, groupByColumn) ?? [];@@ -274,7 +276,7 @@ export async function getBoardData(// First, scan all notes to find what columns actually existawait recursiveGroupBy(parentNote.getChildBranches(), byColumn, groupByColumn, includeArchived,- new Set<string>(), inbox, 0);+ new Set<string>(), inbox, 0, maxDepth);const discoveredValues = [ ...byColumn.keys() ];const columns = resolveBoardColumns(@@ -357,10 +359,12 @@ function regroupRenamedCards(/*** @param inbox where unassigned notes are collected, absent if the board has no inbox.* @param depth how deep below the board the branches are, the board's own children being 0.+ * @param maxDepth the deepest `depth` collected, unlimited if absent or negative.*/async function recursiveGroupBy(branches: FBranch[], byColumn: ColumnMap, groupByColumn: string, includeArchived: boolean,- seenNoteIds: Set<string>, inbox: { nested: boolean } | undefined, depth: number+ seenNoteIds: Set<string>, inbox: { nested: boolean } | undefined, depth: number,+ maxDepth: number | undefined) {for (const branch of branches) {const note = await branch.getNote();@@ -370,10 +374,11 @@ async function recursiveGroupBy(// properties is filed under it, and the inbox would otherwise collect it as one.const isTemplate = note.hasLabel("template");- if (note.type !== "search" && note.hasChildren()) {+ const canDescend = maxDepth === undefined || maxDepth < 0 || depth < maxDepth;+ if (canDescend && note.type !== "search" && note.hasChildren()) {await recursiveGroupBy(note.getChildBranches(), byColumn, groupByColumn, includeArchived,- seenNoteIds, inbox, depth + 1);+ seenNoteIds, inbox, depth + 1, maxDepth);}// A note with no value goes to the inbox, if the board has one and reaches this deep.diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex cf2b880f10..f29dabe34a 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -34,8 +34,8 @@ import CollectionProperties from "../../note_bars/CollectionProperties";import { FormListItem } from "../../react/FormList";import {useContextualShortcutHints, useEffectiveReadOnly, useLingeringTrue, useNoteContext, useNoteLabel,- useNoteLabelBoolean, useNoteLabelWithDefault, useNoteTypeOptions, useSetContextData,- useTrackedElement, useTriliumEvent+ useNoteLabelBoolean, useNoteLabelInt, useNoteLabelWithDefault, useNoteTypeOptions,+ useSetContextData, useTrackedElement, useTriliumEvent} from "../../react/hooks";import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";import { type TemplateChoiceConfig, useTemplateChoice } from "../../react/TemplateDropdown";@@ -405,6 +405,7 @@ function Board({let viewConfig = adoptedConfig ?? storedConfig;const [ includeArchived ] = useNoteLabelBoolean(parentNote, "includeArchived");const [ inboxEnabled ] = useNoteLabelBoolean(parentNote, "board:showInbox");+ const [ maxDepth ] = useNoteLabelInt(parentNote, "maxNestingDepth");const [ addColumnHidden ] = useNoteLabelBoolean(parentNote, "board:hideAddColumn");// Read undefaulted: a board naming no width wears no class, so `--board-column-width` keeps// whatever it inherits.@@ -935,7 +936,7 @@ function Board({getBoardData(parentNote, target, viewConfig ?? {}, includeArchived,- definition?.options ?? [], renames, inboxEnabled)+ definition?.options ?? [], renames, inboxEnabled, maxDepth).then(({byColumn: allCards, columns, newPersistedData, isInRelationMode, settledRenames}) => {@@ -1204,7 +1205,8 @@ function Board({// `groupBy` is a dependency as well as `requestedGroupBy`: committing a switch is what asks for// the refresh that stores the new grouping's columns.useEffect(refresh, [- parentNote, noteIds, viewConfig, requestedGroupBy, groupBy, statusDefinition, inboxEnabled+ parentNote, noteIds, viewConfig, requestedGroupBy, groupBy, statusDefinition, inboxEnabled,+ maxDepth]);// The drag reports where the column landed among the ones on screen, which is not where itdiff --git a/apps/client/src/widgets/collections/board/properties.spec.tsx b/apps/client/src/widgets/collections/board/properties.spec.tsxindex 2cce81ddb8..cefa7499ee 100644--- a/apps/client/src/widgets/collections/board/properties.spec.tsx+++ b/apps/client/src/widgets/collections/board/properties.spec.tsx@@ -14,6 +14,24 @@ import BoardProperties from "./properties";vi.mock("../../../services/i18n", () => ({t: (key: string) => key}));+// The shared property definitions translate through i18next directly, at import.+vi.mock("i18next", async (importOriginal) => ({+ ...await importOriginal<typeof import("i18next")>(),+ t: (key: string) => key+}));++const mocks = vi.hoisted(() => ({+ setBooleanWithInheritance: vi.fn(async () => {}),+ setLabel: vi.fn(async () => {})+}));++vi.mock("../../../services/attributes", () => ({+ default: {+ setBooleanWithInheritance: mocks.setBooleanWithInheritance,+ setLabel: mocks.setLabel,+ isAffecting: () => true+ }+}));// TemplateSelectionCard is tested in its own spec. What this dialog decides is the labels it// passes and where onChange writes.@@ -155,30 +173,25 @@ describe("Board properties", () => {});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:not(.tn-card-section-nested)") ?? [];- expect(rows.length).toBe(5);+ expect(rows.length).toBe(4);expect(toggleAt(0)?.classList.contains("on")).toBe(false);expect(toggleAt(1)?.classList.contains("on")).toBe(true);- expect(toggleAt(2)?.classList.contains("on")).toBe(true);labels["board:hideAddColumn"] = "true";act(() => { render(null, container); });draw();- expect(toggleAt(2)?.classList.contains("on")).toBe(false);+ expect(toggleAt(1)?.classList.contains("on")).toBe(false);});it("asks the board to show each of them", () => {act(() => { toggleAt(0)?.click(); });act(() => { toggleAt(1)?.click(); });- act(() => { toggleAt(2)?.click(); });- expect(toggled).toEqual([- [ "inbox", true ], [ "archived", false ], [ "add-column", false ]- ]);+ expect(toggled).toEqual([ [ "inbox", true ], [ "add-column", false ] ]);});function toggleAt(index: number) {@@ -270,6 +283,24 @@ describe("Board properties", () => {}});+ it("holds which notes the board gathers in a card of their own, after General", () => {+ const included = dialog()?.querySelector<HTMLElement>(".collection-included-notes");+ const titles = [ ...included?.querySelectorAll(".tn-card-option-title") ?? [] ]+ .map((title) => title.textContent);+ expect(titles).toEqual([+ "board_view.show-archived", "book_properties_config.max-nesting-depth"+ ]);+ expect(general()?.compareDocumentPosition(included as Node))+ .toBe(Node.DOCUMENT_POSITION_FOLLOWING);++ const archived = included?.querySelector<HTMLElement>(".switch-button");+ expect(archived?.classList.contains("on")).toBe(true);+ act(() => { archived?.click(); });+ expect(mocks.setBooleanWithInheritance)+ .toHaveBeenCalledWith(+ expect.objectContaining({ noteId: "board1" }), "includeArchived", false);+ });+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 97696593b9..e9f80ad46d 100644--- a/apps/client/src/widgets/collections/board/properties.tsx+++ b/apps/client/src/widgets/collections/board/properties.tsx@@ -4,7 +4,7 @@ import type FNote from "../../../entities/fnote";import dialog from "../../../services/dialog";import { t } from "../../../services/i18n";import { isMobile } from "../../../services/utils";-import { CollectionPropertiesDialog } from "../../note_bars/CollectionProperties";+import { CollectionPropertiesDialog, IncludedNotesCard } from "../../note_bars/CollectionProperties";import { Card, CardSection, OptionCardSection } from "../../react/Card";import FormSelect from "../../react/FormSelect";import FormToggle from "../../react/FormToggle";@@ -40,6 +40,8 @@ export default function BoardProperties({ api, note, shown, onClose }: {><General api={api} note={note} />+ <IncludedNotesCard note={note} archivedLabel={t("board_view.show-archived")} />+<PromotedAttributesCardheading={t("board_view.promoted-attributes")}instruction={t("board_view.promoted-attributes-hint")}@@ -62,10 +64,9 @@ export default function BoardProperties({ api, note, shown, onClose }: {);}-/** What the board draws besides its own cards: the inbox column and what is filed as archived. */+/** What the board draws besides its own cards, such as the inbox column, and how. */function General({ api, note }: { api: BoardApi, note: FNote }) {const [ inboxShown ] = useNoteLabelBoolean(note, "board:showInbox");- const [ archivedShown ] = useNoteLabelBoolean(note, "includeArchived");const [ addColumnHidden ] = useNoteLabelBoolean(note, "board:hideAddColumn");const [ columnWidth ] =useNoteLabelWithDefault(note, COLUMN_WIDTH_LABEL, DEFAULT_COLUMN_WIDTH);@@ -91,16 +92,6 @@ function General({ api, note }: { api: BoardApi, note: FNote }) {/></OptionCardSection>- <OptionCardSection- name="board-show-archived"- label={t("board_view.show-archived")}- >- <FormToggle- currentValue={archivedShown}- onChange={(shown) => api.setArchivedShown(shown)}- />- </OptionCardSection>-<OptionCardSectionname="board-show-add-column"label={t("board_view.show-add-column-button")}diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsxindex bb5442a1e9..e9d4bb42bd 100644--- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx+++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx@@ -263,10 +263,18 @@ function ViewOptions({ note, viewType, optionsChildren }: {* Which notes a collection gathers, as opposed to how its view draws them: a card shared by the* properties dialogs, placed after their General card.*/-export function IncludedNotesCard({ note }: { note: FNote }) {+export function IncludedNotesCard({ note, archivedLabel }: {+ note: FNote;+ /** Names the archived toggle in the view's own words, such as a board's cards and columns. */+ archivedLabel?: string;+}) {+ const archivedProperty = archivedLabel+ ? { ...INCLUDE_ARCHIVED_PROPERTY, label: archivedLabel }+ : INCLUDE_ARCHIVED_PROPERTY;+return (<Card className="collection-included-notes" heading={t("book_properties.included_notes")}>- <ViewPropertySection note={note} property={INCLUDE_ARCHIVED_PROPERTY} />+ <ViewPropertySection note={note} property={archivedProperty} /><ViewPropertySection note={note} property={MAX_NESTING_DEPTH_PROPERTY} /></Card>);diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.htmlindex 6259fcffc2..128b35e043 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html@@ -10,6 +10,11 @@nested notes will be displayed. However, unlike the <a class="reference-link"href="#root/_help_2FvYrpmOXm29">Table</a>, the notes are not displayedhierarchically.</p>+<p>To limit how deep the board looks, go to <a class="reference-link" href="#root/_help_8YBEPzcpUgxw">Note menu</a> → <em>Board properties</em> and+ set <em>Maximum nesting depth</em> (under the <em>Included notes</em> section),+ or apply the <code>#maxNestingDepth</code> label to the board note: <code>0</code> shows+ only the children, <code>1</code> adds their children, and so on. Without+ a value, every level is shown.</p><h2>Working with columns</h2><h3>Creating columns</h3><p>You can create a new column by pressing the <span class="tn-icon bx bx-plus"></span> <em>Add column</em> button@@ -242,9 +247,11 @@href="#root/_help_MKmLg5x6xkor">Archived Notes</a>) on the notes correspondingto its cards.</p><p>To show archived columns again, go to <span class="tn-icon bx bx-cog"></span> <em>Collection options</em> and- toggle <span class="tn-icon bx bx-archive-in"></span> <em>Show archived notes</em>.- Archived columns will appear faded. To restore one, open its column menu- and select <span class="tn-icon bx bx-archive-out"></span> <em>Unarchive column</em>.</p>+ toggle <span class="tn-icon bx bx-archive-in"></span> <em>Show archived notes</em>,+ or turn on <em>Show archived cards and columns</em> in <a class="reference-link"+ href="#root/_help_8YBEPzcpUgxw">Note menu</a> → <em>Board properties</em> (under+ the <em>Included notes</em> section). Archived columns will appear faded.+ To restore one, open its column menu and select <span class="tn-icon bx bx-archive-out"></span> <em>Unarchive column</em>.</p><h3>Deleting a column</h3><p>You can delete a column by opening the column menu → <span class="tn-icon bx bx-trash"></span> <em>Delete column</em>,or by pressing <kbd>Delete</kbd> when a column header is focused, and then@@ -463,9 +470,11 @@ class="admonition tip">class="tn-icon bx bx-archive-in"></span> <em>Archive note</em> command fromthe card's context menu.</p><p>To show archived cards again, go to <span class="tn-icon bx bx-cog"></span> <em>Collection options</em> and- toggle <span class="tn-icon bx bx-archive-in"></span> <em>Show archived notes</em>.- Archived cards will appear faded. To restore one, open its context menu- and select <span class="tn-icon bx bx-archive-out"></span> <em>Unarchive note</em>.</p>+ toggle <span class="tn-icon bx bx-archive-in"></span> <em>Show archived notes</em>,+ or turn on <em>Show archived cards and columns</em> in <a class="reference-link"+ href="#root/_help_8YBEPzcpUgxw">Note menu</a> → <em>Board properties</em> (under+ the <em>Included notes</em> section). Archived cards will appear faded. To+ restore one, open its context menu and select <span class="tn-icon bx bx-archive-out"></span> <em>Unarchive note</em>.</p><asideclass="admonition warning"><p>Archiving a card sets the <code>#archived</code> flag on its note. If thediff --git a/docs/User Guide/User Guide/Collections/Kanban Board.md b/docs/User Guide/User Guide/Collections/Kanban Board.mdindex e8cb1aa989..710303f8a9 100644--- a/docs/User Guide/User Guide/Collections/Kanban Board.md+++ b/docs/User Guide/User Guide/Collections/Kanban Board.md@@ -11,6 +11,8 @@ When you first create a collection of the _Board_ type, a few subnotes are creatNotes are displayed recursively, so even grandchildren and more deeply nested notes will be displayed. However, unlike the <a class="reference-link" href="Table.md">Table</a>, the notes are not displayed hierarchically.+To limit how deep the board looks, go to <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> → _Board properties_ and set _Maximum nesting depth_ (under the _Included notes_ section), or apply the `#maxNestingDepth` label to the board note: `0` shows only the children, `1` adds their children, and so on. Without a value, every level is shown.+## Working with columns### Creating columns@@ -146,7 +148,7 @@ A column that has reached its limit can still accept new cards. Blocking new carIf you want to hide a column from the board without deleting it, you can archive it by opening the column menu → <span class="tn-icon bx bx-archive-in"></span> _Archive column_. Archiving a column does not set the archived flag (see <a class="reference-link" href="../Basic%20Concepts%20and%20Features/Notes/Archived%20Notes.md">Archived Notes</a>) on the notes corresponding to its cards.-To show archived columns again, go to <span class="tn-icon bx bx-cog"></span> _Collection options_ and toggle <span class="tn-icon bx bx-archive-in"></span> _Show archived notes_. Archived columns will appear faded. To restore one, open its column menu and select <span class="tn-icon bx bx-archive-out"></span> _Unarchive column_.+To show archived columns again, go to <span class="tn-icon bx bx-cog"></span> _Collection options_ and toggle <span class="tn-icon bx bx-archive-in"></span> _Show archived notes_, or turn on _Show archived cards and columns_ in <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> → _Board properties_ (under the _Included notes_ section). Archived columns will appear faded. To restore one, open its column menu and select <span class="tn-icon bx bx-archive-out"></span> _Unarchive column_.### Deleting a column@@ -289,7 +291,7 @@ Each card can be tinted with a different color. Open the card's context menu andA card can be hidden from the board without deleting it by using the <span class="tn-icon bx bx-archive-in"></span> _Archive note_ command from the card's context menu.-To show archived cards again, go to <span class="tn-icon bx bx-cog"></span> _Collection options_ and toggle <span class="tn-icon bx bx-archive-in"></span> _Show archived notes_. Archived cards will appear faded. To restore one, open its context menu and select <span class="tn-icon bx bx-archive-out"></span> _Unarchive note_.+To show archived cards again, go to <span class="tn-icon bx bx-cog"></span> _Collection options_ and toggle <span class="tn-icon bx bx-archive-in"></span> _Show archived notes_, or turn on _Show archived cards and columns_ in <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> → _Board properties_ (under the _Included notes_ section). Archived cards will appear faded. To restore one, open its context menu and select <span class="tn-icon bx bx-archive-out"></span> _Unarchive note_.> [!WARNING]> Archiving a card sets the `#archived` flag on its note. If the note exists in multiple locations in the tree, it will appear archived in those locations as well. Read more about <a class="reference-link" href="../Basic%20Concepts%20and%20Features/Notes/Archived%20Notes.md">Archived Notes</a>.