Skip to content

Build your personal knowledge base with Trilium Notes

test(calendar): relation as custom title with attribute label

Elian Doranf953f6514f8b
diff --git a/src/public/app/entities/fnote.ts b/src/public/app/entities/fnote.ts
index ec200bdfab..eea5a5cc47 100644
--- a/src/public/app/entities/fnote.ts
+++ b/src/public/app/entities/fnote.ts
@@ -330,6 +330,7 @@ class FNote {
// notes/clones cannot form tree cycles, it is possible to create attribute inheritance cycle via templates
// when template instance is a parent of template itself
if (path.includes(this.noteId)) {
+ console.log("Forming a path");
return [];
}
diff --git a/src/public/app/test/easy-froca.ts b/src/public/app/test/easy-froca.ts
index 48dd5f2454..dfc02f1100 100644
--- a/src/public/app/test/easy-froca.ts
+++ b/src/public/app/test/easy-froca.ts
@@ -2,6 +2,7 @@ import utils from "../services/utils.js";
import FNote from "../entities/fnote.js";
import froca from "../services/froca.js";
import FAttribute from "../entities/fattribute.js";
+import noteAttributeCache from "../services/note_attribute_cache.js";
type AttributeDefinitions = { [key in `#${string}`]: string; };
type RelationDefinitions = { [key in `~${string}`]: string; };
@@ -60,7 +61,6 @@ export function buildNotes(notes: NoteDefinition[]) {
}
if (key.startsWith("~")) {
- console.log("Created relation with ", name, value);
attribute = new FAttribute(froca, {
noteId: note.noteId,
attributeId,
@@ -79,6 +79,13 @@ export function buildNotes(notes: NoteDefinition[]) {
froca.attributes[attributeId] = attribute;
note.attributes.push(attributeId);
position++;
+
+ // Inject the attribute into the note attribute cache, since FNote.getAttribute() doesn't always work.
+ // If we add support for templates into froca, this might cause issues.
+ if (!noteAttributeCache.attributes[note.noteId]) {
+ noteAttributeCache.attributes[note.noteId] = [];
+ }
+ noteAttributeCache.attributes[note.noteId].push(attribute);
}
}
diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.ts
index 8c1be2961b..6640d2fb60 100644
--- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts
+++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts
@@ -98,4 +98,17 @@ describe("Building events", () => {
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
});
+ it("supports relation as custom title with custom label", async () => {
+ const noteIds = buildNotes([
+ { id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "#myTitle" },
+ { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },
+ { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },
+ ]);
+ const events = await CalendarView.buildEvents(noteIds);
+
+ expect(events).toHaveLength(2);
+ expect(events[0]).toMatchObject({ title: "My shared custom title", start: "2025-05-05" });
+ expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
+ });
+
});
diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts
index 5f5ffddf89..c970f559d7 100644
--- a/src/public/app/widgets/view_widgets/calendar_view.ts
+++ b/src/public/app/widgets/view_widgets/calendar_view.ts
@@ -419,6 +419,7 @@ export default class CalendarView extends ViewMode {
for (const targetNote of notesFromRelation) {
const targetCustomTitleValue = targetNote.getAttributeValue("label", "calendar:title");
+ console.log("Parse custom title for ", targetNote.noteId, targetNote.getAttributes(), targetNote.getOwnedAttributes());
const targetTitles = await CalendarView.#parseCustomTitle(targetCustomTitleValue, targetNote, false);
titles.push(targetTitles.flat());
}