Files
HealthLog/src/components/charts/mini-window.ts
T
Marc-André BombeckandClaude Opus 4.7 7f54c0cad3 feat(charts): mini-mode + windowOverride prop for embedded rationale charts
The Oura-style RecommendationCard (B5c) embeds a small chart pinned
to the recommendation's rationale.dataWindow. HealthChart gains two
opt-in props:

  - mini: drops the range tabs, the moving-average / trend / target-
    band toggle row, and shrinks padding (h-[140px] vs h-[240px]).
    Tooltip + gradient + personal-baseline behaviour stay intact so
    the small chart still tells the same visual story.

  - windowOverride: pins the rangePoints state to the rationale enum
    value (last7days / last30days / last90days / allTime) regardless
    of any parent UI state. Mini mode hides the range tabs anyway,
    so the user can't manually override the pinned window.

The pure helper resolveMiniRangePoints() (`mini-window.ts`) maps the
rationale enum onto the existing per-points TIME_RANGES_KEYS values.
Single source of truth so future schema changes touch one file.

7 new tests in `health-chart-mini.test.tsx` pin the contract:
- enum-to-points mapping for all 4 windows
- mini mode hides toggles + range tabs
- non-mini mode still renders them (regression guard)
- windowOverride seeds the rangePoints state on mount

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 01:17:15 +02:00

39 lines
1.1 KiB
TypeScript

/**
* v1.4.16 phase B5c — shared chart-mini window vocabulary.
*
* The Oura-style RecommendationCard (B5c) embeds a mini-chart that
* pins to the recommendation's `rationale.dataWindow`. This helper
* maps the rationale enum onto the per-points range used by the
* existing chart wrappers.
*
* last7days → 7 points
* last30days → 30 points
* last90days → 90 points
* allTime → 0 (HealthChart treats 0 as "no slice — show all")
*
* The values mirror the existing `TIME_RANGES_KEYS` definition in
* `health-chart.tsx`; the helper is a pure function so unit tests
* pin the contract without depending on Recharts internals.
*/
export type DataWindow =
| "last7days"
| "last30days"
| "last90days"
| "allTime";
const POINTS_BY_WINDOW: Record<DataWindow, number> = {
last7days: 7,
last30days: 30,
last90days: 90,
allTime: 0,
};
/**
* Returns the per-points range value the chart wrapper expects for a
* given rationale dataWindow enum value.
*/
export function resolveMiniRangePoints(window: DataWindow): number {
return POINTS_BY_WINDOW[window];
}