Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doran404e2dffc336
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index cf4333e04b..7e7e40bcaa 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -1696,11 +1696,11 @@ describe("Board column rename", () => {
});
/** An attribute change as the server reports one: the row is tracked as well as carried. */
- function attributeChanged(name: string) {
+ function attributeChanged(name: string, noteId = "someNote") {
const results = new LoadResults([ {
entityName: "attributes",
entityId: "attr1",
- entity: { attributeId: "attr1", noteId: "someNote", type: "label", name }
+ entity: { attributeId: "attr1", noteId, type: "label", name }
} as never ]);
results.addAttribute("attr1", "other");
return results;
@@ -2303,6 +2303,46 @@ describe("Board column rename", () => {
expect(templateReads).toBe(before + 1);
});
+ /**
+ * A template's icon is what the picker and the pill show, and an icon is a label on the note
+ * rather than part of the note row: the change is reported as an attribute changing, which is
+ * not what a reloaded note reads as. Only the notes the board offers are watched for it.
+ */
+ it("reads the templates again when one it offers is given another icon", async () => {
+ const reading = vi.mocked(getNoteTypeOptions);
+ const stockAnswer = reading.getMockImplementation();
+ const template = {
+ id: "template:tmpl1",
+ title: "My template",
+ icon: "bx bx-star",
+ group: "user",
+ options: { type: "text", mime: "text/html", templateNoteId: "tmpl1" }
+ } as NoteTypeOption;
+ reading.mockImplementation(async () => [ ...NOTE_TYPE_OPTIONS, template ]);
+
+ try {
+ const { host } = await setup();
+ const before = reading.mock.calls.length;
+
+ // An icon given to a note the board offers nothing from is not its business.
+ await act(async () => {
+ await host.handleEvent("entitiesReloaded",
+ { loadResults: attributeChanged("iconClass") });
+ await flush();
+ });
+ expect(reading.mock.calls.length).toBe(before);
+
+ await act(async () => {
+ await host.handleEvent("entitiesReloaded",
+ { loadResults: attributeChanged("iconClass", "tmpl1") });
+ await flush();
+ });
+ expect(reading.mock.calls.length).toBe(before + 1);
+ } finally {
+ reading.mockImplementation(stockAnswer ?? (async () => NOTE_TYPE_OPTIONS));
+ }
+ });
+
/**
* Two reads can be in flight at once: the one the board makes as it arrives, and one a template
* being made or deleted asks for. The server need not answer in the order it was asked, so the
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index c76b874b72..df2808a374 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -294,8 +294,16 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
// one deleted would go on being offered until the board was drawn afresh. A template is a note
// carrying `#template`, and its title and icon are what the picker shows.
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- const templated = loadResults.getAttributeRows()
- .some((attribute) => attribute.name === "template");
+ const offered = new Set(availableTemplates
+ .map((option) => option.options.templateNoteId)
+ .filter((noteId) => !!noteId));
+ // A note taking `#template` or losing it changes what a card can be made from, and so does
+ // the icon of one already offered. An icon is a label rather than part of the note row, so
+ // a change to one is reported as the attribute changing and not as the note reloading.
+ const templated = loadResults.getAttributeRows().some((attribute) =>
+ attribute.name === "template"
+ || (attribute.name === "iconClass" && !!attribute.noteId
+ && offered.has(attribute.noteId)));
const renamed = availableTemplates.some((option) =>
option.options.templateNoteId
&& loadResults.isNoteReloaded(option.options.templateNoteId));