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(note_list): archived notes displayed in empty grid card (closes #8184)
Elian Doranae881101d821
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.tsindex 38bb779ac6..cdfdb67fe1 100644--- a/apps/client/src/services/content_renderer.ts+++ b/apps/client/src/services/content_renderer.ts@@ -25,6 +25,8 @@ export interface RenderOptions {noChildrenList?: boolean;/** If enabled, it will prevent rendering of included notes. */noIncludedNotes?: boolean;+ /** If enabled, it will include archived notes when rendering children list. */+ includeArchivedNotes?: boolean;/** Set of note IDs that have already been seen during rendering to prevent infinite recursion. */seenNoteIds?: Set<string>;}diff --git a/apps/client/src/services/content_renderer_text.spec.ts b/apps/client/src/services/content_renderer_text.spec.tsindex 6480e1991f..e9955d4b0d 100644--- a/apps/client/src/services/content_renderer_text.spec.ts+++ b/apps/client/src/services/content_renderer_text.spec.ts@@ -96,4 +96,39 @@ describe("Text content renderer", () => {await renderText(note, $(contentEl));expect(contentEl.querySelectorAll("section.include-note").length).toBe(1);});++ it("renders children list when note is empty", async () => {+ const contentEl = document.createElement("div");+ const parentNote = buildNote({+ title: "Parent note",+ children: [+ { title: "Child note 1" },+ { title: "Child note 2" }+ ]+ });+ await renderText(parentNote, $(contentEl));+ console.log(contentEl.innerHTML);+ const items = contentEl.querySelectorAll("a");+ expect(items.length).toBe(2);+ expect(items[0].textContent).toBe("Child note 1");+ expect(items[1].textContent).toBe("Child note 2");+ });++ it("skips archived notes in children list", async () => {+ const contentEl = document.createElement("div");+ const parentNote = buildNote({+ title: "Parent note",+ children: [+ { title: "Child note 1" },+ { title: "Child note 2", "#archived": "" },+ { title: "Child note 3" }+ ]+ });+ await renderText(parentNote, $(contentEl));+ console.log(contentEl.innerHTML);+ const items = contentEl.querySelectorAll("a");+ expect(items.length).toBe(2);+ expect(items[0].textContent).toBe("Child note 1");+ expect(items[1].textContent).toBe("Child note 3");+ });});diff --git a/apps/client/src/services/content_renderer_text.ts b/apps/client/src/services/content_renderer_text.tsindex a3f277c492..090aa7f03c 100644--- a/apps/client/src/services/content_renderer_text.ts+++ b/apps/client/src/services/content_renderer_text.ts@@ -42,7 +42,7 @@ export default async function renderText(note: FNote | FAttachment, $renderedConawait rewriteMermaidDiagramsInContainer($renderedContent[0] as HTMLDivElement);await formatCodeBlocks($renderedContent);} else if (note instanceof FNote && !options.noChildrenList) {- await renderChildrenList($renderedContent, note);+ await renderChildrenList($renderedContent, note, options.includeArchivedNotes ?? false);}}@@ -115,7 +115,7 @@ export async function applyInlineMermaid(container: HTMLDivElement) {}}-async function renderChildrenList($renderedContent: JQuery<HTMLElement>, note: FNote) {+async function renderChildrenList($renderedContent: JQuery<HTMLElement>, note: FNote, includeArchivedNotes: boolean) {let childNoteIds = note.getChildNoteIds();if (!childNoteIds.length) {@@ -125,14 +125,16 @@ async function renderChildrenList($renderedContent: JQuery<HTMLElement>, note: F$renderedContent.css("padding", "10px");$renderedContent.addClass("text-with-ellipsis");+ // just load the first 10 child notesif (childNoteIds.length > 10) {childNoteIds = childNoteIds.slice(0, 10);}- // just load the first 10 child notesconst childNotes = await froca.getNotes(childNoteIds);for (const childNote of childNotes) {+ if (childNote.isArchived && !includeArchivedNotes) continue;+$renderedContent.append(await link.createLink(`${note.noteId}/${childNote.noteId}`, {showTooltip: false,diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsxindex 9a0c7391db..74e2182b71 100644--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx@@ -45,6 +45,7 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);const { pageNotes, ...pagination } = usePagination(note, noteIds);+ const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived");return (<div class="note-list grid-view">@@ -53,7 +54,7 @@ export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens }<div class="note-list-container use-tn-links">{pageNotes?.map(childNote => (- <GridNoteCard note={childNote} parentNote={note} highlightedTokens={highlightedTokens} />+ <GridNoteCard note={childNote} parentNote={note} highlightedTokens={highlightedTokens} includeArchived={includeArchived} />))}</div>@@ -95,14 +96,14 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan</h5>{isExpanded && <>- <NoteContent note={note} highlightedTokens={highlightedTokens} noChildrenList />+ <NoteContent note={note} highlightedTokens={highlightedTokens} noChildrenList includeArchivedNotes={includeArchived} /><NoteChildren note={note} parentNote={parentNote} highlightedTokens={highlightedTokens} currentLevel={currentLevel} expandDepth={expandDepth} includeArchived={includeArchived} /></>}</div>);}-function GridNoteCard({ note, parentNote, highlightedTokens }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined }) {+function GridNoteCard({ note, parentNote, highlightedTokens, includeArchived }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined, includeArchived: boolean }) {const titleRef = useRef<HTMLSpanElement>(null);const [ noteTitle, setNoteTitle ] = useState<string>();const notePath = getNotePath(parentNote, note);@@ -130,6 +131,7 @@ function GridNoteCard({ note, parentNote, highlightedTokens }: { note: FNote, panote={note}trimhighlightedTokens={highlightedTokens}+ includeArchivedNotes={includeArchived}/></div>);@@ -146,7 +148,13 @@ function NoteAttributes({ note }: { note: FNote }) {return <span className="note-list-attributes" ref={ref} />;}-function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note: FNote, trim?: boolean, noChildrenList?: boolean, highlightedTokens: string[] | null | undefined }) {+function NoteContent({ note, trim, noChildrenList, highlightedTokens, includeArchivedNotes }: {+ note: FNote;+ trim?: boolean;+ noChildrenList?: boolean;+ highlightedTokens: string[] | null | undefined;+ includeArchivedNotes: boolean;+}) {const contentRef = useRef<HTMLDivElement>(null);const highlightSearch = useImperativeSearchHighlighlighting(highlightedTokens);@@ -154,7 +162,8 @@ function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note:content_renderer.getRenderedContent(note, {trim,noChildrenList,- noIncludedNotes: true+ noIncludedNotes: true,+ includeArchivedNotes}).then(({ $renderedContent, type }) => {if (!contentRef.current) return;