fix(measurements): drop the bare separator before a unitless row's date

A score or a rating has no unit word, but the phone row still appended
the separator, so its meta line opened with a stray dot.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 22:57:47 +02:00
1 parent dcbd564962
commit 798fae747f
3 files changed
+43 -13

No files matched your search

@@ -5,6 +5,7 @@ import {
MEASUREMENT_TYPE_ICONS,
MEASUREMENT_TYPE_COLORS,
measurementUnitLabel,
measurementUnitMetaLead,
} from "../measurement-list-meta";
import enMessages from "../../../../messages/en.json";
import deMessages from "../../../../messages/de.json";
@@ -61,3 +62,14 @@ describe("measurementUnitLabel", () => {
expect(measurementUnitLabel("VISCERAL_FAT", "rating", t)).toBe("");
});
});
describe("measurementUnitMetaLead", () => {
const t = (key: string) => `t:${key}`;
it("leads the meta line with the unit and its separator", () => {
expect(measurementUnitMetaLead("WEIGHT", "kg", t)).toBe("kg · ");
});
it("leaves no bare separator for a score or a rating", () => {
expect(measurementUnitMetaLead("PHQ9_SCORE", "score", t)).toBeNull();
expect(measurementUnitMetaLead("VISCERAL_FAT", "rating", t)).toBeNull();
});
});
@@ -425,3 +425,17 @@ export function measurementUnitLabel(
}
const UNITLESS_TOKENS: ReadonlySet<string> = new Set(["score", "rating"]);
/**
* The unit as the lead of a row's meta line ("kg · 2 days ago"), or null
* when the row has no unit word to show: a score or a rating would otherwise
* open the line with a bare separator.
*/
export function measurementUnitMetaLead(
type: string,
unit: string,
t: (key: string) => string,
): string | null {
const label = measurementUnitLabel(type, unit, t);
return label ? `${label} · ` : null;
}
@@ -105,6 +105,7 @@ import {
MEASUREMENT_TYPE_ICONS as TYPE_ICONS,
MEASUREMENT_TYPE_COLORS as TYPE_COLORS,
measurementUnitLabel,
measurementUnitMetaLead,
} from "./measurement-list-meta";
import {
measurementListFiltersToSearch,
@@ -1537,19 +1538,22 @@ export function MeasurementList({
one ("Atemzüge/min") beside the value pushed
the row's controls; it leads the meta line
instead. Sleep reads as a duration. */}
{isSleep ? null : (
<span
data-slot="measurement-row-unit"
className="whitespace-nowrap"
>
{measurementUnitLabel(
m.type,
isGrouped ? m.unit : rowDisplay(m).unit,
t,
)}
{" · "}
</span>
)}
{(() => {
if (isSleep) return null;
const lead = measurementUnitMetaLead(
m.type,
isGrouped ? m.unit : rowDisplay(m).unit,
t,
);
return lead ? (
<span
data-slot="measurement-row-unit"
className="whitespace-nowrap"
>
{lead}
</span>
) : null;
})()}
{m.dayKey !== undefined ? (
<DayLink
date={m.dayKey}