/* * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL */ import { lazy, Suspense, useEffect, type ComponentType, type ReactNode } from 'react'; import { useSchemaStore } from '@/stores/schemaStore'; import { useCacheStore } from '@/stores/cacheStore'; import { useAccountStore } from '@/stores/accountStore'; import { resolveObject } from '@/lib/schemaResolver'; import { DynamicList } from '@/components/lists/DynamicList'; import { DynamicForm } from '@/components/forms/DynamicForm'; import { DynamicViewPage } from '@/components/views/DynamicViewPage'; import { LoadingFallback } from '@/components/common/LoadingFallback'; import type { Schema } from '@/types/schema'; function lazyFeature(load: () => Promise, select: (module: M) => ComponentType

) { return lazy(() => load().then((module) => ({ default: select(module) }))); } const DashboardView = lazyFeature( () => import('@/features/dashboard/components/DashboardView'), (m) => m.DashboardView, ); const DeliveryTracePage = lazyFeature( () => import('@/features/troubleshoot/DeliveryTracePage'), (m) => m.DeliveryTracePage, ); const LiveTracingPage = lazyFeature( () => import('@/features/tracing/components/LiveTracingPage'), (m) => m.LiveTracingPage, ); const TraceDetailView = lazyFeature( () => import('@/features/tracing/components/TraceDetailView'), (m) => m.TraceDetailView, ); const ActionPage = lazyFeature( () => import('@/features/actions/ActionPage'), (m) => m.ActionPage, ); interface MainContentProps { viewName?: string; id?: string; section?: string; } export function MainContent({ viewName, id, section }: MainContentProps) { const schema = useSchemaStore((s) => s.schema); const invalidateAllObjectLists = useCacheStore((s) => s.invalidateAllObjectLists); useEffect(() => { invalidateAllObjectLists(); }, [viewName, invalidateAllObjectLists]); return }>{renderView(schema, viewName, id, section)}; } function renderView(schema: Schema | null, viewName?: string, id?: string, section?: string): ReactNode { if (!viewName) { return (

Select a view from the sidebar.
); } if (viewName.startsWith('Dashboard/')) { const dashboardId = viewName.slice('Dashboard/'.length); return ; } if (viewName.startsWith('CustomComponent/')) { const componentName = viewName.slice('CustomComponent/'.length); if (componentName === 'Dashboard') { const firstId = schema?.dashboards?.[0]?.id ?? 'overview'; return ; } if (componentName === 'LiveDelivery') { return ; } if (componentName === 'LiveTracing') { return ; } return (
Unknown component: {componentName}
); } if (!schema) { return
Loading...
; } const resolved = resolveObject(schema, viewName); if (!resolved) { return
Unknown view: {viewName}
; } if (resolved.objectName === 'x:Action') { return ; } if (resolved.objectType.type === 'singleton') { return ; } if (id === 'new') { return ; } if (id) { if (resolved.objectName === 'x:Trace') { return ; } const canUpdate = useAccountStore.getState().hasObjectPermission(resolved.permissionPrefix, 'Update'); if (!canUpdate) { return ; } return ; } return ; }