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(print): print only the notes a saved search matched
Elian Dorane5c208bfef02
diff --git a/apps/client/src/widgets/collections/legacy/ListPrintView.spec.tsx b/apps/client/src/widgets/collections/legacy/ListPrintView.spec.tsxindex 4901512f8d..05352da874 100644--- a/apps/client/src/widgets/collections/legacy/ListPrintView.spec.tsx+++ b/apps/client/src/widgets/collections/legacy/ListPrintView.spec.tsx@@ -56,4 +56,31 @@ describe("ListPrintView", () => {await vi.waitFor(() => expect(onReady).toHaveBeenCalledOnce());expect(container.querySelector("#note-list-print-render .late")?.textContent).toBe("Script output");});++ it("prints the notes a saved search matched, without what hangs under them", async () => {+ buildNote({ id: "root", title: "root", children: [+ { id: "search-print", title: "Search", type: "search" },+ { id: "search-hit", title: "Hit", children: [ { id: "search-hit-child", title: "Child" } ] },+ { id: "search-hit-2", title: "Hit 2" }+ ] });+ const search = froca.getNoteFromCache("search-print");+ if (!search) throw new Error("expected the search note");++ h.getRenderedContent.mockImplementation(async () => ({ $renderedContent: [ document.createElement("div") ] }));++ const onReady = vi.fn();+ const container = renderInto(+ <ListPrintView+ note={search} notePath="root/search-print" noteIds={[ "search-hit", "search-hit-2" ]}+ highlightedTokens={null} viewConfig={undefined} saveConfig={() => {}}+ media="print" onReady={onReady}+ />+ );++ await vi.waitFor(() => expect(onReady).toHaveBeenCalledOnce());+ expect(h.getRenderedContent).toHaveBeenCalledTimes(2);+ expect(container.querySelector("#note-search-hit")).not.toBeNull();+ expect(container.querySelector("#note-search-hit-2")).not.toBeNull();+ expect(container.querySelector("#note-search-hit-child")).toBeNull();+ });});diff --git a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx b/apps/client/src/widgets/collections/legacy/ListPrintView.tsxindex 72071c68b4..5f593459d3 100644--- a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx+++ b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx@@ -24,6 +24,9 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onProuseLayoutEffect(() => {const noteIdsSet = new Set<string>();+ // A saved search prints the notes it matched, not what hangs under them: a matching folder+ // would otherwise bring its whole subtree, and a result repeated once it is also a child.+ const printsChildren = note.type !== "search";froca.getNotes(noteIds).then(async (notes) => {const noteIdsWithChildren = await note.getSubtreeNoteIds(true);@@ -59,7 +62,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onProonProgressChanged(notesWithContent.length / noteIdsWithChildren.length);}- if (note.hasChildren()) {+ if (printsChildren && note.hasChildren()) {const filteredChildNotes = await filterChildNotes(note);for (const childNote of filteredChildNotes) {await processNote(childNote, depth + 1);