mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
test(calendar): relation as custom title with attribute label
This commit is contained in:
parent
ca7cff45c9
commit
f953f6514f
@ -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 [];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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" });
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user