Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/collections/board: fix an issue
Adorian Doran7afee4c94f81
diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsxindex 3498ae5819..a5e6cf9105 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.spec.tsx@@ -148,6 +148,25 @@ describe("PromotedAttributesCard", () => {expect(stored).toEqual([]);});+ /**+ * The collection can change what it draws itself while the card stands: a board is regrouped+ * from its header, and this card lives as long as the board does. The marks follow.+ */+ it("follows what the collection draws when that changes under it", () => {+ settings = [ { name: "owner" }, { name: "dueDate" } ];+ drawnByCollection = [ "owner" ];+ draw();++ expect(locked()).toEqual([ true, false ]);++ drawnByCollection = [ "dueDate" ];+ draw();++ expect(names()).toEqual([ unnamed("owner"), "Due" ]);+ expect(locked()).toEqual([ false, true ]);+ expect(shown()).toEqual([ true, false ]);+ });+it("follows the order the settings give, and turns off what they hide", () => {settings = [ { name: "owner", hidden: true }, { name: "dueDate" } ];draw();diff --git a/apps/client/src/widgets/react/PromotedAttributesCard.tsx b/apps/client/src/widgets/react/PromotedAttributesCard.tsxindex be160e2657..4a610f37cc 100644--- a/apps/client/src/widgets/react/PromotedAttributesCard.tsx+++ b/apps/client/src/widgets/react/PromotedAttributesCard.tsx@@ -66,6 +66,18 @@ export default function PromotedAttributesCard({}: PromotedAttributesCardProps) {const [ shown, setShown ] =useState(() => resolvePromotedAttributes(note, settings, drawnByCollection));+ // What the collection draws can change while the card stands, a board being regrouped from+ // its header. The rows are marked again where they are, keeping their order and what is+ // hidden; the marks are not stored, so nothing is written back for them.+ const drawn = (drawnByCollection ?? []).join(",");+ const [ lastDrawn, setLastDrawn ] = useState(drawn);+ if (lastDrawn !== drawn) {+ setLastDrawn(drawn);+ setShown((was) => was.map((attribute) => ({+ ...attribute,+ drawnByCollection: drawnByCollection?.includes(attribute.name) ?? false+ })));+ }const [ detail, setDetail ] = useState<AttributeDetailOpts | null>(null);/** The definition the editor last reported, which `save` writes. */const edited = useRef<Attribute>();