|
| 1 | +import { useState } from 'react'; |
| 2 | +import { useParams } from 'react-router-dom'; |
| 3 | +import { ReportViewer } from '@object-ui/plugin-dashboard'; |
| 4 | +import { Empty, EmptyTitle, EmptyDescription, Button } from '@object-ui/components'; |
| 5 | +import { Code2 } from 'lucide-react'; |
| 6 | +import appConfig from '../../objectstack.shared'; |
| 7 | + |
| 8 | +export function ReportView() { |
| 9 | + const { reportName } = useParams<{ reportName: string }>(); |
| 10 | + const [showDebug, setShowDebug] = useState(false); |
| 11 | + |
| 12 | + // Find report definition in config |
| 13 | + // Note: we need to cast appConfig because reports might not be in the strict type yet |
| 14 | + const report = (appConfig as any).reports?.find((r: any) => r.name === reportName); |
| 15 | + |
| 16 | + if (!report) { |
| 17 | + return ( |
| 18 | + <div className="h-full flex items-center justify-center p-8"> |
| 19 | + <Empty> |
| 20 | + <EmptyTitle>Report Not Found</EmptyTitle> |
| 21 | + <EmptyDescription>The report "{reportName}" could not be found.</EmptyDescription> |
| 22 | + </Empty> |
| 23 | + </div> |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | + // Wrap the report definition in the ReportViewer schema |
| 28 | + // The ReportViewer expects a schema property which is of type ReportViewerSchema |
| 29 | + // That schema has a 'report' property which is the actual report definition (ReportSchema) |
| 30 | + const viewerSchema = { |
| 31 | + type: 'report-viewer', |
| 32 | + report: report, // The report definition |
| 33 | + showToolbar: true, |
| 34 | + allowExport: true |
| 35 | + }; |
| 36 | + |
| 37 | + return ( |
| 38 | + <div className="flex flex-col h-full overflow-hidden bg-background"> |
| 39 | + <div className="flex justify-between items-center p-6 border-b shrink-0 bg-muted/10"> |
| 40 | + <div> |
| 41 | + {/* Header is handled by ReportViewer usually, but we can have a page header too */} |
| 42 | + <h1 className="text-lg font-medium text-muted-foreground">Report Viewer</h1> |
| 43 | + </div> |
| 44 | + <Button |
| 45 | + variant={showDebug ? "secondary" : "ghost"} |
| 46 | + size="sm" |
| 47 | + onClick={() => setShowDebug(!showDebug)} |
| 48 | + className="gap-2" |
| 49 | + > |
| 50 | + <Code2 className="h-4 w-4" /> |
| 51 | + Metadata |
| 52 | + </Button> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div className="flex-1 overflow-hidden flex flex-row relative"> |
| 56 | + <div className="flex-1 overflow-auto p-8 bg-muted/5"> |
| 57 | + <div className="max-w-5xl mx-auto shadow-sm border rounded-xl bg-background overflow-hidden min-h-[600px]"> |
| 58 | + <ReportViewer schema={viewerSchema} /> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + |
| 62 | + {showDebug && ( |
| 63 | + <div className="w-[400px] border-l bg-muted/30 p-0 overflow-hidden flex flex-col shrink-0 shadow-xl z-20 transition-all"> |
| 64 | + <div className="p-3 border-b bg-muted/50 font-semibold text-sm flex items-center justify-between"> |
| 65 | + <span>Metadata Inspector</span> |
| 66 | + <span className="text-xs text-muted-foreground">JSON Protocol</span> |
| 67 | + </div> |
| 68 | + <div className="flex-1 overflow-auto p-4 space-y-6"> |
| 69 | + <div> |
| 70 | + <h4 className="text-xs font-bold uppercase text-muted-foreground mb-2">Report Configuration</h4> |
| 71 | + <div className="relative rounded-md border bg-slate-950 text-slate-50 overflow-hidden"> |
| 72 | + <pre className="text-xs p-3 overflow-auto max-h-[800px]"> |
| 73 | + {JSON.stringify(report, null, 2)} |
| 74 | + </pre> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + )} |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + ); |
| 83 | +} |
0 commit comments