From b11b3ff67f9e6c5476dce462e83d4a4be59b5680 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 12 Nov 2025 19:57:18 +0200 Subject: [PATCH] refactor(board): use hook for obtaining the list of attributes --- .../PromotedAttributesDisplay.tsx | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx index 6c8b257e8..007511217 100644 --- a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx +++ b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx @@ -6,22 +6,23 @@ interface PromotedAttributesDisplayProps { ignoredAttributes?: string[]; } -export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) { - const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes(); +interface AttributeWithDefinitions { + name: string; + type: string; + friendlyName: string; + value: string; +} - return promotedDefinitionAttributes.length > 0 && ( +export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) { + const promotedDefinitionAttributes = useNoteAttributesWithDefinitions(note); + return promotedDefinitionAttributes?.length > 0 && (
- {promotedDefinitionAttributes.map((attr) => { - const def = attr.getDefinition(); - const [ type, name ] = attr.name.split(":", 2); - const value = note.getLabelValue(name); - const friendlyName = def?.promotedAlias ?? name; - if (!value) return null; - if (ignoredAttributes && ignoredAttributes.includes(name)) return null; + {promotedDefinitionAttributes?.map((attr) => { + if (ignoredAttributes && ignoredAttributes.includes(attr.name)) return null; return ( - - {friendlyName}: {value} + + {attr.friendlyName}: {attr.value} ); } @@ -30,3 +31,19 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P ) } + +function useNoteAttributesWithDefinitions(note: FNote) { + const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes(); + const result: AttributeWithDefinitions[] = []; + + for (const attr of promotedDefinitionAttributes) { + const def = attr.getDefinition(); + const [ type, name ] = attr.name.split(":", 2); + const value = note.getLabelValue(name); + const friendlyName = def?.promotedAlias ?? name; + if (!value) continue; + + result.push({ name, type, friendlyName, value }); + } + return result; +}