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(sort): re-sort through inherited and chained template relations
Elian Dorana515392ac1a1
diff --git a/packages/trilium-core/src/services/handlers.spec.ts b/packages/trilium-core/src/services/handlers.spec.tsindex 2033598835..76bf09c1bb 100644--- a/packages/trilium-core/src/services/handlers.spec.ts+++ b/packages/trilium-core/src/services/handlers.spec.ts@@ -193,6 +193,31 @@ describe("handlers", () => {});});+ describe("template re-sorting", () => {+ it("re-sorts the parents of notes reached through inherited and chained templates", () => {+ buildNote({ id: "tc-tpl" });+ buildNote({ id: "tc-tpl2", "~template": "tc-tpl" });+ buildNote({ id: "tc-folder", children: [{ id: "tc-chld" }] });+ new BAttribute({+ noteId: "tc-folder", attributeId: randomString(12), type: "relation",+ name: "template", value: "tc-tpl", position: 0, isInheritable: true+ });+ buildNote({ id: "tc-par", "#sorted": "#archived last" });+ new BBranch({ noteId: "tc-chld", parentNoteId: "tc-par", branchId: "tc-par_tc-chld" });+ buildNote({+ id: "tc-par2", "#sorted": "#archived last",+ children: [{ id: "tc-user", "~template": "tc-tpl2" }]+ });++ const archived = addAttribute("tc-tpl", "label", "archived", "");+ eventService.emit(eventService.ENTITY_CHANGED, {+ entityName: "attributes", entity: archived+ });+ expect(sortNotesIfNeeded).toHaveBeenCalledWith("tc-par");+ expect(sortNotesIfNeeded).toHaveBeenCalledWith("tc-par2");+ });+ });+describe("folder re-sorting", () => {it("re-sorts the parents grouping folders when a note gains or loses its only child", () => {// The becca loader removes a deleted branch from its parent's children only once loaded.diff --git a/packages/trilium-core/src/services/handlers.ts b/packages/trilium-core/src/services/handlers.tsindex 230a7514cb..5c639c817d 100644--- a/packages/trilium-core/src/services/handlers.ts+++ b/packages/trilium-core/src/services/handlers.ts@@ -193,13 +193,11 @@ function handleMaybeSortingLabel(entity: BAttribute) {return;}- // An inheritable or template label also applies to the notes that inherit it.- const affectedNotes = entity.isInheritable- ? note.getSubtreeNotesIncludingTemplated()- : note.getInheritingNotes();+ // Covers inherited and chained templates as `invalidateSubTree()` does; for a non-inheritable+ // label it also reaches the subtree, whose parents then keep the order they have.const parentNotes = new Set<BNote>();- for (const affectedNote of affectedNotes) {+ for (const affectedNote of note.getSubtreeNotesIncludingTemplated()) {for (const parentNote of affectedNote.getParentNotes()) {parentNotes.add(parentNote);}