feat: Enhance Dashboard-Lab with widget catalog integration and layout updates
Deploy Development / deploy (push) Successful in 46s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

- Integrated a new API endpoint for fetching the widget catalog in the Dashboard-Lab.
- Updated the dashboard layout schema to utilize the widget catalog for dynamic widget management.
- Refactored DashboardLabPage and PilotVizPage to leverage the new widget rendering system.
- Removed deprecated widget metadata from the frontend, streamlining the widget management process.
- Bumped app_dashboard version to 1.1.0 to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-04-07 11:47:16 +02:00
1 parent e5f6e6c10d
commit f6c5f96768
13 files changed
+275 -99

No files matched your search

@@ -0,0 +1,60 @@
/** @typedef {{ refreshTick: number, requestRefresh: () => void }} WidgetRenderContext */
const registry = new Map()
/**
* @param {{ id: string, Component: import('react').ComponentType<any>, mapProps?: (ctx: WidgetRenderContext) => Record<string, unknown> }} spec
*/
export function registerDashboardWidget(spec) {
if (!spec?.id || !spec?.Component) {
console.warn('registerDashboardWidget: id und Component erforderlich', spec)
return
}
registry.set(spec.id, spec)
}
export function getRegisteredWidgetIds() {
return [...registry.keys()]
}
export function clearDashboardWidgetRegistry() {
registry.clear()
}
/**
* Nur für Tests: Registry neu füllen.
*/
export function __resetDashboardWidgetRegistryForTests() {
registry.clear()
}
/**
* @param {string} id
* @param {WidgetRenderContext} ctx
*/
export function renderRegisteredWidget(id, ctx) {
const spec = registry.get(id)
if (!spec) {
return (
<div key={id} className="card" style={{ borderColor: 'var(--danger, #D85A30)', marginBottom: 16 }}>
<strong>Unbekanntes Widget</strong>
<div style={{ fontSize: 13, color: 'var(--text2)' }}>{id}</div>
</div>
)
}
const { Component } = spec
const props = spec.mapProps ? spec.mapProps(ctx) : {}
return <Component key={id} {...props} />
}
/**
* Rendert alle aktivierten Widgets in Layout-Reihenfolge.
* @param {{ version: number, widgets: Array<{ id: string, enabled: boolean }> }} layout
* @param {WidgetRenderContext} ctx
*/
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))}</>
}
@@ -0,0 +1,15 @@
/**
* Standard-Layout v1 (nur Pilot-Fallback ohne API).
* Reihenfolge: gleich backend/widget_catalog.WIDGET_CATALOG bei Änderung dort mitpflegen
* (oder später nur noch aus GET /api/app/dashboard-layout default_layout beziehen).
*/
export const DEFAULT_LAB_LAYOUT = {
version: 1,
widgets: [
{ id: 'welcome', enabled: true },
{ id: 'quick_capture', enabled: true },
{ id: 'kpi_board', enabled: true },
{ id: 'body_overview', enabled: true },
{ id: 'activity_overview', enabled: true },
],
}
+16
View File
@@ -0,0 +1,16 @@
export function moveWidget(layout, index, delta) {
const next = [...layout.widgets]
const j = index + delta
if (j < 0 || j >= next.length) return layout
const t = next[index]
next[index] = next[j]
next[j] = t
return { ...layout, widgets: next }
}
export function toggleWidget(layout, index) {
const next = layout.widgets.map((w, i) => (i === index ? { ...w, enabled: !w.enabled } : w))
const anyOn = next.some((w) => w.enabled)
if (!anyOn) return layout
return { ...layout, widgets: next }
}
@@ -0,0 +1,47 @@
/**
* Pilot/Lab-Widgets registrieren. IDs müssen zu backend/widget_catalog.WIDGET_CATALOG passen.
*/
import PilotWelcome from '../components/pilot/PilotWelcome'
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 { registerDashboardWidget } from './dashboardWidgetRegistry'
let _registered = false
export function ensurePilotLabWidgetsRegistered() {
if (_registered) return
_registered = true
registerDashboardWidget({
id: 'welcome',
Component: PilotWelcome,
mapProps: () => ({}),
})
registerDashboardWidget({
id: 'quick_capture',
Component: PilotQuickCapture,
mapProps: (ctx) => ({ onSaved: ctx.requestRefresh }),
})
registerDashboardWidget({
id: 'kpi_board',
Component: PilotKpiBoard,
mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
})
registerDashboardWidget({
id: 'body_overview',
Component: PilotBodySection,
mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
})
registerDashboardWidget({
id: 'activity_overview',
Component: PilotActivitySection,
mapProps: (ctx) => ({ refreshTick: ctx.refreshTick }),
})
}
/** @internal Nur für Tests */
export function __resetPilotLabRegistrationForTests() {
_registered = false
}