From 46c2e162f07ff4074e3c17c61a375a972d052efa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 12 Nov 2025 20:31:27 +0200 Subject: [PATCH] feat(board/promoted_attributes): format number with precision --- .../PromotedAttributesDisplay.tsx | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx index 01dfa908d..761a0bb3b 100644 --- a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx +++ b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx @@ -3,6 +3,7 @@ import FNote from "../../entities/fnote"; import "./PromotedAttributesDisplay.css"; import { useTriliumEvent } from "../react/hooks"; import attributes from "../../services/attributes"; +import { DefinitionObject } from "../../services/promoted_attribute_definition_parser"; interface PromotedAttributesDisplayProps { note: FNote; @@ -10,10 +11,11 @@ interface PromotedAttributesDisplayProps { } interface AttributeWithDefinitions { + friendlyName: string; name: string; type: string; - friendlyName: string; value: string; + def: DefinitionObject; } export default function PromotedAttributesDisplay({ note, ignoredAttributes }: PromotedAttributesDisplayProps) { @@ -23,7 +25,7 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P {promotedDefinitionAttributes?.map((attr) => { return ( - {attr.friendlyName}: {attr.value} + {attr.friendlyName}: {formatLabelValue(attr)} ); } @@ -45,6 +47,22 @@ function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: stri return promotedDefinitionAttributes; } +function formatLabelValue(attr: AttributeWithDefinitions): string { + let value = attr.value; + switch (attr.def.labelType) { + case "number": + const numberValue = Number(value); + if (attr.def.numberPrecision) { + return numberValue.toFixed(attr.def.numberPrecision); + } else { + return numberValue.toString(); + } + case "text": + default: + return value; + } +} + function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] { const promotedDefinitionAttributes = note.getPromotedDefinitionAttributes(); const result: AttributeWithDefinitions[] = []; @@ -56,7 +74,7 @@ function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] if (!value) continue; if (attributesToIgnore.includes(name)) continue; - result.push({ name, type, friendlyName, value }); + result.push({ def, name, type, value, friendlyName }); } return result; }