Files
supabase/apps/studio/components/interfaces/ExplainVisualizer/ExplainVisualizer.tsx
kemal.earth 46cf0d37d8 fix(studio): explain tab scroll area and small improvements (#41713)
* fix: add extra slack to bottom of explain scroll area

* chore: match styling of total time to other inline stats

* feat: tidy up explain visualizer header for space

* fix: small syntax fix

* fix: divide instead of border bottom for rows
2026-01-05 15:39:24 +00:00

51 lines
1.6 KiB
TypeScript

import { useMemo } from 'react'
import { ExplainHeader } from './ExplainVisualizer.Header'
import { ExplainNodeRow } from './ExplainVisualizer.NodeRow'
import { calculateMaxDuration, calculateSummary, createNodeTree } from './ExplainVisualizer.parser'
import type { QueryPlanRow } from './ExplainVisualizer.types'
export interface ExplainVisualizerProps {
rows: readonly QueryPlanRow[]
onShowRaw?: () => void
id?: string
}
export function ExplainVisualizer({ rows, onShowRaw, id }: ExplainVisualizerProps) {
const parsedTree = useMemo(() => createNodeTree(rows), [rows])
const maxDuration = useMemo(() => calculateMaxDuration(parsedTree), [parsedTree])
const summary = useMemo(() => calculateSummary(parsedTree), [parsedTree])
if (parsedTree.length === 0) {
return (
<div className="bg-studio">
<p className="m-0 border-0 px-4 py-3 font-mono text-sm text-foreground-light">
No execution plan data available
</p>
</div>
)
}
return (
<div className="bg-studio h-full flex flex-col min-h-0">
{onShowRaw && (
<ExplainHeader
mode="visual"
onToggleMode={onShowRaw}
summary={summary}
id={id}
rows={rows}
/>
)}
{/* Plan nodes */}
<div className="flex-1 overflow-auto min-h-0">
<div className="flex flex-col min-w-max pb-1 divide-y divide-border-muted">
{parsedTree.map((node, idx) => (
<ExplainNodeRow key={idx} node={node} depth={0} maxDuration={maxDuration} />
))}
</div>
</div>
</div>
)
}