From d4796ee0b155cd85157a4881a9a1b3fa16b04efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 14 May 2026 17:07:25 +0200 Subject: [PATCH] refactor(insights): derive SubPageSlug + SUB_PAGE_SLUGS from SUB_PAGE_METRIC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three independent listings of the same seven sub-page slugs collapse to one. The keys of SUB_PAGE_METRIC drive both the type union and the array — adding a sub-page becomes a single-line change in one record instead of touching three declarations that must stay in lockstep. --- src/lib/insights/sub-page-metric.ts | 32 ++++++++++------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/lib/insights/sub-page-metric.ts b/src/lib/insights/sub-page-metric.ts index 58a0501ae..b66fe7060 100644 --- a/src/lib/insights/sub-page-metric.ts +++ b/src/lib/insights/sub-page-metric.ts @@ -19,26 +19,12 @@ * only (we don't fetch a height series; the user's height lives on the * profile). */ -export type SubPageSlug = - | "blutdruck" - | "gewicht" - | "puls" - | "stimmung" - | "medikamente" - | "bmi" - | "schlaf"; - -export const SUB_PAGE_SLUGS = [ - "blutdruck", - "gewicht", - "puls", - "stimmung", - "medikamente", - "bmi", - "schlaf", -] as const satisfies readonly SubPageSlug[]; - -export const SUB_PAGE_METRIC: Record = { +/** + * Single source of truth for the routed insights sub-pages. The slug + * enum, the slug array, and the per-slug metric list all derive from + * the keys of this record — adding a sub-page is a one-place change. + */ +export const SUB_PAGE_METRIC = { blutdruck: ["BLOOD_PRESSURE_SYS", "BLOOD_PRESSURE_DIA", "PULSE"], gewicht: ["WEIGHT"], puls: ["PULSE"], @@ -48,7 +34,11 @@ export const SUB_PAGE_METRIC: Record = { // BMI is derived from WEIGHT + profile height (no separate series). bmi: ["WEIGHT"], schlaf: ["SLEEP_DURATION"], -}; +} as const satisfies Record; + +export type SubPageSlug = keyof typeof SUB_PAGE_METRIC; + +export const SUB_PAGE_SLUGS = Object.keys(SUB_PAGE_METRIC) as SubPageSlug[]; /** * Mother-page route. Kept here as a named constant so call sites