refactor(insights): consolidate relative-time and confidence-band tables

Three live byte-identical formatRelativeTime copies (hero-strip,
daily-briefing, coach history-rail) lifted to src/lib/i18n/relative-
time.ts. Both correlation-card and trend-annotation duplicated the
exact same low/moderate/high Dracula classnames; extracted to
src/components/insights/confidence-badge.ts (per-component i18n
labels stay local — the copy differs).

Drop the dead "null" placeholder branch in useCoachConversation's
queryKey: the ternary picked a different key when id was null, but
enabled: id !== null kept the query disabled so the placeholder never
fired. Key directly on id.

Hoist STORYBOARD_COLOR_BY_CATEGORY in /insights/page.tsx to module
scope so the map isn't recreated on every render.

Fixes Simplify-S-02, Simplify-S-03, Simplify-S-04, Simplify-S-05,
Code-LOW-02.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.7 committed 2026-05-10 18:09:45 +02:00
1 parent cfe6d1c577
commit 340239423b
9 files changed
+66 -84

No files matched your search

+13 -8
View File
@@ -518,6 +518,16 @@ function getMedicationComplianceSectionStatus(input: {
};
}
// v1.4.20 phase D reconcile — module-scope so the map isn't recreated
// on every render of `<InsightsPage>` (the page renders often on
// TanStack-Query refetches; this map carries no closures over locals).
const STORYBOARD_COLOR_BY_CATEGORY: Record<string, string> = {
medication: "var(--dracula-pink)",
event: "var(--dracula-cyan)",
milestone: "var(--dracula-green)",
warning: "var(--dracula-orange)",
};
export default function InsightsPage() {
const { isAuthenticated, user } = useAuth();
const { t, locale } = useTranslations();
@@ -915,14 +925,9 @@ export default function InsightsPage() {
// v1.4.20 phase B4 — storyboard annotations for the 90-day BP chart.
// The advisor payload may carry up to 20 entries; we transform them
// into the {date, label, color} shape <HealthChart> consumes. The
// colour map mirrors the four canonical categories. Cached payloads
// from before PROMPT_VERSION 4.20.2 simply produce an empty array.
const STORYBOARD_COLOR_BY_CATEGORY: Record<string, string> = {
medication: "var(--dracula-pink)",
event: "var(--dracula-cyan)",
milestone: "var(--dracula-green)",
warning: "var(--dracula-orange)",
};
// colour map mirrors the four canonical categories (hoisted to
// module scope above). Cached payloads from before PROMPT_VERSION
// 4.20.2 simply produce an empty array.
const rawStoryboard = (
advisor.payload?.insights as
| { storyboardAnnotations?: Array<{