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(client): resolve the path of a note dropped from froca
Elian Doran91524cb3b14d
diff --git a/apps/client/src/entities/fnote.spec.ts b/apps/client/src/entities/fnote.spec.tsindex 521bbf3a84..0883c160db 100644--- a/apps/client/src/entities/fnote.spec.ts+++ b/apps/client/src/entities/fnote.spec.ts@@ -825,6 +825,27 @@ describe("FNote paths & hierarchy", () => {expect(withActive[0].notePath).toEqual(["root", "plainP", "hoistLeaf"]);});+ it("getBestNotePathString still resolves a note that froca has dropped", () => {+ const root = froca.notes["root"] ?? buildNote({ id: "root", title: "root" });+ const parent = buildNote({ id: "droppedParent", title: "parent" });+ registerBranch("br-root-droppedParent", "droppedParent", "root", 0);+ root.addChild("droppedParent", "br-root-droppedParent", false);+ parent.addParent("root", "br-root-droppedParent", false);++ const leaf = buildNote({ id: "droppedLeaf", title: "leaf", "#archived": "" });+ registerBranch("br-droppedParent-droppedLeaf", "droppedLeaf", "droppedParent", 0);+ parent.addChild("droppedLeaf", "br-droppedParent-droppedLeaf", false);+ leaf.addParent("droppedParent", "br-droppedParent-droppedLeaf", false);++ // `froca_updater` removes a deleted note from `froca.notes`, while a view can still hold it.+ delete froca.notes["droppedLeaf"];++ const [ record ] = leaf.getSortedNotePathRecords("root");+ expect(record.notePath).toEqual(["root", "droppedParent", "droppedLeaf"]);+ expect(record.isArchived).toBe(true);+ expect(leaf.getBestNotePathString()).toBe("root/droppedParent/droppedLeaf");+ });+it("getSortedNotePathRecords comparator exercises both ternary directions (reversed parent order)", () => {const root = froca.notes["root"] ?? buildNote({ id: "root", title: "root" });const hidden = froca.notes["_hidden"] ?? buildNote({ id: "_hidden", title: "hidden" });diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex eab1b26f83..4ef1a39797 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -438,12 +438,16 @@ export default class FNote {getSortedNotePathRecords(hoistedNoteId = "root", activeNotePath: string | null = null): NotePathRecord[] {const isHoistedRoot = hoistedNoteId === "root";+ // Every ancestor in a path comes out of `froca.notes`, but the last segment is this note,+ // which a view can still hold after `froca_updater` drops it from the cache.+ const getPathNote = (noteId: string) =>+ noteId === this.noteId ? this : this.froca.notes[noteId];const notePaths: NotePathRecord[] = this.getAllNotePaths().map((path) => ({notePath: path,isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId),- isArchived: path.some((noteId) => this.froca.notes[noteId].isArchived),- isSearch: path.some((noteId) => this.froca.notes[noteId].type === "search"),+ isArchived: path.some((noteId) => getPathNote(noteId).isArchived),+ isSearch: path.some((noteId) => getPathNote(noteId).type === "search"),isHidden: path.includes("_hidden")}));