feat(board/promoted_attributes): format boolean

This commit is contained in:
Elian Doran 2025-11-12 20:42:30 +02:00
parent 3015576d7e
commit d79a23bc9e
No known key found for this signature in database

View File

@ -5,6 +5,8 @@ import { useTriliumEvent } from "../react/hooks";
import attributes from "../../services/attributes"; import attributes from "../../services/attributes";
import { DefinitionObject } from "../../services/promoted_attribute_definition_parser"; import { DefinitionObject } from "../../services/promoted_attribute_definition_parser";
import { formatDateTime } from "../../utils/formatters"; import { formatDateTime } from "../../utils/formatters";
import { ComponentChildren } from "preact";
import Icon from "../react/Icon";
interface PromotedAttributesDisplayProps { interface PromotedAttributesDisplayProps {
note: FNote; note: FNote;
@ -26,7 +28,7 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P
{promotedDefinitionAttributes?.map((attr) => { {promotedDefinitionAttributes?.map((attr) => {
return ( return (
<span key={attr.friendlyName} className="promoted-attribute"> <span key={attr.friendlyName} className="promoted-attribute">
<strong>{attr.friendlyName}:</strong> {formatLabelValue(attr)} {formatLabelValue(attr)}
</span> </span>
); );
} }
@ -48,25 +50,27 @@ function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: stri
return promotedDefinitionAttributes; return promotedDefinitionAttributes;
} }
function formatLabelValue(attr: AttributeWithDefinitions): string { function formatLabelValue(attr: AttributeWithDefinitions): ComponentChildren {
let value = attr.value; let value = attr.value;
switch (attr.def.labelType) { switch (attr.def.labelType) {
case "number": case "number":
let formattedValue = value;
const numberValue = Number(value); const numberValue = Number(value);
if (attr.def.numberPrecision) { if (attr.def.numberPrecision) {
return numberValue.toFixed(attr.def.numberPrecision); formattedValue = numberValue.toFixed(attr.def.numberPrecision);
} else {
return numberValue.toString();
} }
return <><strong>{attr.friendlyName}:</strong> {formattedValue}</>;
case "date": case "date":
case "datetime": case "datetime":
const date = new Date(value); const date = new Date(value);
if (isNaN(date.getTime())) return value; if (isNaN(date.getTime())) return value;
const timeFormat = attr.def.labelType === "datetime" ? "short" : "none"; const timeFormat = attr.def.labelType === "datetime" ? "short" : "none";
return formatDateTime(date, "short", timeFormat); return <><strong>{attr.friendlyName}:</strong> {formatDateTime(date, "short", timeFormat)}</>;
case "boolean":
return <><Icon icon={value === "true" ? "bx bx-check-square" : "bx bx-square"} /> <strong>{attr.friendlyName}</strong></>;
case "text": case "text":
default: default:
return value; return <><strong>{attr.friendlyName}:</strong> {value}</>;
} }
} }