Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): note map of an archived note coming out empty

Elian Doran038261ce1317
diff --git a/packages/trilium-core/src/routes/api/note_map.spec.ts b/packages/trilium-core/src/routes/api/note_map.spec.ts
index b865174003..f1717dd0be 100644
--- a/packages/trilium-core/src/routes/api/note_map.spec.ts
+++ b/packages/trilium-core/src/routes/api/note_map.spec.ts
@@ -242,6 +242,35 @@ describe("Note map service (branch coverage)", () => {
expect(exNames).not.toContain("friend");
});
+ it("keeps archived notes only for a map rooted at an archived note", () => {
+ const archivedRoot = buildNote({
+ id: "arcRoot",
+ title: "Archived root",
+ "#archived": "true",
+ children: [
+ { id: "arcChild", title: "Archived child", "#archived": "true", "~friend": "arcRoot" }
+ ]
+ });
+
+ // Without this, the walk skips the root as archived and the map comes out empty: the root is
+ // missing from its own map, and the relation goes with it since a link needs both of its ends.
+ const linkMap = note_map.getLinkMap(req(archivedRoot.noteId)) as LinkMapResponse;
+ expect(linkMap.notes.map((n) => n[0])).toEqual(expect.arrayContaining([ "arcRoot", "arcChild" ]));
+ expect(linkMap.links.map((l) => l.name)).toContain("friend");
+
+ const treeMap = note_map.getTreeMap(req(archivedRoot.noteId)) as TreeMapResponse;
+ expect(treeMap.notes.map((n) => n[0])).toEqual(expect.arrayContaining([ "arcRoot", "arcChild" ]));
+
+ // A map rooted at a note that isn't archived keeps hiding the archived notes under it.
+ const liveRoot = buildNote({
+ id: "arcLiveRoot",
+ title: "Live root",
+ children: [ { id: "arcHidden", title: "Archived child", "#archived": "true" } ]
+ });
+ const liveMap = note_map.getLinkMap(req(liveRoot.noteId)) as LinkMapResponse;
+ expect(liveMap.notes.map((n) => n[0])).not.toContain("arcHidden");
+ });
+
it("getLinkMap: imageLink retained only when target is not a child of the source", () => {
// source -> imageLink -> external image note (not a child) => retained as a link
const mapRoot = buildNote({
diff --git a/packages/trilium-core/src/routes/api/note_map.ts b/packages/trilium-core/src/routes/api/note_map.ts
index 1e29bb16fa..534e5058e7 100644
--- a/packages/trilium-core/src/routes/api/note_map.ts
+++ b/packages/trilium-core/src/routes/api/note_map.ts
@@ -104,6 +104,11 @@ function getLinkMap(req: Request<{ noteId: string }>) {
// if the map root itself has "excludeFromNoteMap" attribute (journal typically) then there wouldn't be anything
// to display, so we'll just ignore it
const ignoreExcludeFromNoteMap = mapRootNote.isLabelTruthy("excludeFromNoteMap");
+ // a subtree walk skips an archived note along with everything below it — the map root included,
+ // which left an archived note out of its own map, and its relations dropped with it (a link needs
+ // both of its ends in the map). Someone reading an archived note is already looking at the
+ // archive, so there we keep the archived notes instead of hiding them.
+ const includeArchived = mapRootNote.isArchived;
let unfilteredNotes;
const toSet = (data: unknown) => new Set<string>(data instanceof Array ? data : []);
@@ -116,7 +121,7 @@ function getLinkMap(req: Request<{ noteId: string }>) {
unfilteredNotes = mapRootNote.getSearchResultNotes();
} else {
unfilteredNotes = mapRootNote.getSubtree({
- includeArchived: false,
+ includeArchived,
resolveSearch: true,
includeHidden: mapRootNote.isInHiddenSubtree()
}).notes;
@@ -181,8 +186,9 @@ function getTreeMap(req: Request<{ noteId: string }>) {
// if the map root itself has "excludeFromNoteMap" (journal typically) then there wouldn't be anything to display,
// so we'll just ignore it
const ignoreExcludeFromNoteMap = mapRootNote.isLabelTruthy("excludeFromNoteMap");
+ // the map of an archived note keeps the archived notes — see getLinkMap
const subtree = mapRootNote.getSubtree({
- includeArchived: false,
+ includeArchived: mapRootNote.isArchived,
resolveSearch: true,
includeHidden: mapRootNote.isInHiddenSubtree()
});