From f76f679800c9ff3e0a0a9933d0e4a4ba799c99c8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 28 Feb 2025 20:45:23 +0200 Subject: [PATCH] feat(calendar): allow relations in promoted attributes --- .../widgets/view_widgets/calendar_view.spec.ts | 17 +++++++++++++++++ .../app/widgets/view_widgets/calendar_view.ts | 13 +++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) 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 c512a4d56..9623f0172 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts @@ -145,4 +145,21 @@ describe("Promoted attributes", () => { Mood: "happy" }) }); + + it("supports relations", async () => { + const note = buildNote({ + "title": "Hello", + "~assignee": buildNote({ + "title": "Target note" + }).noteId, + "#calendar:promotedAttributes": "relation:assignee", + "#relation:assignee": "promoted,alias=Assignee,single,text", + }); + + const event = await CalendarView.buildEvent(note, "2025-04-04"); + expect(event).toHaveLength(1); + expect(event[0]?.promotedAttributes).toMatchObject({ + "Assignee": "Target note" + }) + }); }); diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index 512d5a650..e38f95690 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -378,8 +378,6 @@ export default class CalendarView extends ViewMode { const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name)); const result: Record = {}; - console.log("Got promoted attributes ", promotedAttributeNames, filteredPromotedAttributes); - for (const promotedAttribute of filteredPromotedAttributes) { const [ type, name ] = promotedAttribute.name.split(":", 2); const definition = promotedAttribute.getDefinition(); @@ -389,12 +387,15 @@ export default class CalendarView extends ViewMode { continue; } - // TODO: Add support for relations - if (type !== "label" || !note.hasLabel(name)) { - continue; + let value: string | undefined | null = null; + + if (type === "label" && note.hasLabel(name)) { + value = note.getLabelValue(name); + } else if (type === "relation" && note.hasRelation(name)) { + const targetNote = await note.getRelationTarget(name); + value = targetNote?.title; } - const value = note.getLabelValue(name); const friendlyName = definition.promotedAlias ?? name; if (friendlyName && value) { result[friendlyName] = value;