feat: add recovery_history_viz widget and enhance configuration handling
Deploy Development / deploy (push) Successful in 47s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s

- Introduced the `recovery_history_viz` widget to the dashboard, enabling users to visualize recovery history data.
- Updated widget configuration to include `recovery_history_viz` in the allowed widgets and added validation for its configuration.
- Enhanced the widget catalog with details for the new `recovery_history_viz` entry.
- Implemented default values and validation logic for the widget's configuration, ensuring proper handling of user inputs.
- Added tests to ensure proper validation of the `recovery_history_viz` widget configuration.
- Bumped application version to reflect the addition of the new widget.
This commit is contained in:
Lars committed 2026-04-22 10:18:02 +02:00
1 parent d22e0ba0a7
commit e20b321b64
16 files changed
+735 -258

No files matched your search

@@ -0,0 +1,106 @@
import { RECOVERY_HISTORY_VIZ_WIDGET_DEFAULTS, normalizeRecoveryHistoryVizConfig } from './recoveryHistoryVizConfig'
const CHART_TOGGLES = [
{ key: 'show_chart_recovery_score', label: 'HRV-/Recovery-Score-Verlauf' },
{ key: 'show_chart_sleep_quality', label: 'Schlaf: Dauer & Qualität' },
{ key: 'show_chart_sleep_debt', label: 'Schlafschuld' },
{ key: 'show_chart_hrv_rhr', label: 'HRV & Ruhepuls (Zeitverlauf)' },
]
const SECTION_TOGGLES = [
{ key: 'show_sleep_section_heading', label: 'Zwischenüberschrift «Schlaf & Erholung»' },
{ key: 'show_heart_section_heading', label: 'Zwischenüberschrift «Herz & Kreislauf»' },
{ key: 'show_heart_context_card', label: 'Herz: Einordnung, Zonen, Snapshots' },
{ key: 'show_vitals_extra_heading', label: 'Überschrift «Weitere Vitalparameter»' },
{ key: 'show_vitals_extra_trends', label: 'VO2 / SpO2 / Atemfrequenz (Verläufe)' },
]
const OTHER_TOGGLES = [
{ key: 'show_layer_meta', label: 'Meta-Zeile (Fenster-Tage, Data-Layer)' },
{ key: 'show_kpis', label: 'KPI-Kacheln' },
{ key: 'show_progress_insights', label: 'Überblick: Recovery & Schlaf (Karten)' },
]
/**
* @param {{ config: Record<string, unknown>, onChange: (next: Record<string, unknown>) => void }} props
*/
export default function RecoveryHistoryVizConfigEditor({ config, onChange }) {
const merged = normalizeRecoveryHistoryVizConfig(config)
const patch = (partial) => {
const next = { ...merged, ...partial }
const def = RECOVERY_HISTORY_VIZ_WIDGET_DEFAULTS
const stored = {}
for (const k of Object.keys(def)) {
if (next[k] !== def[k]) stored[k] = next[k]
}
onChange(stored)
}
const setBool = (key, checked) => {
patch({ [key]: checked })
}
return (
<div style={{ marginTop: 10, marginLeft: 28 }}>
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 8, lineHeight: 1.5 }}>
<strong>Erholung (Verlauf-Bundle):</strong> welche Blöcke auf der Übersicht erscheinen. Unbelegte Felder = schlanker
Standard (KPI kompakt, Schlaf-Charts, HRV/RHR — ohne Kontextkarte und Extra-Vitals).
</div>
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 6 }}>KPI-Umfang</div>
<label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, marginBottom: 10, cursor: 'pointer' }}>
<input
type="radio"
name="recovery_hist_kpi_detail"
checked={merged.kpi_detail === 'compact'}
onChange={() => patch({ kpi_detail: 'compact' })}
/>
<span>Kompakt (erste 4 Kacheln)</span>
</label>
<label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, marginBottom: 12, cursor: 'pointer' }}>
<input
type="radio"
name="recovery_hist_kpi_detail"
checked={merged.kpi_detail === 'full'}
onChange={() => patch({ kpi_detail: 'full' })}
/>
<span>Voll (alle Kacheln)</span>
</label>
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 6 }}>Bereiche</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{OTHER_TOGGLES.map(({ key, label }) => (
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, cursor: 'pointer' }}>
<input type="checkbox" checked={merged[key]} onChange={(e) => setBool(key, e.target.checked)} />
<span>{label}</span>
</label>
))}
</div>
<div style={{ fontSize: 12, color: 'var(--text2)', margin: '12px 0 6px' }}>Abschnitte</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{SECTION_TOGGLES.map(({ key, label }) => (
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, cursor: 'pointer' }}>
<input type="checkbox" checked={merged[key]} onChange={(e) => setBool(key, e.target.checked)} />
<span>{label}</span>
</label>
))}
</div>
<div style={{ fontSize: 12, color: 'var(--text2)', margin: '12px 0 6px' }}>Charts</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{CHART_TOGGLES.map(({ key, label }) => (
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, cursor: 'pointer' }}>
<input type="checkbox" checked={merged[key]} onChange={(e) => setBool(key, e.target.checked)} />
<span>{label}</span>
</label>
))}
</div>
<button
type="button"
className="btn btn-secondary"
style={{ marginTop: 10, fontSize: 12, padding: '6px 12px' }}
onClick={() => onChange({})}
>
Auf schlanken Standard zurück
</button>
</div>
)
}
@@ -0,0 +1,85 @@
/**
* Sichtbarkeit für recovery_history_viz (sync mit backend dashboard_widget_config).
* `visibility === undefined` → Verlauf: volle Erholungs-Übersicht (wie bisher).
*/
export const RECOVERY_HISTORY_VIZ_HISTORY_FULL = {
chart_days: 30,
show_layer_meta: true,
show_kpis: true,
kpi_detail: 'full',
show_progress_insights: true,
show_sleep_section_heading: true,
show_chart_recovery_score: true,
show_chart_sleep_quality: true,
show_chart_sleep_debt: true,
show_heart_section_heading: true,
show_heart_context_card: true,
show_chart_hrv_rhr: true,
show_vitals_extra_heading: true,
show_vitals_extra_trends: true,
}
export const RECOVERY_HISTORY_VIZ_WIDGET_DEFAULTS = {
chart_days: 30,
show_layer_meta: false,
show_kpis: true,
kpi_detail: 'compact',
show_progress_insights: false,
show_sleep_section_heading: true,
show_chart_recovery_score: true,
show_chart_sleep_quality: true,
show_chart_sleep_debt: false,
show_heart_section_heading: true,
show_heart_context_card: false,
show_chart_hrv_rhr: true,
show_vitals_extra_heading: false,
show_vitals_extra_trends: false,
}
const BOOL_KEYS = [
'show_layer_meta',
'show_kpis',
'show_progress_insights',
'show_sleep_section_heading',
'show_chart_recovery_score',
'show_chart_sleep_quality',
'show_chart_sleep_debt',
'show_heart_section_heading',
'show_heart_context_card',
'show_chart_hrv_rhr',
'show_vitals_extra_heading',
'show_vitals_extra_trends',
]
/**
* @param {Record<string, unknown>|null|undefined} raw
*/
export function normalizeRecoveryHistoryVizConfig(raw) {
const base = { ...RECOVERY_HISTORY_VIZ_WIDGET_DEFAULTS }
if (!raw || typeof raw !== 'object') return base
for (const k of BOOL_KEYS) {
if (Object.prototype.hasOwnProperty.call(raw, k)) {
base[k] = raw[k] === true
}
}
if (raw.kpi_detail === 'full' || raw.kpi_detail === 'compact') {
base.kpi_detail = raw.kpi_detail
}
if (raw.chart_days != null) {
const n = Number(raw.chart_days)
if (Number.isFinite(n)) {
base.chart_days = Math.min(90, Math.max(7, Math.round(n)))
}
}
return base
}
/**
* @param {Array<object>} kpiTiles
* @param {'compact'|'full'} detail
*/
export function filterRecoveryHistoryKpiTiles(kpiTiles, detail) {
if (detail === 'full' || !Array.isArray(kpiTiles)) return kpiTiles
return kpiTiles.slice(0, 4)
}
@@ -17,9 +17,11 @@ import NutritionDetailChartsWidget from '../components/dashboard-widgets/Nutriti
import BodyHistoryVizWidget from '../components/dashboard-widgets/BodyHistoryVizWidget'
import NutritionHistoryVizWidget from '../components/dashboard-widgets/NutritionHistoryVizWidget'
import FitnessHistoryVizWidget from '../components/dashboard-widgets/FitnessHistoryVizWidget'
import RecoveryHistoryVizWidget from '../components/dashboard-widgets/RecoveryHistoryVizWidget'
import { normalizeBodyHistoryVizConfig } from './bodyHistoryVizConfig'
import { normalizeNutritionHistoryVizConfig } from './nutritionHistoryVizConfig'
import { normalizeFitnessHistoryVizConfig } from './fitnessHistoryVizConfig'
import { normalizeRecoveryHistoryVizConfig } from './recoveryHistoryVizConfig'
import RecoveryChartsPanelWidget from '../components/dashboard-widgets/RecoveryChartsPanelWidget'
import ProgressPhotosWidget from '../components/dashboard-widgets/ProgressPhotosWidget'
import RecoverySleepRestWidget from '../components/dashboard-widgets/RecoverySleepRestWidget'
@@ -142,6 +144,14 @@ export function ensurePilotLabWidgetsRegistered() {
fitnessHistoryVizConfig: normalizeFitnessHistoryVizConfig(ctx.layoutEntry?.config),
}),
})
registerDashboardWidget({
id: 'recovery_history_viz',
Component: RecoveryHistoryVizWidget,
mapProps: (ctx) => ({
refreshTick: ctx.refreshTick,
recoveryHistoryVizConfig: normalizeRecoveryHistoryVizConfig(ctx.layoutEntry?.config),
}),
})
registerDashboardWidget({
id: 'recovery_charts_panel',
Component: RecoveryChartsPanelWidget,