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

@@ -0,0 +1,10 @@
/** Körper-Chart: gültiger Bereich (sync mit backend dashboard_widget_config body_overview). */
export const BODY_CHART_DAYS_MIN = 7
export const BODY_CHART_DAYS_MAX = 90
export const BODY_CHART_DAYS_DEFAULT = 30
export function normalizeBodyChartDays(raw) {
const n = Number(raw)
if (!Number.isFinite(n)) return BODY_CHART_DAYS_DEFAULT
return Math.min(BODY_CHART_DAYS_MAX, Math.max(BODY_CHART_DAYS_MIN, Math.round(n)))
}
@@ -1,4 +1,12 @@
/** @typedef {{ refreshTick: number, requestRefresh: () => void }} WidgetRenderContext */
/**
* @typedef {object} LayoutWidgetEntry
* @property {string} id
* @property {boolean} enabled
* @property {Record<string, unknown>} [config]
*/
/**
* @typedef {{ refreshTick: number, requestRefresh: () => void, layoutEntry: LayoutWidgetEntry }} WidgetRenderContext
*/
const registry = new Map()
@@ -49,12 +57,21 @@ export function renderRegisteredWidget(id, ctx) {
/**
* Rendert alle aktivierten Widgets in Layout-Reihenfolge.
* @param {{ version: number, widgets: Array<{ id: string, enabled: boolean }> }} layout
* @param {WidgetRenderContext} ctx
* @param {{ version: number, widgets: Array<LayoutWidgetEntry> }} layout
* @param {{ refreshTick: number, requestRefresh: () => void }} base
*/
export function WidgetRenderer({ layout, refreshTick, requestRefresh }) {
if (!layout?.widgets?.length) return null
const ctx = { refreshTick, requestRefresh }
const enabled = layout.widgets.filter((w) => w.enabled)
return <>{enabled.map((w) => renderRegisteredWidget(w.id, ctx))}</>
return (
<>
{enabled.map((w) =>
renderRegisteredWidget(w.id, {
refreshTick,
requestRefresh,
layoutEntry: w,
})
)}
</>
)
}
+11
View File
@@ -1,3 +1,14 @@
export function normalizeLayoutForEditor(layout) {
if (!layout?.widgets) return layout
return {
...layout,
widgets: layout.widgets.map((w) => ({
...w,
config: w.config && typeof w.config === 'object' ? { ...w.config } : {},
})),
}
}
export function moveWidget(layout, index, delta) {
const next = [...layout.widgets]
const j = index + delta
@@ -6,6 +6,7 @@ import PilotQuickCapture from '../components/pilot/PilotQuickCapture'
import PilotKpiBoard from '../components/pilot/PilotKpiBoard'
import PilotBodySection from '../components/pilot/PilotBodySection'
import PilotActivitySection from '../components/pilot/PilotActivitySection'
import { normalizeBodyChartDays } from './bodyChartDays'
import { registerDashboardWidget } from './dashboardWidgetRegistry'
let _registered = false
@@ -32,7 +33,10 @@ export function ensurePilotLabWidgetsRegistered() {
registerDashboardWidget({
id: 'body_overview',
Component: PilotBodySection,
mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
mapProps: (ctx) => ({
refreshTick: ctx.refreshTick,
chartDays: normalizeBodyChartDays(ctx.layoutEntry?.config?.chart_days),
}),
})
registerDashboardWidget({
id: 'activity_overview',