feat: add fitness_history_viz widget and enhance configuration handling
Deploy Development / deploy (push) Successful in 51s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 18s

- Introduced the `fitness_history_viz` widget to the dashboard, enabling users to visualize fitness history data.
- Updated widget configuration to include `fitness_history_viz` in the allowed widgets and added validation for its configuration.
- Enhanced the widget catalog with details for the new `fitness_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 `fitness_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:13:21 +02:00
1 parent db5557e4aa
commit d22e0ba0a7
14 files changed
+616 -179

No files matched your search

@@ -17,6 +17,11 @@ import {
import { api } from '../utils/api'
import KpiTilesOverview from './KpiTilesOverview'
import { getStatusColor } from '../utils/interpret'
import {
FITNESS_HISTORY_VIZ_HISTORY_FULL,
filterFitnessHistoryKpiTiles,
normalizeFitnessHistoryVizConfig,
} from '../widgetSystem/fitnessHistoryVizConfig'
import dayjs from 'dayjs'
const PERIODS = [
@@ -28,21 +33,35 @@ const PERIODS = [
/**
* Layer 2b: Kennzahlen und Charts nur aus GET /api/charts/fitness-dashboard-viz (activity_metrics).
* @param {number} [props.externalPeriod] — feste Tage (z. B. Dashboard-Widget 7–90)
* @param {boolean} [props.embedded]
* @param {Record<string, unknown>} [props.visibility] — Dashboard-Config; undefined = voller Verlauf
* @param {import('react').ReactNode} [props.footer]
*/
export default function FitnessDashboardOverview({
period: periodProp,
onPeriodChange,
hidePeriodSelector = false,
externalPeriod,
embedded = false,
visibility,
footer = null,
}) {
const nav = useNavigate()
const [internalPeriod, setInternalPeriod] = useState(28)
const controlled = periodProp !== undefined && typeof onPeriodChange === 'function'
const period = controlled ? periodProp : internalPeriod
const setPeriod = controlled ? onPeriodChange : setInternalPeriod
const period =
externalPeriod !== undefined ? externalPeriod : controlled ? periodProp : internalPeriod
const setPeriod =
externalPeriod !== undefined ? () => {} : controlled ? onPeriodChange : setInternalPeriod
const [viz, setViz] = useState(null)
const [loading, setLoading] = useState(true)
const [err, setErr] = useState(null)
const display = visibility === undefined ? FITNESS_HISTORY_VIZ_HISTORY_FULL : normalizeFitnessHistoryVizConfig(visibility)
const chartH = embedded ? 176 : 200
const chartLoadH = embedded ? 200 : 220
useEffect(() => {
let cancelled = false
setLoading(true)
@@ -63,10 +82,13 @@ export default function FitnessDashboardOverview({
}
}, [period])
const outerClass = embedded ? '' : 'card section-gap'
const showPeriodDropdown = !hidePeriodSelector && externalPeriod === undefined && !controlled
if (loading) {
return (
<div className="card section-gap">
<div className="card-title">Fitness-Übersicht</div>
<div className={outerClass || undefined}>
{!embedded && <div className="card-title">Fitness-Übersicht</div>}
<div className="spinner" style={{ margin: 24 }} />
</div>
)
@@ -74,8 +96,8 @@ export default function FitnessDashboardOverview({
if (err) {
return (
<div className="card section-gap">
<div className="card-title">Fitness-Übersicht</div>
<div className={outerClass || undefined}>
{!embedded && <div className="card-title">Fitness-Übersicht</div>}
<div style={{ color: 'var(--danger)' }}>{err}</div>
</div>
)
@@ -83,8 +105,8 @@ export default function FitnessDashboardOverview({
if (!viz?.has_activity_entries) {
return (
<div className="card section-gap">
<div className="card-title">Fitness-Übersicht</div>
<div className={outerClass || undefined}>
{!embedded && <div className="card-title">Fitness-Übersicht</div>}
<p style={{ fontSize: 12, color: 'var(--text3)', lineHeight: 1.45, marginBottom: 14 }}>
Noch keine Aktivitätsdaten. Sobald du Trainings erfasst oder importierst, erscheinen Auswertungen hier.
</p>
@@ -130,11 +152,14 @@ export default function FitnessDashboardOverview({
}))
const loadMeta = loadCh?.metadata || {}
const kpiTiles = (viz.kpi_tiles || []).map((t) => ({
const kpiTilesRaw = (viz.kpi_tiles || []).map((t) => ({
...t,
sublabel:
typeof t.sublabel === 'string' && t.sublabel.length > 42 ? `${t.sublabel.slice(0, 40)}…` : t.sublabel,
}))
const kpiTilesShown = display.show_kpis
? filterFitnessHistoryKpiTiles(kpiTilesRaw, display.kpi_detail || 'full')
: []
const insights = viz.progress_insights || []
const eff = viz.effective_window_days
@@ -142,49 +167,59 @@ export default function FitnessDashboardOverview({
const dTyp = viz.training_type_dist_days_used
const loadDays = viz.load_chart_days_used
const showPeriodDropdown = !hidePeriodSelector && !controlled
const gridWrapStyle = { width: '100%', minWidth: 0 }
return (
<div className="card section-gap">
<div className="card-title" style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 12 }}>
<span>Fitness-Übersicht</span>
{showPeriodDropdown ? (
<label
style={{ fontSize: 12, fontWeight: 500, color: 'var(--text3)', display: 'flex', alignItems: 'center', gap: 8 }}
>
Zeitraum
<select
className="form-input"
style={{ maxWidth: 140, padding: '6px 10px', fontSize: 13 }}
value={period}
onChange={(e) => setPeriod(Number(e.target.value))}
<div className={outerClass || undefined}>
{!embedded && (
<div className="card-title" style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 12 }}>
<span>Fitness-Übersicht</span>
{showPeriodDropdown ? (
<label
style={{ fontSize: 12, fontWeight: 500, color: 'var(--text3)', display: 'flex', alignItems: 'center', gap: 8 }}
>
{PERIODS.map((p) => (
<option key={p.v} value={p.v}>
{p.label}
</option>
))}
</select>
</label>
) : null}
</div>
Zeitraum
<select
className="form-input"
style={{ maxWidth: 140, padding: '6px 10px', fontSize: 13 }}
value={period}
onChange={(e) => setPeriod(Number(e.target.value))}
>
{PERIODS.map((p) => (
<option key={p.v} value={p.v}>
{p.label}
</option>
))}
</select>
</label>
) : null}
</div>
)}
<p style={{ fontSize: 11, color: 'var(--text3)', lineHeight: 1.45, marginBottom: 10 }}>
Alles aus dem Aktivitäts-Data-Layer (Issue 53). Zusammenfassung ca. <strong>{eff}</strong> Tage · Volumen{' '}
<strong>{wUsed}</strong> Wochen · Kategorien <strong>{dTyp}</strong> Tage · Load-Zeitreihe{' '}
<strong>{loadDays ?? '—'}</strong> Tage
{viz.last_updated ? (
<>
{' '}
· letzte Aktivität <strong>{viz.last_updated}</strong>
</>
) : null}
.
</p>
{embedded && viz?.last_updated ? (
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 10 }}>
Letzte Aktivität {viz.last_updated}
</div>
) : null}
<KpiTilesOverview tiles={kpiTiles} heading="Kennzahlen" />
{display.show_layer_meta ? (
<p style={{ fontSize: 11, color: 'var(--text3)', lineHeight: 1.45, marginBottom: 10 }}>
Alles aus dem Aktivitäts-Data-Layer (Issue 53). Zusammenfassung ca. <strong>{eff}</strong> Tage · Volumen{' '}
<strong>{wUsed}</strong> Wochen · Kategorien <strong>{dTyp}</strong> Tage · Load-Zeitreihe{' '}
<strong>{loadDays ?? '—'}</strong> Tage
{viz.last_updated ? (
<>
{' '}
· letzte Aktivität <strong>{viz.last_updated}</strong>
</>
) : null}
.
</p>
) : null}
{insights.length > 0 ? (
{kpiTilesShown.length > 0 ? <KpiTilesOverview tiles={kpiTilesShown} heading="Kennzahlen" /> : null}
{display.show_progress_insights && insights.length > 0 ? (
<div style={{ marginBottom: 14 }}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Einschätzungen</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
@@ -213,136 +248,155 @@ export default function FitnessDashboardOverview({
gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))',
gap: 16,
marginTop: 8,
minWidth: 0,
}}
>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Trainingsvolumen (Minuten / Woche)
</div>
{volRows.length >= 1 ? (
<ResponsiveContainer width="100%" height={200}>
<BarChart data={volRows} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis
dataKey="name"
tick={{ fontSize: 9, fill: 'var(--text3)' }}
tickLine={false}
interval={0}
angle={-35}
textAnchor="end"
height={48}
/>
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
formatter={(v) => [`${Math.round(v)} min`, 'Volumen']}
/>
<Bar dataKey="min" fill="#1D9E75" radius={[3, 3, 0, 0]} name="Minuten" />
</BarChart>
</ResponsiveContainer>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Wochendaten im gewählten Fenster.</div>
)}
</div>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Training nach Kategorie
</div>
{pieData.length >= 1 ? (
<ResponsiveContainer width="100%" height={200}>
<PieChart>
<Pie
data={pieData}
dataKey="value"
nameKey="name"
cx="50%"
cy="50%"
outerRadius={72}
label={({ name, percent }) => `${name} ${(percent * 100).toFixed(0)}%`}
/>
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
</PieChart>
</ResponsiveContainer>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine kategorisierten Sessions im Fenster.</div>
)}
</div>
<div>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Qualitäts-Sessions (Schätzung)
</div>
{qualBar.length >= 1 ? (
<ResponsiveContainer width="100%" height={200}>
<BarChart data={qualBar} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis dataKey="name" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} allowDecimals={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
<Bar dataKey="n" radius={[3, 3, 0, 0]}>
{qualBar.map((entry, i) => (
<Cell key={`q-${i}`} fill={entry.fill} />
))}
</Bar>
</BarChart>
</ResponsiveContainer>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Daten.</div>
)}
</div>
<div style={{ gridColumn: '1 / -1', maxWidth: '100%' }}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Belastung (Proxy-Load · duration×RPE / Tag)
</div>
{loadRows.length >= 1 ? (
<>
<ResponsiveContainer width="100%" height={220}>
<LineChart data={loadRows} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis dataKey="t" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
<Line type="monotone" dataKey="load" stroke="#1D9E75" strokeWidth={2} dot={false} name="Load" />
</LineChart>
</ResponsiveContainer>
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 6, lineHeight: 1.4 }}>
ACWR {loadMeta.acwr != null ? Number(loadMeta.acwr).toFixed(2) : '—'} (
{loadMeta.acwr_status === 'optimal' ? 'oft als günstig beschrieben' : 'außerhalb 0,8–1,3'} · Proxy)
{display.show_chart_training_volume ? (
<div style={gridWrapStyle}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Trainingsvolumen (Minuten / Woche)
</div>
{volRows.length >= 1 ? (
<div style={{ width: '100%', minWidth: 0, height: chartH }}>
<ResponsiveContainer width="100%" height="100%">
<BarChart data={volRows} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis
dataKey="name"
tick={{ fontSize: 9, fill: 'var(--text3)' }}
tickLine={false}
interval={0}
angle={-35}
textAnchor="end"
height={48}
/>
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
formatter={(v) => [`${Math.round(v)} min`, 'Volumen']}
/>
<Bar dataKey="min" fill="#1D9E75" radius={[3, 3, 0, 0]} name="Minuten" />
</BarChart>
</ResponsiveContainer>
</div>
</>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Load-Daten im Fenster.</div>
)}
</div>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Wochendaten im gewählten Fenster.</div>
)}
</div>
) : null}
{display.show_chart_training_type_distribution ? (
<div style={gridWrapStyle}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Training nach Kategorie
</div>
{pieData.length >= 1 ? (
<div style={{ width: '100%', minWidth: 0, height: chartH }}>
<ResponsiveContainer width="100%" height="100%">
<PieChart>
<Pie
data={pieData}
dataKey="value"
nameKey="name"
cx="50%"
cy="50%"
outerRadius={72}
label={({ name, percent }) => `${name} ${(percent * 100).toFixed(0)}%`}
/>
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
</PieChart>
</ResponsiveContainer>
</div>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine kategorisierten Sessions im Fenster.</div>
)}
</div>
) : null}
{display.show_chart_quality_sessions ? (
<div style={gridWrapStyle}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Qualitäts-Sessions (Schätzung)
</div>
{qualBar.length >= 1 ? (
<div style={{ width: '100%', minWidth: 0, height: chartH }}>
<ResponsiveContainer width="100%" height="100%">
<BarChart data={qualBar} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis dataKey="name" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} allowDecimals={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
<Bar dataKey="n" radius={[3, 3, 0, 0]}>
{qualBar.map((entry, i) => (
<Cell key={`q-${i}`} fill={entry.fill} />
))}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Daten.</div>
)}
</div>
) : null}
{display.show_chart_load_monitoring ? (
<div style={{ ...gridWrapStyle, gridColumn: '1 / -1', maxWidth: '100%' }}>
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
Belastung (Proxy-Load · duration×RPE / Tag)
</div>
{loadRows.length >= 1 ? (
<>
<div style={{ width: '100%', minWidth: 0, height: chartLoadH }}>
<ResponsiveContainer width="100%" height="100%">
<LineChart data={loadRows} margin={{ top: 4, right: 8, bottom: 0, left: -12 }}>
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3" />
<XAxis dataKey="t" tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<YAxis tick={{ fontSize: 9, fill: 'var(--text3)' }} tickLine={false} />
<Tooltip
contentStyle={{
background: 'var(--surface)',
border: '1px solid var(--border)',
borderRadius: 8,
fontSize: 11,
}}
/>
<Line type="monotone" dataKey="load" stroke="#1D9E75" strokeWidth={2} dot={false} name="Load" />
</LineChart>
</ResponsiveContainer>
</div>
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 6, lineHeight: 1.4 }}>
ACWR {loadMeta.acwr != null ? Number(loadMeta.acwr).toFixed(2) : '—'} (
{loadMeta.acwr_status === 'optimal' ? 'oft als günstig beschrieben' : 'außerhalb 0,8–1,3'} · Proxy)
</div>
</>
) : (
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Keine Load-Daten im Fenster.</div>
)}
</div>
) : null}
</div>
{footer}
</div>
)
}
@@ -0,0 +1,29 @@
import { useNavigate } from 'react-router-dom'
import FitnessHistoryVizSection from '../history/FitnessHistoryVizSection'
import { normalizeBodyChartDays } from '../../widgetSystem/bodyChartDays'
import { normalizeFitnessHistoryVizConfig } from '../../widgetSystem/fitnessHistoryVizConfig'
/**
* Verlauf → Fitness als Dashboard-Widget: GET /charts/fitness-dashboard-viz (Layer 2b), Umfang über Layout-Config.
* @param {{ refreshTick?: number, fitnessHistoryVizConfig?: Record<string, unknown> }} props
*/
export default function FitnessHistoryVizWidget({ refreshTick = 0, fitnessHistoryVizConfig }) {
const nav = useNavigate()
const cfg = normalizeFitnessHistoryVizConfig(fitnessHistoryVizConfig)
const days = normalizeBodyChartDays(cfg.chart_days)
return (
<div className="card section-gap" style={{ marginBottom: 16 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
<div>
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Fitness (Verlauf-Bundle)</div>
<div style={{ fontSize: 12, color: 'var(--text3)' }}>fitness-dashboard-viz · {days} Tage</div>
</div>
<button type="button" className="btn btn-secondary" style={{ fontSize: 12, padding: '6px 12px' }} onClick={() => nav('/history', { state: { tab: 'activity' } })}>
Verlauf →
</button>
</div>
<FitnessHistoryVizSection key={`${refreshTick}-${days}`} externalPeriod={days} embedded visibility={cfg} />
</div>
)
}
@@ -0,0 +1,33 @@
import FitnessDashboardOverview from '../FitnessDashboardOverview'
/**
* Verlauf → Fitness bzw. Dashboard-Widget: GET /charts/fitness-dashboard-viz (Layer 2b).
* @param {number} [props.externalPeriod] — Widget: feste Tage (7–90)
* @param {number} [props.period] — Verlauf: gesteuerter Zeitraum (inkl. 9999)
* @param {(n: number) => void} [props.onPeriodChange]
* @param {boolean} [props.hidePeriodSelector]
* @param {boolean} [props.embedded]
* @param {Record<string, unknown>} [props.visibility] — undefined = volle Übersicht (wie bisher)
* @param {import('react').ReactNode} [props.footer]
*/
export default function FitnessHistoryVizSection({
externalPeriod,
period,
onPeriodChange,
hidePeriodSelector,
embedded,
visibility,
footer,
}) {
return (
<FitnessDashboardOverview
period={period}
onPeriodChange={onPeriodChange}
hidePeriodSelector={hidePeriodSelector}
externalPeriod={externalPeriod}
embedded={embedded}
visibility={visibility}
footer={footer}
/>
)
}