From 50a6247177de32457b760d791d9776fbf985bcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 22 Oct 2026 15:18:58 +0200 Subject: [PATCH] refactor(settings): move the managed-record option lists and label keys into a data module The Coach metric and cluster options and the label keys of the managed-record settings forms are data; they now sit beside the forms instead of inside the component file, which drops back under its size baseline after the locale picker started reading the locale list. --- .../managed-record-settings-labels.ts | 107 +++++++++++++++++ .../managed-record-settings-section.tsx | 112 ++---------------- 2 files changed, 116 insertions(+), 103 deletions(-) create mode 100644 src/components/settings/managed-record-settings-labels.ts diff --git a/src/components/settings/managed-record-settings-labels.ts b/src/components/settings/managed-record-settings-labels.ts new file mode 100644 index 000000000..7e4a54d4c --- /dev/null +++ b/src/components/settings/managed-record-settings-labels.ts @@ -0,0 +1,107 @@ +/** + * The option lists and label keys of the managed-record settings forms: + * which Coach metrics and data clusters a guardian can exclude, and the + * bundle key each option, insights section and threshold metric renders + * with. Data only; the forms live in `managed-record-settings-section.tsx`. + */ +import type { InsightsSectionId } from "@/lib/insights-layout"; +import type { ThresholdMetric } from "@/lib/analytics/effective-range"; + +export const COACH_EXCLUDE_METRICS = [ + "bp", + "weight", + "pulse", + "mood", + "compliance", + "hrv", + "sleep", + "resting_hr", + "steps", + "medications", + "anthropometrics", +] as const; +export const COACH_DATA_CLUSTERS = [ + "cardio", + "body", + "activity", + "workouts", + "sleep", + "mood", + "glucose", + "medication", + "mobility", + "environment", +] as const; +export const COACH_EXCLUDE_METRIC_LABEL_KEYS: Record< + (typeof COACH_EXCLUDE_METRICS)[number], + string +> = { + bp: "settings.sharedRecord.managedSettings.coach.metrics.bp", + weight: "settings.sharedRecord.managedSettings.coach.metrics.weight", + pulse: "settings.sharedRecord.managedSettings.coach.metrics.pulse", + mood: "settings.sharedRecord.managedSettings.coach.metrics.mood", + compliance: "settings.sharedRecord.managedSettings.coach.metrics.compliance", + hrv: "settings.sharedRecord.managedSettings.coach.metrics.hrv", + sleep: "settings.sharedRecord.managedSettings.coach.metrics.sleep", + resting_hr: "settings.sharedRecord.managedSettings.coach.metrics.restingHr", + steps: "settings.sharedRecord.managedSettings.coach.metrics.steps", + medications: + "settings.sharedRecord.managedSettings.coach.metrics.medications", + anthropometrics: + "settings.sharedRecord.managedSettings.coach.metrics.anthropometrics", +}; +export const COACH_DATA_CLUSTER_LABEL_KEYS: Record< + (typeof COACH_DATA_CLUSTERS)[number], + string +> = { + cardio: "settings.sharedRecord.managedSettings.coach.clusters.cardio", + body: "settings.sharedRecord.managedSettings.coach.clusters.body", + activity: "settings.sharedRecord.managedSettings.coach.clusters.activity", + workouts: "settings.sharedRecord.managedSettings.coach.clusters.workouts", + sleep: "settings.sharedRecord.managedSettings.coach.clusters.sleep", + mood: "settings.sharedRecord.managedSettings.coach.clusters.mood", + glucose: "settings.sharedRecord.managedSettings.coach.clusters.glucose", + medication: "settings.sharedRecord.managedSettings.coach.clusters.medication", + mobility: "settings.sharedRecord.managedSettings.coach.clusters.mobility", + environment: + "settings.sharedRecord.managedSettings.coach.clusters.environment", +}; +export const INSIGHTS_SECTION_LABEL_KEYS: Record = { + "wellness-scores": + "settings.sharedRecord.managedSettings.insights.sectionLabels.wellnessScores", + "daily-briefing": + "settings.sharedRecord.managedSettings.insights.sectionLabels.dailyBriefing", + vitals: "settings.sharedRecord.managedSettings.insights.sectionLabels.vitals", + trends: "settings.sharedRecord.managedSettings.insights.sectionLabels.trends", + "period-review": + "settings.sharedRecord.managedSettings.insights.sectionLabels.periodReview", + "cycle-summary": + "settings.sharedRecord.managedSettings.insights.sectionLabels.cycleSummary", + signals: + "settings.sharedRecord.managedSettings.insights.sectionLabels.signals", + "rhythm-events": + "settings.sharedRecord.managedSettings.insights.sectionLabels.rhythmEvents", + "health-status": + "settings.sharedRecord.managedSettings.insights.sectionLabels.healthStatus", + breathing: + "settings.sharedRecord.managedSettings.insights.sectionLabels.breathing", + "labs-changes": + "settings.sharedRecord.managedSettings.insights.sectionLabels.labsChanges", + ecg: "settings.sharedRecord.managedSettings.insights.sectionLabels.ecg", +}; +export const METRIC_LABEL_KEYS: Record = { + WEIGHT: "thresholds.metricWeight", + BLOOD_PRESSURE_SYS: "thresholds.metricBpSys", + BLOOD_PRESSURE_DIA: "thresholds.metricBpDia", + PULSE: "thresholds.metricPulse", + BODY_FAT: "thresholds.metricBodyFat", + SLEEP_DURATION: "thresholds.metricSleep", + ACTIVITY_STEPS: "thresholds.metricSteps", + BLOOD_GLUCOSE_FASTING: "thresholds.metricGlucoseFasting", + BLOOD_GLUCOSE_POSTPRANDIAL: "thresholds.metricGlucosePostprandial", + BLOOD_GLUCOSE_RANDOM: "thresholds.metricGlucoseRandom", + BLOOD_GLUCOSE_BEDTIME: "thresholds.metricGlucoseBedtime", + TOTAL_BODY_WATER: "thresholds.metricBodyWater", + BONE_MASS: "thresholds.metricBoneMass", + OXYGEN_SATURATION: "thresholds.metricOxygenSaturation", +}; diff --git a/src/components/settings/managed-record-settings-section.tsx b/src/components/settings/managed-record-settings-section.tsx index 111139dff..219578aed 100644 --- a/src/components/settings/managed-record-settings-section.tsx +++ b/src/components/settings/managed-record-settings-section.tsx @@ -7,10 +7,7 @@ import { Settings } from "lucide-react"; import { useAuth } from "@/hooks/use-auth"; import { apiGet, apiPatch } from "@/lib/api/api-fetch"; import { useTranslations } from "@/lib/i18n/context"; -import { - normalizeInsightsTileId, - type InsightsSectionId, -} from "@/lib/insights-layout"; +import { normalizeInsightsTileId } from "@/lib/insights-layout"; import { MODULE_REGISTRY } from "@/lib/modules/registry"; import { aiInputDependentKeys, @@ -47,6 +44,14 @@ import { SettingsCardHeader } from "./_card-header"; import { SettingsCard } from "./settings-card"; import { DEFAULT_TIMEZONE } from "@/lib/tz/format"; import { locales } from "@/lib/i18n/config"; +import { + COACH_EXCLUDE_METRICS, + COACH_DATA_CLUSTERS, + COACH_EXCLUDE_METRIC_LABEL_KEYS, + COACH_DATA_CLUSTER_LABEL_KEYS, + INSIGHTS_SECTION_LABEL_KEYS, + METRIC_LABEL_KEYS, +} from "./managed-record-settings-labels"; interface ManagedRecordSettingsResponse { recordId: string; @@ -67,105 +72,6 @@ type SettingsFormProps = { error?: ReactNode; }; -const COACH_EXCLUDE_METRICS = [ - "bp", - "weight", - "pulse", - "mood", - "compliance", - "hrv", - "sleep", - "resting_hr", - "steps", - "medications", - "anthropometrics", -] as const; -const COACH_DATA_CLUSTERS = [ - "cardio", - "body", - "activity", - "workouts", - "sleep", - "mood", - "glucose", - "medication", - "mobility", - "environment", -] as const; -const COACH_EXCLUDE_METRIC_LABEL_KEYS: Record< - (typeof COACH_EXCLUDE_METRICS)[number], - string -> = { - bp: "settings.sharedRecord.managedSettings.coach.metrics.bp", - weight: "settings.sharedRecord.managedSettings.coach.metrics.weight", - pulse: "settings.sharedRecord.managedSettings.coach.metrics.pulse", - mood: "settings.sharedRecord.managedSettings.coach.metrics.mood", - compliance: "settings.sharedRecord.managedSettings.coach.metrics.compliance", - hrv: "settings.sharedRecord.managedSettings.coach.metrics.hrv", - sleep: "settings.sharedRecord.managedSettings.coach.metrics.sleep", - resting_hr: "settings.sharedRecord.managedSettings.coach.metrics.restingHr", - steps: "settings.sharedRecord.managedSettings.coach.metrics.steps", - medications: - "settings.sharedRecord.managedSettings.coach.metrics.medications", - anthropometrics: - "settings.sharedRecord.managedSettings.coach.metrics.anthropometrics", -}; -const COACH_DATA_CLUSTER_LABEL_KEYS: Record< - (typeof COACH_DATA_CLUSTERS)[number], - string -> = { - cardio: "settings.sharedRecord.managedSettings.coach.clusters.cardio", - body: "settings.sharedRecord.managedSettings.coach.clusters.body", - activity: "settings.sharedRecord.managedSettings.coach.clusters.activity", - workouts: "settings.sharedRecord.managedSettings.coach.clusters.workouts", - sleep: "settings.sharedRecord.managedSettings.coach.clusters.sleep", - mood: "settings.sharedRecord.managedSettings.coach.clusters.mood", - glucose: "settings.sharedRecord.managedSettings.coach.clusters.glucose", - medication: "settings.sharedRecord.managedSettings.coach.clusters.medication", - mobility: "settings.sharedRecord.managedSettings.coach.clusters.mobility", - environment: - "settings.sharedRecord.managedSettings.coach.clusters.environment", -}; -const INSIGHTS_SECTION_LABEL_KEYS: Record = { - "wellness-scores": - "settings.sharedRecord.managedSettings.insights.sectionLabels.wellnessScores", - "daily-briefing": - "settings.sharedRecord.managedSettings.insights.sectionLabels.dailyBriefing", - vitals: "settings.sharedRecord.managedSettings.insights.sectionLabels.vitals", - trends: "settings.sharedRecord.managedSettings.insights.sectionLabels.trends", - "period-review": - "settings.sharedRecord.managedSettings.insights.sectionLabels.periodReview", - "cycle-summary": - "settings.sharedRecord.managedSettings.insights.sectionLabels.cycleSummary", - signals: - "settings.sharedRecord.managedSettings.insights.sectionLabels.signals", - "rhythm-events": - "settings.sharedRecord.managedSettings.insights.sectionLabels.rhythmEvents", - "health-status": - "settings.sharedRecord.managedSettings.insights.sectionLabels.healthStatus", - breathing: - "settings.sharedRecord.managedSettings.insights.sectionLabels.breathing", - "labs-changes": - "settings.sharedRecord.managedSettings.insights.sectionLabels.labsChanges", - ecg: "settings.sharedRecord.managedSettings.insights.sectionLabels.ecg", -}; -const METRIC_LABEL_KEYS: Record = { - WEIGHT: "thresholds.metricWeight", - BLOOD_PRESSURE_SYS: "thresholds.metricBpSys", - BLOOD_PRESSURE_DIA: "thresholds.metricBpDia", - PULSE: "thresholds.metricPulse", - BODY_FAT: "thresholds.metricBodyFat", - SLEEP_DURATION: "thresholds.metricSleep", - ACTIVITY_STEPS: "thresholds.metricSteps", - BLOOD_GLUCOSE_FASTING: "thresholds.metricGlucoseFasting", - BLOOD_GLUCOSE_POSTPRANDIAL: "thresholds.metricGlucosePostprandial", - BLOOD_GLUCOSE_RANDOM: "thresholds.metricGlucoseRandom", - BLOOD_GLUCOSE_BEDTIME: "thresholds.metricGlucoseBedtime", - TOTAL_BODY_WATER: "thresholds.metricBodyWater", - BONE_MASS: "thresholds.metricBoneMass", - OXYGEN_SATURATION: "thresholds.metricOxygenSaturation", -}; - function asRecord(value: unknown): Record { return value !== null && typeof value === "object" && !Array.isArray(value) ? (value as Record)