feat: Enhance Dashboard-Lab with widget catalog integration and layout updates
- 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:
1 parent
e5f6e6c10d
commit
f6c5f96768
13 files changed
+275
-99
No files matched your search
@@ -2,45 +2,34 @@ 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 { DASHBOARD_LAB_WIDGET_META } from '../app/areas/dashboardLab/dashboardLabWidgets'
|
||||
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 { WidgetRenderer } from '../widgetSystem/dashboardWidgetRegistry'
|
||||
import { ensurePilotLabWidgetsRegistered } from '../widgetSystem/registerPilotLabWidgets'
|
||||
import { moveWidget, toggleWidget } from '../widgetSystem/layoutEditor'
|
||||
|
||||
const metaById = Object.fromEntries(DASHBOARD_LAB_WIDGET_META.map((m) => [m.id, m]))
|
||||
|
||||
function moveWidget(layout, index, delta) {
|
||||
const next = [...layout.widgets]
|
||||
const j = index + delta
|
||||
if (j < 0 || j >= next.length) return layout
|
||||
;[next[index], next[j]] = [next[j], next[index]]
|
||||
return { ...layout, widgets: next }
|
||||
}
|
||||
|
||||
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 }
|
||||
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 bump = () => setRefreshTick((t) => t + 1)
|
||||
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 b = await api.getAppDashboardLayout()
|
||||
const [cat, b] = await Promise.all([api.getAppWidgetsCatalog(), api.getAppDashboardLayout()])
|
||||
setCatalog(cat)
|
||||
setBundle(b)
|
||||
setLayout(b.layout)
|
||||
} catch (e) {
|
||||
@@ -92,23 +81,6 @@ export default function DashboardLabPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const renderWidget = (id) => {
|
||||
switch (id) {
|
||||
case 'welcome':
|
||||
return <PilotWelcome key="welcome" />
|
||||
case 'quick_capture':
|
||||
return <PilotQuickCapture key="quick_capture" onSaved={bump} />
|
||||
case 'kpi_board':
|
||||
return <PilotKpiBoard key="kpi_board" refreshTick={refreshTick} />
|
||||
case 'body_overview':
|
||||
return <PilotBodySection key="body_overview" refreshTick={refreshTick} />
|
||||
case 'activity_overview':
|
||||
return <PilotActivitySection key="activity_overview" refreshTick={refreshTick} />
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
if (err && !layout) {
|
||||
return (
|
||||
<div style={{ padding: 24, maxWidth: 640, margin: '0 auto' }}>
|
||||
@@ -128,8 +100,6 @@ export default function DashboardLabPage() {
|
||||
)
|
||||
}
|
||||
|
||||
const enabledOrder = layout.widgets.filter((w) => w.enabled)
|
||||
|
||||
return (
|
||||
<div style={{ paddingBottom: 96, textAlign: 'left', maxWidth: 920, margin: '0 auto' }}>
|
||||
<div style={{ marginBottom: 20 }}>
|
||||
@@ -145,10 +115,10 @@ export default function DashboardLabPage() {
|
||||
App-Bereich: Dashboard-Lab
|
||||
</h1>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', lineHeight: 1.6, marginTop: 8 }}>
|
||||
Geschützte Route (Login erforderlich). Widget-Reihenfolge und Sichtbarkeit werden pro Profil in der
|
||||
Datenbank gespeichert — getrennt vom Produktiv-Dashboard. Vergleich:{' '}
|
||||
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:{' '}
|
||||
<Link to="/pilot/viz" style={{ color: 'var(--accent)' }}>
|
||||
Pilot-Übersicht (festes Layout)
|
||||
Pilot-Übersicht (festes Standard-Layout)
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
@@ -171,15 +141,11 @@ export default function DashboardLabPage() {
|
||||
Status: {bundle.custom ? 'individuell gespeichert' : 'Standard (nicht in DB)'}
|
||||
</p>
|
||||
)}
|
||||
{err && (
|
||||
<p style={{ fontSize: 12, color: '#D85A30', marginBottom: 8 }}>{err}</p>
|
||||
)}
|
||||
{msg && (
|
||||
<p style={{ fontSize: 12, color: 'var(--accent)', marginBottom: 8 }}>{msg}</p>
|
||||
)}
|
||||
{err && <p style={{ fontSize: 12, color: '#D85A30', marginBottom: 8 }}>{err}</p>}
|
||||
{msg && <p style={{ fontSize: 12, color: 'var(--accent)', marginBottom: 8 }}>{msg}</p>}
|
||||
<ul style={{ listStyle: 'none', padding: 0, margin: '0 0 12px' }}>
|
||||
{layout.widgets.map((w, i) => {
|
||||
const label = metaById[w.id]?.label || w.id
|
||||
const label = metaById[w.id]?.title || w.id
|
||||
return (
|
||||
<li
|
||||
key={w.id}
|
||||
@@ -237,7 +203,7 @@ export default function DashboardLabPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{enabledOrder.map((w) => renderWidget(w.id))}
|
||||
<WidgetRenderer layout={layout} refreshTick={refreshTick} requestRefresh={requestRefresh} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,21 +1,19 @@
|
||||
import { useState } from 'react'
|
||||
import { FlaskConical } from 'lucide-react'
|
||||
import { Link } from 'react-router-dom'
|
||||
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 { WidgetRenderer } from '../widgetSystem/dashboardWidgetRegistry'
|
||||
import { ensurePilotLabWidgetsRegistered } from '../widgetSystem/registerPilotLabWidgets'
|
||||
import { DEFAULT_LAB_LAYOUT } from '../widgetSystem/defaultLabLayout'
|
||||
|
||||
/**
|
||||
* Pilot-Übersicht nach Product-Spec:
|
||||
* Willkommen → Schnelleingabe (Gewicht + Vitalwerte) → KPIs (Referenzen + KF% + Ø kcal, max. 9)
|
||||
* → Bereich Körper (Gewicht-Chart 30 T, Ø7/Ø14, Bewertung wie Verlauf)
|
||||
* → Bereich Aktivität (Trainingstyp 30 T, Konsistenz).
|
||||
* Pilot-Übersicht nach Product-Spec (festes Standard-Layout).
|
||||
* Nutzt dasselbe Widget-Rendering wie /app/dashboard-lab.
|
||||
*/
|
||||
export default function PilotVizPage() {
|
||||
ensurePilotLabWidgetsRegistered()
|
||||
|
||||
const [refreshTick, setRefreshTick] = useState(0)
|
||||
const bump = () => setRefreshTick((t) => t + 1)
|
||||
const requestRefresh = () => setRefreshTick((t) => t + 1)
|
||||
|
||||
return (
|
||||
<div style={{ paddingBottom: 96, textAlign: 'left', maxWidth: 920, margin: '0 auto' }}>
|
||||
@@ -37,11 +35,11 @@ export default function PilotVizPage() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<PilotWelcome />
|
||||
<PilotQuickCapture onSaved={bump} />
|
||||
<PilotKpiBoard refreshTick={refreshTick} />
|
||||
<PilotBodySection refreshTick={refreshTick} />
|
||||
<PilotActivitySection refreshTick={refreshTick} />
|
||||
<WidgetRenderer
|
||||
layout={DEFAULT_LAB_LAYOUT}
|
||||
refreshTick={refreshTick}
|
||||
requestRefresh={requestRefresh}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user