3 Commits

3 changed files with 120 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
"use client"
import * as React from "react"
import { FileText, ChevronDown, ChevronRight, X, Copy } from "lucide-react"
import { FileText, ChevronDown, ChevronRight, X, Copy, Radio } from "lucide-react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
@@ -84,6 +84,8 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
/>
</>
)}
<RealtimeDocCard table={table} />
</div>
</ScrollArea>
</div>
@@ -92,6 +94,121 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
)
}
// Realtime (SSE) documentation: connect and update topics for this entity
function RealtimeDocCard({ table }: { table: TableMetadata }) {
const [isOpen, setIsOpen] = React.useState(false)
const entityName = table.schema.name
const baseUrl = "https://your-api.com"
const sampleRowId = "019c1b81-364b-7000-8120-b5416b2c42c2"
const connectExample = `# Connect to SSE: subscribe to this entity (all rows) and/or a specific row
# Topics: entity name only, or entity:row_id for a single row
curl -N -H "Authorization: Bearer YOUR_TOKEN" \\
"${baseUrl}/api/v1/realtime?topics=${entityName}"
# Subscribe to entity + a specific row (comma-separated)
curl -N -H "Authorization: Bearer YOUR_TOKEN" \\
"${baseUrl}/api/v1/realtime?topics=${entityName},${entityName}:${sampleRowId}"`
const updateTopicsExample = `# Update topics for an existing SSE session (from the "connected" event client_id)
curl -X POST "${baseUrl}/api/v1/realtime" \\
-H "Authorization: Bearer YOUR_TOKEN" \\
-H "Content-Type: application/json" \\
-d '{
"client_id": "sse_1769987962000_0abc1",
"topics": ["${entityName}", "${entityName}:${sampleRowId}"]
}'
# Clear topics to disconnect
curl -X POST "${baseUrl}/api/v1/realtime" \\
-H "Authorization: Bearer YOUR_TOKEN" \\
-H "Content-Type: application/json" \\
-d '{"client_id": "sse_1769987962000_0abc1", "topics": []}'`
const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text)
}
return (
<Collapsible open={isOpen} onOpenChange={setIsOpen}>
<CollapsibleTrigger asChild>
<div className="p-4 border rounded-lg cursor-pointer hover:bg-muted/50 transition-colors">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<Radio className="h-4 w-4 text-muted-foreground" />
<span className="font-medium">Realtime (SSE)</span>
{isOpen ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}
</div>
</div>
<p className="text-sm text-muted-foreground mt-2">
Subscribe to database changes for this entity (all rows) or a specific row. Connect via GET, then update topics via POST.
</p>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="border-l-2 border-muted ml-4 pl-6 space-y-6 mt-4">
<div>
<h5 className="font-medium mb-1">Connect to SSE</h5>
<p className="text-sm text-muted-foreground mb-2">
Open a long-lived SSE stream. Use <code className="bg-muted px-1 rounded">topics</code> query param: entity name (e.g. <code className="bg-muted px-1 rounded">{entityName}</code>) for all rows, or <code className="bg-muted px-1 rounded">{entityName}:row_id</code> for a single row. Multiple topics are comma-separated.
</p>
<div className="flex justify-end mb-2">
<Button variant="outline" size="sm" onClick={() => copyToClipboard(connectExample)} className="h-8">
<Copy className="h-3 w-3 mr-1" />
Copy
</Button>
</div>
<ScrollArea className="h-40">
<pre className="bg-muted p-4 rounded text-sm border whitespace-pre">
<code>{connectExample}</code>
</pre>
</ScrollArea>
</div>
<div>
<h5 className="font-medium mb-1">Update topics to monitor</h5>
<p className="text-sm text-muted-foreground mb-2">
POST with <code className="bg-muted px-1 rounded">client_id</code> from the <code className="bg-muted px-1 rounded">connected</code> event and a new <code className="bg-muted px-1 rounded">topics</code> array. Send <code className="bg-muted px-1 rounded">topics: []</code> to disconnect.
</p>
<div className="flex justify-end mb-2">
<Button variant="outline" size="sm" onClick={() => copyToClipboard(updateTopicsExample)} className="h-8">
<Copy className="h-3 w-3 mr-1" />
Copy
</Button>
</div>
<ScrollArea className="h-48">
<pre className="bg-muted p-4 rounded text-sm border whitespace-pre">
<code>{updateTopicsExample}</code>
</pre>
</ScrollArea>
</div>
<div>
<h5 className="font-medium mb-2">SSE event types</h5>
<div className="grid grid-cols-1 gap-2 text-sm">
<div className="flex items-center gap-2">
<Badge variant="secondary" className="text-xs">connected</Badge>
<span>Sent once when the stream opens; includes <code className="bg-muted px-1 rounded">client_id</code> and <code className="bg-muted px-1 rounded">topics</code>.</span>
</div>
<div className="flex items-center gap-2">
<Badge variant="secondary" className="text-xs">ping</Badge>
<span>Keep-alive sent periodically.</span>
</div>
<div className="flex items-center gap-2">
<Badge variant="secondary" className="text-xs">change</Badge>
<span>Database change: <code className="bg-muted px-1 rounded">action</code> (insert/update/delete), <code className="bg-muted px-1 rounded">entity</code>, <code className="bg-muted px-1 rounded">row_id</code>, <code className="bg-muted px-1 rounded">data</code> (row payload or null for delete).</span>
</div>
</div>
</div>
<div className="text-sm text-muted-foreground">
<p>
Access uses the same rules as entity <strong>list</strong> (topic = entity name) and <strong>get</strong> (topic = entity:row_id). In browsers, <code className="bg-muted px-1 rounded">EventSource</code> cannot send <code className="bg-muted px-1 rounded">Authorization</code>; use <code className="bg-muted px-1 rounded">fetch()</code> with the same URL and headers, then read the body as a stream to process SSE events.
</p>
</div>
</div>
</CollapsibleContent>
</Collapsible>
)
}
function ApiEndpointCard({
method,
endpoint,

View File

@@ -57,7 +57,7 @@ export function LogsSection({ apiClient }: LogsSectionProps) {
const [totalCount, setTotalCount] = React.useState<number>(-1) // -1 means unknown
const [searchTerm, setSearchTerm] = React.useState("")
const [levelFilter, setLevelFilter] = React.useState<string>("all") // Exact level filter
const [minLevelFilter, setMinLevelFilter] = React.useState<string>("trace") // Minimum level filter (default)
const [minLevelFilter, setMinLevelFilter] = React.useState<string>("info") // Minimum level filter (default: info+)
const [useMinLevel, setUseMinLevel] = React.useState<boolean>(true) // Use minimum level by default
const [selectedLog, setSelectedLog] = React.useState<LogEntry | null>(null)
const [drawerOpen, setDrawerOpen] = React.useState(false)

View File

@@ -1,6 +1,6 @@
{
"name": "mantisbase-admin",
"version": "0.3.6",
"version": "0.3.7",
"private": true,
"scripts": {
"export": "next build && next export",