mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
The /targets page composed everything inline in a 790-line page.tsx.
Break it into focused primitives under src/components/targets/ so the
W3e redesign can iterate per-card without growing the page file:
- target-card.tsx — the redesigned card composition. Headline + verbal
status pill, big-number row with inline trend chevron, range bar,
consistency strip, recency + streak chips (both conditional on real
data), per-card Coach CTA gated by aiEnabled, source link footer.
MOOD_STABILITY swaps the raw σ headline for a verbal label via the
moodStabilityLabel helper. Fixed card order is owned by the page;
this component is presentational.
- range-bar.tsx — extracted intact from page.tsx. Same behaviour, same
data-slot. Now carries its own test suite.
- consistency-strip.tsx — NEW. 7 dots (one per Berlin-tz day), each
filled / amber / red / hollow per the day's band classification.
Caption flips between "X of 7 in range" and "X of 7 logged" when
cadence is the more informative signal. Accessible: <ul role="list">
with per-dot aria-labels seeded from i18n. No empty-state copy
inside the strip — Marc directive: hide entirely when insufficient.
- target-coach-button.tsx — NEW. Per-card "Ask Coach about this" CTA
that returns null when aiEnabled is false. No greyed-out button,
no tooltip placeholder — the gate is total per Marc's
"no broken-button state" directive.
Supporting helpers (each unit-tested):
- src/lib/targets/mood-stability-label.ts — pure σ → verbal-label
threshold logic (< 1.0 stable, < 2.0 variable, ≥ 2.0
highlyVariable). Thresholds documented in the helper and confirmed
in the W3e plan.
- src/lib/ai/coach/target-prompts.ts — 8 metric × 2 locale templates
for the per-card Coach prefill. Falls back to a general template for
glucose contexts. PROMPT_VERSION unchanged (the assistant-facing
prompt does not shift; only user-side prefills do).
- src/lib/ai/coach/target-scope.ts — per-target CoachScope.sources
mapping. Derived metrics (BMI → weight, MOOD_STABILITY → mood) point
at the underlying source; unmapped targets return an empty array
so the drawer falls back to defaults.
i18n keys added: targets.consistency.* (cap + dot aria + relative day
+ insufficient-data), targets.card.{lastMet,streak}, targets.relativeDay.*,
targets.summary.{weekTitle,weekTitleAll,streakHighlight},
targets.coach.cta, targets.mood.stability.* — all EN + DE.
Tests: 17 cases across 5 suites (consistency-strip render variants,
target-coach-button gate branches, range-bar zone painting,
target-card full-data + insufficient-data + aiEnabled-off +
MOOD_STABILITY verbal-headline, mood-stability-label thresholds).
Page.tsx still uses the old inline composition for now — Phase 5
wires it to the new components.
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
/**
|
||
* v1.4.25 W3e — verbal label for the MOOD_STABILITY target headline.
|
||
*
|
||
* The card used to render the raw σ value ("0.42 σ"), which most users
|
||
* cannot interpret. Replace with a three-state verbal label keyed
|
||
* against translation entries `targets.mood.stability.{stable,
|
||
* variable,highlyVariable}`.
|
||
*
|
||
* Thresholds (Marc-set, documented in the W3e implementation plan):
|
||
* σ < 1.0 → "stable" (stabil / stable)
|
||
* σ < 2.0 → "variable" (schwankend / variable)
|
||
* σ ≥ 2.0 → "highly-variable" (sehr schwankend / highly variable)
|
||
*
|
||
* Pure helper so the threshold logic can be unit-tested in isolation
|
||
* without React. Returns the stable English key — callers (the card,
|
||
* the Coach prompt builder) own the locale resolution.
|
||
*/
|
||
export type MoodStabilityLabel = "stable" | "variable" | "highlyVariable";
|
||
|
||
export function moodStabilityLabel(sigma: number): MoodStabilityLabel {
|
||
if (sigma < 1.0) return "stable";
|
||
if (sigma < 2.0) return "variable";
|
||
return "highlyVariable";
|
||
}
|