Skip to content

Commit d79a23b

Browse files
committed
feat(board/promoted_attributes): format boolean
1 parent 3015576 commit d79a23b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useTriliumEvent } from "../react/hooks";
55
import attributes from "../../services/attributes";
66
import { DefinitionObject } from "../../services/promoted_attribute_definition_parser";
77
import { formatDateTime } from "../../utils/formatters";
8+
import { ComponentChildren } from "preact";
9+
import Icon from "../react/Icon";
810

911
interface PromotedAttributesDisplayProps {
1012
note: FNote;
@@ -26,7 +28,7 @@ export default function PromotedAttributesDisplay({ note, ignoredAttributes }: P
2628
{promotedDefinitionAttributes?.map((attr) => {
2729
return (
2830
<span key={attr.friendlyName} className="promoted-attribute">
29-
<strong>{attr.friendlyName}:</strong> {formatLabelValue(attr)}
31+
{formatLabelValue(attr)}
3032
</span>
3133
);
3234
}
@@ -48,25 +50,27 @@ function useNoteAttributesWithDefinitions(note: FNote, attributesToIgnore: stri
4850
return promotedDefinitionAttributes;
4951
}
5052

51-
function formatLabelValue(attr: AttributeWithDefinitions): string {
53+
function formatLabelValue(attr: AttributeWithDefinitions): ComponentChildren {
5254
let value = attr.value;
5355
switch (attr.def.labelType) {
5456
case "number":
57+
let formattedValue = value;
5558
const numberValue = Number(value);
5659
if (attr.def.numberPrecision) {
57-
return numberValue.toFixed(attr.def.numberPrecision);
58-
} else {
59-
return numberValue.toString();
60+
formattedValue = numberValue.toFixed(attr.def.numberPrecision);
6061
}
62+
return <><strong>{attr.friendlyName}:</strong> {formattedValue}</>;
6163
case "date":
6264
case "datetime":
6365
const date = new Date(value);
6466
if (isNaN(date.getTime())) return value;
6567
const timeFormat = attr.def.labelType === "datetime" ? "short" : "none";
66-
return formatDateTime(date, "short", timeFormat);
68+
return <><strong>{attr.friendlyName}:</strong> {formatDateTime(date, "short", timeFormat)}</>;
69+
case "boolean":
70+
return <><Icon icon={value === "true" ? "bx bx-check-square" : "bx bx-square"} /> <strong>{attr.friendlyName}</strong></>;
6771
case "text":
6872
default:
69-
return value;
73+
return <><strong>{attr.friendlyName}:</strong> {value}</>;
7074
}
7175
}
7276

0 commit comments

Comments
 (0)