fix(insights,medications): reconcile review findings on the v1.14.0 surfaces

- Medication cycle status: re-hydrate `nextDueAt` (it arrives as an ISO string
  over the wire) before the Berlin day-bucketing, so "next dose in N days" no
  longer drifts by a day near midnight or off Berlin. Covered by a new
  string-input test.
- Wellness rings: drive the conic sheen off a fixed white so it always lightens
  (a near-black light-mode foreground under overlay was darkening the tile into
  a grey band); give the ring a transform transition so it scales smoothly with
  the tile lift instead of snapping; cap the green-band glow at a few breaths
  instead of an infinite drop-shadow repaint; deepen the light-mode stress and
  recovery end-stops for non-text contrast; track the sm/md column count to the
  active-score count so two or four scores never leave an empty cell.
- Mood factor crosstab: bound the snapshot's cross-metric read to the 365-day
  window and exclude soft-deleted rows, so the factor deltas the model cites
  match the visible board over the same canonical row set (no recency-biased
  truncation, no soft-delete skew); thread the user's source priority so the
  per-day canonical pick agrees with the screen; render the delta neutrally
  rather than green/red, since a higher vital is good for steps but bad for
  resting heart rate and the board is observational.
- Log-intake: surface an error when a pinned slot can't resolve to an instant
  instead of silently logging the dose through the unscheduled path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.8 committed 2026-06-06 00:22:29 +02:00
1 parent dfda2a1c7e
commit 189202f4c6
14 files changed
+110 -28

No files matched your search

@@ -326,6 +326,15 @@ export function WellnessScores({
5: "lg:grid-cols-5",
};
const lgCols = LG_COLS[Math.min(tiles.length, 5)] ?? "lg:grid-cols-5";
// The sm/md row caps at 3 columns; track the actual tile count there too so
// two or four active scores don't leave an empty cell that reads as a
// missing tile (the same fill rule the lg row already follows).
const SM_COLS: Record<number, string> = {
1: "sm:grid-cols-1",
2: "sm:grid-cols-2",
3: "sm:grid-cols-3",
};
const smCols = SM_COLS[Math.min(tiles.length, 3)] ?? "sm:grid-cols-3";
return (
<section
@@ -342,7 +351,7 @@ export function WellnessScores({
// `data-revealed` triggers the CSS tile-rise + sheen keyframes on the
// fresh-session reveal; absent on subsequent mounts (paint final).
data-revealed={play ? "true" : undefined}
className={cn("grid grid-cols-2 gap-3 sm:grid-cols-3", lgCols)}
className={cn("grid grid-cols-2 gap-3", smCols, lgCols)}
>
{tiles}
</div>
@@ -106,11 +106,14 @@ export function MoodFactorMetricCrosstab({
METRIC_LABEL_KEY[row.metricKey] ?? row.metricKey,
);
const unit = t(UNIT_KEY[row.display]);
// `delta` = lowAvg − highAvg: negative = vital runs lower on the
// low-factor (worse) days. The read-out is colored by sign.
// `delta` = lowAvg − highAvg: positive = the vital runs higher on the
// low-factor (worse) days. The number stays NEUTRAL — a higher value
// is good for steps but bad for resting HR, and this board is
// observational ("associations, not causes"), so colouring it
// green/red would imply a health verdict the data doesn't support.
// The sign prefix + `data-direction` carry the direction.
const up = row.delta >= 0;
const deltaText = `${up ? "+" : ""}${fmt(row.delta, row.display)} ${unit}`;
const deltaColor = up ? "var(--success)" : "var(--destructive)";
return (
<li
key={`${row.metricKey}:${row.factor}`}
@@ -136,10 +139,7 @@ export function MoodFactorMetricCrosstab({
metric: metricLabel,
})}
</span>
<span
className="shrink-0 text-sm font-semibold tabular-nums"
style={{ color: deltaColor }}
>
<span className="text-foreground shrink-0 text-sm font-semibold tabular-nums">
{deltaText}
</span>
<span
@@ -213,6 +213,19 @@ describe("medication cycle status — open-cycle line", () => {
expect(html).toContain("lucide-circle-check");
});
it("on_track reads the same day count when nextDueAt arrives as an ISO string", () => {
// Over the wire `nextDueAt` is JSON, so it reaches the card as a string
// even though the type says `Date`. The component must re-hydrate it for
// the Berlin day-bucketing — a raw string would silently drift the count.
const iso = inDays(4).toISOString() as unknown as Date;
const html = render(
<MedicationCycleStatus
cycle={{ ...baseCycle, state: "on_track", nextDueAt: iso }}
/>,
);
expect(html).toContain("Next dose in 4 days");
});
it("on_track one day out reads tomorrow", () => {
const html = render(
<MedicationCycleStatus
@@ -78,8 +78,12 @@ export function MedicationCycleStatus({ cycle }: MedicationCycleStatusProps) {
tone = "text-success";
icon = <CircleCheck className="size-3.5 shrink-0" aria-hidden="true" />;
const now = new Date();
// `nextDueAt` is typed `Date` but arrives as an ISO string over the wire;
// re-hydrate it so the Berlin day-bucketing (toLocaleString with a
// timeZone) actually applies — a raw string would silently skip it and
// drift the count by a day near midnight / off Berlin.
const days = cycle.nextDueAt
? calendarDayDelta(cycle.nextDueAt, now)
? calendarDayDelta(new Date(cycle.nextDueAt), now)
: null;
if (days === null || days <= 0) {
// on_track with the slot today (now < dueAt but same calendar day).
@@ -22,6 +22,7 @@
import { useMemo, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { Loader2 } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import {
@@ -144,10 +145,20 @@ export function LogIntakeDialog({
if (!medicationId || busy) return;
const med = medications.find((m) => m.id === medicationId);
if (!med) return;
// A pinned slot must resolve to a real instant; if it can't, surface an
// error rather than silently logging the dose through the unscheduled path
// (which would miss the canonical slot upsert and could duplicate the row).
let scheduledFor: string | undefined;
if (slot !== NO_SLOT) {
const iso = slotInstantIso(takenAt, slot);
if (!iso) {
toast.error(t("medications.logIntake.slotError"));
return;
}
scheduledFor = iso;
}
setBusy(true);
try {
const scheduledFor =
slot !== NO_SLOT ? (slotInstantIso(takenAt, slot) ?? undefined) : undefined;
const ok = await runLogIntake({
medication: { id: med.id, name: med.name },
skipped,