diff --git a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx
index 3b90dc3d2..987647519 100644
--- a/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx
+++ b/apps/client/src/widgets/attribute_widgets/PromotedAttributesDisplay.tsx
@@ -5,7 +5,7 @@ import { useTriliumEvent } from "../react/hooks";
import attributes from "../../services/attributes";
import { DefinitionObject } from "../../services/promoted_attribute_definition_parser";
import { formatDateTime } from "../../utils/formatters";
-import { ComponentChildren, CSSProperties } from "preact";
+import { ComponentChild, ComponentChildren, CSSProperties } from "preact";
import Icon from "../react/Icon";
import NoteLink from "../react/NoteLink";
import { getReadableTextColor } from "../../services/css_class_manager";
@@ -56,39 +56,53 @@ function PromotedAttribute({ attr, children, style }: { attr: AttributeWithDefin
}
function buildPromotedAttribute(attr: AttributeWithDefinitions): ComponentChildren {
- if (attr.type === "relation") {
- return {attr.friendlyName}:
+ const defaultLabel = <>{attr.friendlyName}:{" "}>;
+ let content: ComponentChildren;
+ let style: CSSProperties | undefined;
+
+ if (attr.type === "label") {
+ let value = attr.value;
+ switch (attr.def.labelType) {
+ case "number":
+ let formattedValue = value;
+ const numberValue = Number(value);
+ if (!Number.isNaN(numberValue) && attr.def.numberPrecision) formattedValue = numberValue.toFixed(attr.def.numberPrecision);
+ content = <>{defaultLabel}{formattedValue}>;
+ break;
+ case "date":
+ case "datetime": {
+ const date = new Date(value);
+ const timeFormat = attr.def.labelType !== "date" ? "short" : "none";
+ const formattedValue = formatDateTime(date, "short", timeFormat);
+ content = <>{defaultLabel}{formattedValue}>;
+ break;
+ }
+ case "time": {
+ const date = new Date(`1970-01-01T${value}Z`);
+ const formattedValue = formatDateTime(date, "none", "short");
+ content = <>{defaultLabel}{formattedValue}>;
+ break;
+ }
+ case "boolean":
+ content = <>{" "}{attr.friendlyName}>;
+ break;
+ case "url":
+ content = {attr.friendlyName};
+ break;
+ case "color":
+ style = { backgroundColor: value, color: getReadableTextColor(value) };
+ content = <>{attr.friendlyName}>;
+ break;
+ case "text":
+ default:
+ content = <>{defaultLabel}{value}>;
+ break;
+ }
+ } else if (attr.type === "relation") {
+ content = <>{defaultLabel}>;
}
- let value = attr.value;
- switch (attr.def.labelType) {
- case "number":
- let formattedValue = value;
- const numberValue = Number(value);
- if (attr.def.numberPrecision) {
- formattedValue = numberValue.toFixed(attr.def.numberPrecision);
- }
- return {attr.friendlyName}: {formattedValue};
- case "date":
- case "datetime": {
- const date = new Date(value);
- const timeFormat = attr.def.labelType !== "date" ? "short" : "none";
- return {attr.friendlyName}: {formatDateTime(date, "short", timeFormat)};
- }
- case "time": {
- const date = new Date(`1970-01-01T${value}Z`);
- return {attr.friendlyName}: {formatDateTime(date, "none", "short")};
- }
- case "boolean":
- return {attr.friendlyName};
- case "url":
- return {attr.friendlyName};
- case "color":
- return {attr.friendlyName};
- case "text":
- default:
- return {attr.friendlyName}: {value};
- }
+ return {content}
}
function getAttributesWithDefinitions(note: FNote, attributesToIgnore: string[] = []): AttributeWithDefinitions[] {