feat: Extend widget configuration for KPI board and enhance validation
- Added support for the "kpi_board" widget in the dashboard configuration, allowing for chart_days validation. - Updated the widget catalog description to reflect the new configuration options for KPI tiles. - Enhanced the DashboardLabPage to manage chart_days input for the KPI board, improving user experience. - Introduced normalization functions for KPI kcal window days to maintain consistent behavior. - Bumped app_dashboard version to 1.4.0 to reflect these enhancements.
This commit is contained in:
1 parent
97f9aa696e
commit
de99856a28
8 files changed
+65
-24
No files matched your search
@@ -4,6 +4,7 @@ import dayjs from 'dayjs'
|
||||
import { api } from '../../utils/api'
|
||||
import { getBfCategory } from '../../utils/calc'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { KPI_KCAL_WINDOW_DEFAULT } from '../../widgetSystem/bodyChartDays'
|
||||
|
||||
const MAX_KPI = 9
|
||||
|
||||
@@ -16,9 +17,9 @@ function formatRefVal(row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* KPIs: Referenzwerte (Layer-1-Summary) + Körperfett % + Ø Kalorien 7T — max. 9 Kacheln.
|
||||
* KPIs: Referenzwerte (Layer-1-Summary) + Körperfett % + Ø Kalorien (Fenster konfigurierbar) — max. 9 Kacheln.
|
||||
*/
|
||||
export default function PilotKpiBoard({ refreshTick = 0 }) {
|
||||
export default function PilotKpiBoard({ refreshTick = 0, kcalWindowDays = KPI_KCAL_WINDOW_DEFAULT }) {
|
||||
const { activeProfile } = useProfile()
|
||||
const sex = activeProfile?.sex || 'm'
|
||||
const [refs, setRefs] = useState([])
|
||||
@@ -32,15 +33,18 @@ export default function PilotKpiBoard({ refreshTick = 0 }) {
|
||||
;(async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const nutrLimit = Math.min(2000, Math.max(60, kcalWindowDays * 5))
|
||||
const [summary, calipers, nutrition] = await Promise.all([
|
||||
api.listProfileReferenceValuesSummary().catch(() => ({ tiles: [] })),
|
||||
api.listCaliper(3).catch(() => []),
|
||||
api.listNutrition(30).catch(() => []),
|
||||
api.listNutrition(nutrLimit).catch(() => []),
|
||||
])
|
||||
if (cancelled) return
|
||||
const tiles = Array.isArray(summary?.tiles) ? summary.tiles.filter((t) => t?.latest) : []
|
||||
const latestCal = Array.isArray(calipers) && calipers[0]?.body_fat_pct != null ? calipers[0] : null
|
||||
const recentNutr = (nutrition || []).filter((n) => n.date >= dayjs().subtract(7, 'day').format('YYYY-MM-DD'))
|
||||
const recentNutr = (nutrition || []).filter(
|
||||
(n) => n.date >= dayjs().subtract(kcalWindowDays, 'day').format('YYYY-MM-DD'),
|
||||
})
|
||||
const kcal =
|
||||
recentNutr.length > 0
|
||||
? Math.round(recentNutr.reduce((s, n) => s + (n.kcal || 0), 0) / recentNutr.length)
|
||||
@@ -74,7 +78,7 @@ export default function PilotKpiBoard({ refreshTick = 0 }) {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [refreshTick, sex])
|
||||
}, [refreshTick, sex, kcalWindowDays])
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -124,7 +128,9 @@ export default function PilotKpiBoard({ refreshTick = 0 }) {
|
||||
if (avgKcal != null) {
|
||||
tiles.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 (7T)</div>
|
||||
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)' }}>
|
||||
Ø Kalorien ({kcalWindowDays}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>,
|
||||
|
||||
Reference in new issue
Block a user