import { useCallback, useEffect, useState } from 'react' import { ChevronDown, ChevronUp, LayoutGrid } from 'lucide-react' 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' function catalogMetaById(catalog) { if (!catalog?.widgets?.length) return {} return Object.fromEntries(catalog.widgets.map((w) => [w.id, w])) } export default function DashboardLabPage() { ensurePilotLabWidgetsRegistered() const [refreshTick, setRefreshTick] = useState(0) const requestRefresh = () => setRefreshTick((t) => t + 1) const [catalog, setCatalog] = useState(null) const [bundle, setBundle] = useState(null) const [layout, setLayout] = useState(null) const [err, setErr] = useState(null) const [busy, setBusy] = useState(false) const [msg, setMsg] = useState(null) const metaById = catalogMetaById(catalog) const load = useCallback(async () => { setErr(null) try { const [cat, b] = await Promise.all([api.getAppWidgetsCatalog(), api.getAppDashboardLayout()]) setCatalog(cat) setBundle(b) setLayout(b.layout) } catch (e) { setErr(formatFastApiDetail(null, e.message)) } }, []) useEffect(() => { load() }, [load]) const save = async () => { if (!layout) return setBusy(true) setMsg(null) setErr(null) try { await api.putAppDashboardLayout(layout) setMsg('Layout gespeichert.') await load() } catch (e) { setErr(formatFastApiDetail(null, e.message)) } finally { setBusy(false) } } const reset = async () => { if (!confirm('Persönliches Layout löschen und Standard wiederherstellen?')) return setBusy(true) setMsg(null) setErr(null) try { const r = await api.resetAppDashboardLayout() setLayout(r.layout) setMsg('Auf Standard zurückgesetzt.') await load() } catch (e) { setErr(formatFastApiDetail(null, e.message)) } finally { setBusy(false) } } const applyDefaultLocal = () => { if (bundle?.default_layout) { setLayout(structuredClone(bundle.default_layout)) setMsg('Standard geladen (noch nicht gespeichert).') } } if (err && !layout) { return (
{err}
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:{' '} Pilot-Übersicht (festes Standard-Layout) .
Status: {bundle.custom ? 'individuell gespeichert' : 'Standard (nicht in DB)'}
)} {err &&{err}
} {msg &&{msg}
}