mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
feat(calendar): allow relations in promoted attributes
This commit is contained in:
parent
e7d06fceba
commit
f76f679800
@ -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"
|
||||
})
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user