feat: Refactor PilotVizPage and widget registry for improved layout and rendering
Deploy Development / deploy (push) Successful in 54s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s

- Replaced the previous widget retrieval method with a new layout-based approach in PilotVizPage.
- Introduced a PilotVizAdminCard for layout configuration and management.
- Updated widget definitions in the registry to include new components and default order.
- Enhanced user feedback for widget visibility with a message when no widgets are active.
This commit is contained in:
Lars committed 2026-04-07 10:21:11 +02:00
1 parent 932bceb1e1
commit 8c8f595385
6 files changed
+398 -26

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
/**
* Pilot-Layout: nur lokal (localStorage), kein Server.
* Dient zum Testen von Sichtbarkeit und Reihenfolge vor einer DB-Lösung.
*/
import { PILOT_WIDGET_DEFS, PILOT_WIDGET_IDS_DEFAULT_ORDER } from './widgetRegistry'
const STORAGE_KEY = 'mitai_pilot_viz_layout_v1'
function defaultLayout() {
const order = [...PILOT_WIDGET_IDS_DEFAULT_ORDER]
const enabled = Object.fromEntries(order.map((id) => [id, true]))
return { version: 1, order, enabled}
}
function mergeWithRegistry(saved) {
if (!saved || typeof saved !== 'object') return defaultLayout()
const known = new Set(Object.keys(PILOT_WIDGET_DEFS))
let order = Array.isArray(saved.order) ? saved.order.filter((id) => known.has(id)) : []
for (const id of PILOT_WIDGET_IDS_DEFAULT_ORDER) {
if (!order.includes(id)) order.push(id)
}
const enabled = { ...defaultLayout().enabled, ...(saved.enabled && typeof saved.enabled === 'object' ? saved.enabled : {}) }
for (const id of Object.keys(PILOT_WIDGET_DEFS)) {
if (typeof enabled[id] !== 'boolean') enabled[id] = true
}
return { version: 1, order, enabled }
}
export function loadPilotLayout() {
try {
const raw = localStorage.getItem(STORAGE_KEY)
if (!raw) return defaultLayout()
return mergeWithRegistry(JSON.parse(raw))
} catch {
return defaultLayout()
}
}
export function savePilotLayout(layout) {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(layout))
} catch {
/* ignore quota */
}
}
export function resetPilotLayout() {
const d = defaultLayout()
savePilotLayout(d)
return d
}
+24 -6
View File
@@ -1,20 +1,38 @@
import ReferenceValuesSummaryWidget from '../components/pilot/ReferenceValuesSummaryWidget'
import GoalsSnapshotWidget from '../components/pilot/GoalsSnapshotWidget'
import WeightKpiWidget from '../components/pilot/WeightKpiWidget'
/**
* Pilot: konfigurierbare Widget-Reihenfolge (Layer 3b-Vorspiel).
* Nur für /pilot/viz – produktives Dashboard bleibt unverändert.
* Pilot: Widget-Registry (Layer 3b-Vorspiel).
* Reihenfolge-Default: PILOT_WIDGET_IDS_DEFAULT_ORDER
*/
export const PILOT_WIDGET_ORDER = ['reference_values_summary']
export const PILOT_WIDGET_IDS_DEFAULT_ORDER = ['weight_kpi', 'goals_teaser', 'reference_values_summary']
export const PILOT_WIDGET_DEFS = {
weight_kpi: {
id: 'weight_kpi',
title: 'Gewicht (KPI)',
description: 'Letzter Eintrag und Delta zum vorherigen Messwert (API weight/stats).',
Component: WeightKpiWidget,
},
goals_teaser: {
id: 'goals_teaser',
title: 'Strategische Ziele',
description: 'Anzahl aktiver Ziele, Link zur Ziele-Seite (API goals/list).',
Component: GoalsSnapshotWidget,
},
reference_values_summary: {
id: 'reference_values_summary',
title: 'Referenzwerte',
description: 'Aktuellste Kennwerte pro Typ (Daten via Layer 1 → bestehende API).',
description: 'Aktuellste Kennwerte pro Typ (Layer 1 → /profile-reference-values/summary).',
Component: ReferenceValuesSummaryWidget,
},
}
export function getPilotWidgetsInOrder() {
return PILOT_WIDGET_ORDER.map((id) => PILOT_WIDGET_DEFS[id]).filter(Boolean)
/** Sichtbare Widgets in gespeicherter Reihenfolge (für Render). */
export function resolvePilotWidgetsForRender(layout) {
if (!layout?.order) return []
return layout.order
.filter((id) => layout.enabled[id] && PILOT_WIDGET_DEFS[id])
.map((id) => PILOT_WIDGET_DEFS[id])
}