refactor: integrate KpiTilesOverview component for enhanced KPI display
Deploy Development / deploy (push) Successful in 54s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 16s

- Introduced the KpiTilesOverview component to streamline the presentation of KPI tiles, replacing the previous BodyKpiOverview implementation.
- Updated the PilotKpiBoard and History components to utilize the new KpiTilesOverview for better touch and hover interactions.
- Refactored CSS styles to accommodate the new component structure, ensuring a responsive design across devices.
- Enhanced the logic for generating KPI tiles, improving data handling and user experience.
This commit is contained in:
Lars committed 2026-04-19 17:00:05 +02:00
1 parent 8c60601ed1
commit 08b7aa0ca1
4 files changed
+248 -176

No files matched your search

+63 -55
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, useMemo, useCallback } from 'react'
import { useState, useEffect, useMemo } from 'react'
import { Link } from 'react-router-dom'
import dayjs from 'dayjs'
import { api } from '../../utils/api'
@@ -6,6 +6,7 @@ import { getBfCategory } from '../../utils/calc'
import { useProfile } from '../../context/ProfileContext'
import { KPI_KCAL_WINDOW_DEFAULT } from '../../widgetSystem/bodyChartDays'
import { kpiTileOrderFromConfig } from '../../widgetSystem/kpiBoardTiles'
import KpiTilesOverview from '../KpiTilesOverview'
const MAX_KPI = 9
@@ -113,62 +114,63 @@ export default function PilotKpiBoard({ refreshTick = 0, kpiConfig }) {
return buildAutoTileIds(refTiles, hasBf, hasKcal)
}, [manualOrder, refTiles, bf, avgKcal])
const pushTileForId = useCallback(
(id, out) => {
if (id === 'body_fat') {
if (!bf) return
out.push(
<div key="kpi-bf" className="card" style={{ margin: 0, padding: 12, boxSizing: 'border-box' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)' }}>Körperfett</div>
<div style={{ fontSize: 17, fontWeight: 700, marginTop: 4, color: bf.cat?.color || 'var(--text1)' }}>
{bf.pct}%
</div>
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>{bf.cat?.label || 'Caliper'}</div>
</div>,
)
return
}
if (id === 'avg_kcal') {
if (avgKcal == null) return
out.push(
<div key="kpi-kcal" className="card" style={{ margin: 0, padding: 12, boxSizing: 'border-box' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)' }}>
Ø Kalorien ({KPI_KCAL_WINDOW_DEFAULT}T)
</div>
<div style={{ fontSize: 17, fontWeight: 700, marginTop: 4, color: '#EF9F27' }}>{avgKcal} kcal</div>
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>Ernährung</div>
</div>,
)
return
}
const tk = parseRefTypeKey(id)
if (!tk) return
const tile = refByKey.get(tk)
if (!tile?.latest) return
const l = tile.latest
out.push(
<div key={`ref-${tk}`} className="card" style={{ margin: 0, padding: 12, boxSizing: 'border-box' }}>
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)' }}>{tile.type_label}</div>
<div style={{ fontSize: 17, fontWeight: 700, marginTop: 4 }}>
{formatRefVal(l)}
{l.unit ? (
<span style={{ fontSize: 13, fontWeight: 600, color: 'var(--text2)', marginLeft: 4 }}>{l.unit}</span>
) : null}
</div>
<div style={{ fontSize: 10, color: 'var(--text3)', marginTop: 4 }}>Ref.wert</div>
</div>,
)
},
[bf, avgKcal, refByKey],
)
const visibleTiles = useMemo(() => {
const kpiTiles = useMemo(() => {
const out = []
for (const id of orderIds) {
pushTileForId(id, out)
if (id === 'body_fat') {
if (!bf) continue
out.push({
key: 'kpi-bf',
status: 'good',
category: 'Körperfett',
icon: '🫧',
value: `${bf.pct}%`,
sublabel: bf.cat?.label || 'Caliper',
valueColor: bf.cat?.color,
hoverTop: 'Körperfett (Caliper)',
hoverBody:
`Letzte Messung: ${bf.date ? dayjs(bf.date).format('DD.MM.YYYY') : '—'}.\n` +
'Wert aus dem Caliper-Log; die Farbe/Kategorie richtet sich nach Geschlecht und üblicher Spanne.',
})
continue
}
if (id === 'avg_kcal') {
if (avgKcal == null) continue
out.push({
key: 'kpi-kcal',
status: 'good',
category: `Ø Kalorien (${KPI_KCAL_WINDOW_DEFAULT}T)`,
icon: '🍽️',
value: `${avgKcal} kcal`,
sublabel: 'Ernährung',
valueColor: '#EF9F27',
hoverTop: `Ø Kalorien (${KPI_KCAL_WINDOW_DEFAULT} Tage)`,
hoverBody:
`Durchschnitt der täglichen Kalorien aus dem Ernährungs-Log über die letzten ${KPI_KCAL_WINDOW_DEFAULT} Tage (Mittel über alle geladenen Tageseinträge im Fenster).`,
})
continue
}
const tk = parseRefTypeKey(id)
if (!tk) continue
const tile = refByKey.get(tk)
if (!tile?.latest) continue
const l = tile.latest
const valStr = formatRefVal(l)
const withUnit = l.unit ? `${valStr} ${l.unit}`.trim() : valStr
out.push({
key: `ref-${tk}`,
status: 'good',
category: tile.type_label,
icon: '📌',
value: withUnit,
sublabel: 'Ref.wert',
hoverTop: tile.type_label,
hoverBody:
'Persönlicher Referenzwert aus dem Profil. Verwaltung unter Einstellungen → Referenzwerte.',
})
}
return out
}, [orderIds, pushTileForId])
}, [orderIds, bf, avgKcal, refByKey])
if (loading) {
return (
@@ -185,7 +187,7 @@ export default function PilotKpiBoard({ refreshTick = 0, kpiConfig }) {
)
}
if (visibleTiles.length === 0) {
if (kpiTiles.length === 0) {
return (
<div className="card section-gap">
<div className="card-title">Kennzahlen</div>
@@ -216,7 +218,13 @@ export default function PilotKpiBoard({ refreshTick = 0, kpiConfig }) {
? 'Ausgewählte Kacheln in festgelegter Reihenfolge (ohne Daten werden Kacheln ausgelassen).'
: `Bis ${MAX_KPI} Kacheln: Referenzwerte, Körperfett, Ø Kalorien (${KPI_KCAL_WINDOW_DEFAULT}T).`}
</p>
<div className="ref-value-tiles-grid">{visibleTiles}</div>
<KpiTilesOverview
tiles={kpiTiles}
heading={null}
showTouchHint
gridClassName="ref-value-tiles-grid"
marginBottom={0}
/>
</div>
)
}