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
fix(collections/table): leave the hidden subtree out of root's table
Elian Dorand4887a22694f
diff --git a/apps/client/src/widgets/collections/table/rows.spec.ts b/apps/client/src/widgets/collections/table/rows.spec.tsindex 97413430b4..8367eeecc9 100644--- a/apps/client/src/widgets/collections/table/rows.spec.ts+++ b/apps/client/src/widgets/collections/table/rows.spec.ts@@ -240,6 +240,27 @@ describe("buildRowDefinitions", () => {expect(definitions[2]._children?.[1]._children?.[0]).toMatchObject({ title: "C2.x" });post.mockRestore();});++ it("leaves out the hidden subtree, as the note tree does under root", async () => {+ const parent = buildNote({+ title: "Root",+ children: [+ { title: "Task" },+ { id: "_hidden", title: "Hidden Notes", children: [ { title: "Help" } ] }+ ]+ });+ const hiddenChild = froca.getNoteFromCache("_hidden")?.children[0];+ if (!hiddenChild) throw new Error("expected the hidden subtree to be built");+ delete froca.notes[hiddenChild];+ const post = vi.spyOn(server, "post").mockResolvedValue({});++ const { definitions, hasSubtree } = await buildRowDefinitions(parent, [], false);++ expect(definitions.map((def) => def.title)).toEqual([ "Task" ]);+ expect(hasSubtree).toBe(false);+ expect(post.mock.calls.filter(([ url ]) => url === "tree/load")).toHaveLength(0);+ post.mockRestore();+ });});/** Gives the note another relation under a name it already carries, which one literal cannot. */diff --git a/apps/client/src/widgets/collections/table/rows.ts b/apps/client/src/widgets/collections/table/rows.tsindex 8853b62b66..73917fa39e 100644--- a/apps/client/src/widgets/collections/table/rows.ts+++ b/apps/client/src/widgets/collections/table/rows.ts@@ -44,7 +44,7 @@ export async function buildRowDefinitions(parentNote: FNote, infos: AttributeDeffor (const branch of childBranches) {const note = await branch.getNote();- if (!note || (!includeArchived && note.isArchived)) {+ if (!note || !isRowNote(note, includeArchived)) {continue;}@@ -111,11 +111,16 @@ async function loadRowNotes(parentNote: FNote, includeArchived: boolean, maxDeptlet parents = [ parentNote ];for (let depth = 0; parents.length > 0; depth++) {const notes = await froca.getNotes(parents.flatMap((note) => note.children), true);- parents = notes.filter((note) => (includeArchived || !note.isArchived)+ parents = notes.filter((note) => isRowNote(note, includeArchived)&& note.hasChildren() && (maxDepth < 0 || depth < maxDepth));}}+/** Whether the note gets a row. `_hidden` sits under root, where the note tree leaves it out too. */+function isRowNote(note: FNote, includeArchived: boolean) {+ return note.noteId !== "_hidden" && (includeArchived || !note.isArchived);+}+/*** Fills each row's `relationTitles` with the titles its relation cells show, loading the targets* as one batch. A relation can point at a note since deleted, or one the user may not see — such