Skip to content

Build your personal knowledge base with Trilium Notes

fix(calendar): call a chip's field what its definition calls it

Elian Doranb4e4980f575a
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
index d477d8b6a1..6d8cfed4f6 100644
--- a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
+++ b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts
@@ -143,8 +143,11 @@ describe("Promoted attributes", () => {
const event = await buildEvent(note, { startDate: "2025-04-04" });
expect(event).toHaveLength(1);
expect(event[0]?.promotedAttributes).toMatchObject([
+ // No alias to go by, so the label says itself.
[ "weight", "75" ],
- [ "mood", "happy" ]
+ // Named as the definition names it, which is how the note's own promoted field is
+ // labelled — the chip would otherwise say the same value under a second name.
+ [ "Mood", "happy" ]
]);
});
@@ -161,7 +164,20 @@ describe("Promoted attributes", () => {
const event = await buildEvent(note, { startDate: "2025-04-04" });
expect(event).toHaveLength(1);
expect(event[0]?.promotedAttributes).toMatchObject([
- [ "assignee", "Target note" ]
+ [ "Assignee", "Target note" ]
+ ]);
+ });
+
+ it("says an attribute nobody defined by its own name, promotion being no condition of showing one", async () => {
+ const note = buildNote({
+ title: "Hello",
+ "#mood": "happy",
+ "#calendar:displayedAttributes": "mood"
+ });
+
+ const event = await buildEvent(note, { startDate: "2025-04-04" });
+ expect(event[0]?.promotedAttributes).toMatchObject([
+ [ "mood", "happy" ]
]);
});
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.ts b/apps/client/src/widgets/collections/calendar/event_builder.ts
index 5ecdf6f6a3..cec3ef745d 100644
--- a/apps/client/src/widgets/collections/calendar/event_builder.ts
+++ b/apps/client/src/widgets/collections/calendar/event_builder.ts
@@ -3,6 +3,7 @@ import clsx from "clsx";
import { EventInput, EventSourceFuncInfo, EventSourceInput } from "fullcalendar";
import * as rruleLib from 'rrule';
+import FAttribute from "../../../entities/fattribute";
import FNote from "../../../entities/fnote";
import froca from "../../../services/froca";
import server from "../../../services/server";
@@ -227,9 +228,24 @@ async function buildDisplayedAttributes(note: FNote, calendarDisplayedAttributes
const result: Array<[string, string]> = [];
for (const attribute of filteredDisplayedAttributes) {
- if (attribute.type === "label") result.push([attribute.name, attribute.value]);
- else result.push([attribute.name, (await attribute.getTargetNote())?.title || ""]);
+ const name = displayedAttributeName(note, attribute);
+ if (attribute.type === "label") result.push([name, attribute.value]);
+ else result.push([name, (await attribute.getTargetNote())?.title || ""]);
}
return result;
}
+
+/**
+ * What a field is called on the chip: the alias its definition gives it, and the attribute's own
+ * name where no definition gives one.
+ *
+ * Both halves are needed. The alias is the name the reader chose — the promoted field in the note
+ * itself is labelled by it, and a chip saying something else is the same value under two names. The
+ * fallback is what lets the calendar go on showing an attribute that was never promoted, which is
+ * the whole point of `#calendar:displayedAttributes` naming attributes rather than definitions.
+ */
+function displayedAttributeName(note: FNote, attribute: FAttribute) {
+ const definition = note.getAttribute("label", `${attribute.type}:${attribute.name}`);
+ return definition?.getDefinition().promotedAlias || attribute.name;
+}