feat: Revamp KPI board configuration and validation
- Enhanced the KPI board widget to support tile configuration, allowing users to select and order tiles. - Updated validation logic to ensure proper handling of tile IDs and configuration fields. - Removed legacy chart_days support, transitioning to a fixed analysis window for KPI metrics. - Improved the DashboardLabPage to integrate the new KpiBoardConfigEditor for managing tile selections. - Bumped app_dashboard version to 1.5.0 to reflect these significant changes.
This commit is contained in:
1 parent
096d896166
commit
c0c512e942
10 files changed
+390
-91
No files matched your search
@@ -8,14 +8,13 @@ import {
|
||||
BODY_CHART_DAYS_DEFAULT,
|
||||
BODY_CHART_DAYS_MAX,
|
||||
BODY_CHART_DAYS_MIN,
|
||||
KPI_KCAL_WINDOW_DEFAULT,
|
||||
normalizeBodyChartDays,
|
||||
normalizeKpiKcalWindowDays,
|
||||
} from '../widgetSystem/bodyChartDays'
|
||||
import KpiBoardConfigEditor from '../widgetSystem/KpiBoardConfigEditor'
|
||||
import { moveWidget, normalizeLayoutForEditor, toggleWidget } from '../widgetSystem/layoutEditor'
|
||||
|
||||
/** Widgets mit optionalem config.chart_days (7–90), gleiche UX im Editor */
|
||||
const CHART_DAYS_WIDGET_IDS = new Set(['body_overview', 'activity_overview', 'kpi_board'])
|
||||
const CHART_DAYS_WIDGET_IDS = new Set(['body_overview', 'activity_overview'])
|
||||
|
||||
function catalogMetaById(catalog) {
|
||||
if (!catalog?.widgets?.length) return {}
|
||||
@@ -39,12 +38,9 @@ export default function DashboardLabPage() {
|
||||
const metaById = catalogMetaById(catalog)
|
||||
|
||||
const commitChartDaysDraftToLayout = useCallback((draftStr, baseLayout, widgetId) => {
|
||||
const clamped =
|
||||
widgetId === 'kpi_board'
|
||||
? normalizeKpiKcalWindowDays(draftStr === '' || draftStr == null ? null : draftStr)
|
||||
: normalizeBodyChartDays(
|
||||
draftStr === '' || draftStr == null ? BODY_CHART_DAYS_DEFAULT : draftStr
|
||||
)
|
||||
const clamped = normalizeBodyChartDays(
|
||||
draftStr === '' || draftStr == null ? BODY_CHART_DAYS_DEFAULT : draftStr
|
||||
)
|
||||
return {
|
||||
...baseLayout,
|
||||
widgets: baseLayout.widgets.map((x) =>
|
||||
@@ -156,8 +152,8 @@ export default function DashboardLabPage() {
|
||||
</h1>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.6, marginTop: 8 }}>
|
||||
Widget-System: Katalog, Registry, Renderer; optional pro Widget <code>config</code> (z. B.{' '}
|
||||
<strong>Körper</strong>, <strong>Aktivität</strong>, <strong>KPI Ø-Kalorien</strong>: 7–90 Tage). Layout pro
|
||||
Profil in der DB —
|
||||
<strong>Körper</strong> / <strong>Aktivität</strong>: Zeitraum 7–90 Tage; <strong>KPI</strong>: Kacheln
|
||||
wählen & sortieren). Layout pro Profil in der DB —
|
||||
getrennt vom Produktiv-Dashboard.
|
||||
Vergleich:{' '}
|
||||
<Link to="/pilot/viz" style={{ color: 'var(--accent)' }}>
|
||||
@@ -189,11 +185,10 @@ export default function DashboardLabPage() {
|
||||
<ul style={{ listStyle: 'none', padding: 0, margin: '0 0 12px' }}>
|
||||
{layout.widgets.map((w, i) => {
|
||||
const label = metaById[w.id]?.title || w.id
|
||||
const chartDaysFallback = w.id === 'kpi_board' ? KPI_KCAL_WINDOW_DEFAULT : BODY_CHART_DAYS_DEFAULT
|
||||
const chartDaysVal =
|
||||
w.config?.chart_days != null
|
||||
? normalizeBodyChartDays(w.config.chart_days)
|
||||
: chartDaysFallback
|
||||
: BODY_CHART_DAYS_DEFAULT
|
||||
return (
|
||||
<li
|
||||
key={w.id}
|
||||
@@ -239,14 +234,34 @@ export default function DashboardLabPage() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{w.id === 'kpi_board' && (
|
||||
<KpiBoardConfigEditor
|
||||
tiles={Object.prototype.hasOwnProperty.call(w.config || {}, 'tiles') ? w.config.tiles : undefined}
|
||||
onChange={(next) =>
|
||||
setLayout((L) =>
|
||||
normalizeLayoutForEditor({
|
||||
...L,
|
||||
widgets: L.widgets.map((x, j) => {
|
||||
if (j !== i) return x
|
||||
const cfg = { ...(x.config || {}) }
|
||||
if (next === undefined) {
|
||||
delete cfg.tiles
|
||||
} else {
|
||||
cfg.tiles = next
|
||||
}
|
||||
return { ...x, config: cfg }
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{CHART_DAYS_WIDGET_IDS.has(w.id) && (
|
||||
<div style={{ marginTop: 10, marginLeft: 28 }}>
|
||||
<label style={{ fontSize: 12, color: 'var(--text2)', display: 'block', marginBottom: 4 }}>
|
||||
{w.id === 'body_overview'
|
||||
? 'Körper-Chart'
|
||||
: w.id === 'activity_overview'
|
||||
? 'Aktivität (Verteilung & Konsistenz)'
|
||||
: 'KPI Ø-Kalorien (Ernährung)'}{' '}
|
||||
: 'Aktivität (Verteilung & Konsistenz)'}{' '}
|
||||
— Zeitraum (Tage): {BODY_CHART_DAYS_MIN}–{BODY_CHART_DAYS_MAX}
|
||||
</label>
|
||||
<input
|
||||
@@ -258,9 +273,7 @@ export default function DashboardLabPage() {
|
||||
aria-label={
|
||||
w.id === 'body_overview'
|
||||
? 'Körper-Chart Zeitraum in Tagen'
|
||||
: w.id === 'activity_overview'
|
||||
? 'Aktivität Zeitraum in Tagen'
|
||||
: 'KPI Ø-Kalorien Fenster in Tagen'
|
||||
: 'Aktivität Zeitraum in Tagen'
|
||||
}
|
||||
value={
|
||||
chartDaysDraftByWidgetId[w.id] !== undefined
|
||||
|
||||
Reference in new issue
Block a user