Skip to content

Build your personal knowledge base with Trilium Notes

fix(board): list the attributes of a card that joins while Board Properties is open

Elian Doran37dd2508851b
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
index bb69d2a009..0b8655f613 100644
--- a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
+++ b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx
@@ -201,6 +201,27 @@ describe("PromotedAttributesCard", () => {
expect(stored.at(-1)?.[2]).toMatchObject({ name: "project", hidden: true });
});
+ /**
+ * A card that joins the board through a branch change, such as a sync, brings no attribute row,
+ * so the new `itemNotes` alone must add its definitions.
+ */
+ it("lists what a newly shown item defines, keeping the order and what is hidden", () => {
+ settings = [ { name: "owner" }, { name: "dueDate", hidden: true } ];
+ itemNotes = [];
+ draw();
+
+ itemNotes = [ {
+ noteId: "task1",
+ getAttributeDefinitions: () => [
+ { ...definition("label:project", { alias: "Project" }), noteId: "template1" }
+ ]
+ } as unknown as FNote ];
+ draw();
+
+ expect(names()).toEqual([ unnamed("owner"), "Due", "Project" ]);
+ expect(shown()).toEqual([ true, false, true ]);
+ });
+
it("reports the whole list in its new order", () => {
draw();
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.tsx
index fa8e226a66..5a8865fe73 100644
--- a/apps/client/src/widgets/react/PromotedAttributesCard.tsx
+++ b/apps/client/src/widgets/react/PromotedAttributesCard.tsx
@@ -83,6 +83,15 @@ export default function PromotedAttributesCard({
drawnByCollection: drawnByCollection?.includes(attribute.name) ?? false
})));
}
+ // A card that joins through a branch change brings no attribute row for `entitiesReloaded`, so
+ // the list is resolved again when the definition names of `itemNotes` change.
+ const itemDefinitions = definitionNames(itemNotes);
+ const [ lastItemDefinitions, setLastItemDefinitions ] = useState(itemDefinitions);
+ if (lastItemDefinitions !== itemDefinitions) {
+ setLastItemDefinitions(itemDefinitions);
+ setShown((was) => resolvePromotedAttributes(
+ note, storedPromotedAttributes(was), drawnByCollection, itemNotes));
+ }
const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);
/** The definition the editor last reported, which `save` writes. */
const edited = useRef<Attribute>();
@@ -299,6 +308,17 @@ export default function PromotedAttributesCard({
);
}
+/** Returns the definition names of `notes`, sorted and joined, for comparing between renders. */
+function definitionNames(notes: Iterable<FNote> | undefined) {
+ const names = new Set<string>();
+ for (const note of notes ?? []) {
+ for (const definition of note.getAttributeDefinitions()) {
+ names.add(definition.name);
+ }
+ }
+ return [ ...names ].sort().join(",");
+}
+
/** The kind entry for an attribute: its `labelType`, or the relation kind for a relation. */
function promotedAttributeType(attribute: PromotedAttribute) {
const kind = attribute.type === "relation"