feat: Enhance Dashboard widget configuration and layout management
Deploy Development / deploy (push) Successful in 46s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

- Added validation for widget configuration in the DashboardWidgetEntry model to ensure proper data structure.
- Updated the DashboardLayoutPayload to include widget configuration in the serialized output.
- Improved the PilotBodySection and DashboardLabPage components to support dynamic chart days configuration for the body overview widget.
- Refactored layout editor functions to normalize widget configurations for better handling.
- Bumped app_dashboard version to 1.2.0 to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-04-07 11:58:07 +02:00
1 parent f6c5f96768
commit 87c4cbc4b4
11 files changed
+298 -62

No files matched your search

+92 -37
View File
@@ -4,7 +4,13 @@ import { Link } from 'react-router-dom'
import { api, formatFastApiDetail } from '../utils/api'
import { WidgetRenderer } from '../widgetSystem/dashboardWidgetRegistry'
import { ensurePilotLabWidgetsRegistered } from '../widgetSystem/registerPilotLabWidgets'
import { moveWidget, toggleWidget } from '../widgetSystem/layoutEditor'
import {
BODY_CHART_DAYS_DEFAULT,
BODY_CHART_DAYS_MAX,
BODY_CHART_DAYS_MIN,
normalizeBodyChartDays,
} from '../widgetSystem/bodyChartDays'
import { moveWidget, normalizeLayoutForEditor, toggleWidget } from '../widgetSystem/layoutEditor'
function catalogMetaById(catalog) {
if (!catalog?.widgets?.length) return {}
@@ -31,7 +37,7 @@ export default function DashboardLabPage() {
const [cat, b] = await Promise.all([api.getAppWidgetsCatalog(), api.getAppDashboardLayout()])
setCatalog(cat)
setBundle(b)
setLayout(b.layout)
setLayout(normalizeLayoutForEditor(b.layout))
} catch (e) {
setErr(formatFastApiDetail(null, e.message))
}
@@ -64,7 +70,7 @@ export default function DashboardLabPage() {
setErr(null)
try {
const r = await api.resetAppDashboardLayout()
setLayout(r.layout)
setLayout(normalizeLayoutForEditor(r.layout))
setMsg('Auf Standard zurückgesetzt.')
await load()
} catch (e) {
@@ -76,7 +82,7 @@ export default function DashboardLabPage() {
const applyDefaultLocal = () => {
if (bundle?.default_layout) {
setLayout(structuredClone(bundle.default_layout))
setLayout(normalizeLayoutForEditor(structuredClone(bundle.default_layout)))
setMsg('Standard geladen (noch nicht gespeichert).')
}
}
@@ -115,8 +121,9 @@ export default function DashboardLabPage() {
App-Bereich: Dashboard-Lab
</h1>
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.6, marginTop: 8 }}>
Widget-System (Iteration 1): Katalog vom Server, Registry im Frontend, Renderer für alle
Pilot-Module. Layout wird pro Profil persistiert — getrennt vom Produktiv-Dashboard. Vergleich:{' '}
Widget-System: Katalog, Registry, Renderer; optional pro Widget <code>config</code> (z. B.{' '}
<strong>Körper-Chart</strong> 7–90 Tage). Layout pro Profil in der DB — getrennt vom Produktiv-Dashboard.
Vergleich:{' '}
<Link to="/pilot/viz" style={{ color: 'var(--accent)' }}>
Pilot-Übersicht (festes Standard-Layout)
</Link>
@@ -146,46 +153,94 @@ 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 chartDaysVal =
w.config?.chart_days != null ? normalizeBodyChartDays(w.config.chart_days) : BODY_CHART_DAYS_DEFAULT
return (
<li
key={w.id}
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
flexWrap: 'wrap',
padding: '8px 0',
borderBottom: '1px solid var(--border)',
}}
>
<label style={{ display: 'flex', alignItems: 'center', gap: 8, flex: '1 1 140px' }}>
<input
type="checkbox"
checked={w.enabled}
onChange={() => setLayout((L) => toggleWidget(L, i))}
/>
<span style={{ fontSize: 14 }}>{label}</span>
</label>
<div style={{ display: 'flex', gap: 6 }}>
<button
type="button"
className="btn btn-secondary"
style={{ padding: '6px 10px' }}
aria-label="Nach oben"
onClick={() => setLayout((L) => moveWidget(L, i, -1))}
>
<ChevronUp size={18} />
</button>
<button
type="button"
className="btn btn-secondary"
style={{ padding: '6px 10px' }}
aria-label="Nach unten"
onClick={() => setLayout((L) => moveWidget(L, i, 1))}
>
<ChevronDown size={18} />
</button>
<div
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
flexWrap: 'wrap',
}}
>
<label style={{ display: 'flex', alignItems: 'center', gap: 8, flex: '1 1 140px' }}>
<input
type="checkbox"
checked={w.enabled}
onChange={() => setLayout((L) => toggleWidget(L, i))}
/>
<span style={{ fontSize: 14 }}>{label}</span>
</label>
<div style={{ display: 'flex', gap: 6 }}>
<button
type="button"
className="btn btn-secondary"
style={{ padding: '6px 10px' }}
aria-label="Nach oben"
onClick={() => setLayout((L) => moveWidget(L, i, -1))}
>
<ChevronUp size={18} />
</button>
<button
type="button"
className="btn btn-secondary"
style={{ padding: '6px 10px' }}
aria-label="Nach unten"
onClick={() => setLayout((L) => moveWidget(L, i, 1))}
>
<ChevronDown size={18} />
</button>
</div>
</div>
{w.id === 'body_overview' && (
<div style={{ marginTop: 10, marginLeft: 28 }}>
<label style={{ fontSize: 12, color: 'var(--text2)', display: 'block', marginBottom: 4 }}>
Körper-Chart Zeitraum (Tage): {BODY_CHART_DAYS_MIN}–{BODY_CHART_DAYS_MAX}
</label>
<input
type="number"
className="form-input"
style={{ maxWidth: 120 }}
min={BODY_CHART_DAYS_MIN}
max={BODY_CHART_DAYS_MAX}
value={chartDaysVal}
onChange={(e) => {
const v = parseInt(e.target.value, 10)
setLayout((L) => ({
...L,
widgets: L.widgets.map((x, j) =>
j !== i
? x
: {
...x,
config: {
...x.config,
chart_days: Number.isFinite(v) ? v : BODY_CHART_DAYS_DEFAULT,
},
}
),
}))
}}
onBlur={(e) => {
const clamped = normalizeBodyChartDays(e.target.value)
setLayout((L) => ({
...L,
widgets: L.widgets.map((x, j) =>
j !== i ? x : { ...x, config: { ...x.config, chart_days: clamped } }
),
}))
}}
/>
</div>
)}
</li>
)
})}