feat(calendar): allow relations in promoted attributes

This commit is contained in:
Elian Doran 2025-02-28 20:45:23 +02:00
parent e7d06fceba
commit f76f679800
No known key found for this signature in database
2 changed files with 24 additions and 6 deletions

View File

@ -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"
})
});
});

View File

@ -378,8 +378,6 @@ export default class CalendarView extends ViewMode {
const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name));
const result: Record<string, string> = {};
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;