Files
supabase/apps/database-new/components/SchemaGraph/SchemaGraph.tsx
T
fbfe910c22 Initial work on database.new visualizer (#19027)
* Initial commit.

* Remove bunch of unneeded deps.

* Fix the providers.

* Minor fixes to make the themes work.

* Fix prettier errors.

* Add default constraint.

* Midway styling

* General styling improvements

* More styling stuff

* Bit more styling

* Bit more pizzazz

* Scaffold all threads modal

* Small style fix

* Ensure loading state persist in new page until redirect

* Fix

* Test';

* Add basic validation

* Fix

* Remove console logs

* Hide show all threads button

* chore: style the blocks

* fix: stroke width

* add some shadow

* stroke width

* Update TableNode.tsx

* Swap hide chat for hide code

* more sidebar styling

* Resolve conflicts

* Some style fixeds

* Some style fixeds

* mock profile

* update user dorpdown

* Update globals.css

* Chore/db new layouts and url params (#19142)

* chore: layouts

* Fix + clean up

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>

* Fix header

* Scaffold profile and conversations

* Some quick styling

* Update apps/database-new/.env.local.example

Co-authored-by: Greg Richardson <greg.nmr@gmail.com>

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Greg Richardson <greg.nmr@gmail.com>
2023-11-22 12:31:32 -03:30

85 lines
2.1 KiB
TypeScript

'use client'
import { PostgresTable } from '@/lib/types'
import { useTheme } from 'next-themes'
import { useEffect, useMemo, useState } from 'react'
import ReactFlow, {
Background,
BackgroundVariant,
ReactFlowProvider,
useReactFlow,
} from 'reactflow'
import 'reactflow/dist/style.css'
import { cn } from 'ui'
import { getGraphDataFromTables } from './SchemaGraph.utils'
import TableNode from './TableNode'
interface SchemaGraphProps {
tables: PostgresTable[]
}
const TablesGraph = ({ tables }: SchemaGraphProps) => {
const { resolvedTheme } = useTheme()
const [mounted, setMounted] = useState(false)
const reactFlowInstance = useReactFlow()
const nodeTypes = useMemo(() => ({ table: TableNode }), [])
useEffect(() => {
setMounted(true)
}, [])
useEffect(() => {
getGraphDataFromTables(tables).then(({ nodes, edges }) => {
reactFlowInstance.setNodes(nodes)
reactFlowInstance.setEdges(edges)
setTimeout(() => reactFlowInstance.fitView({}), 10)
})
}, [tables, resolvedTheme])
return (
<>
<div className={cn('h-full grow')}>
<ReactFlow
defaultNodes={[]}
defaultEdges={[]}
defaultEdgeOptions={{
type: 'smoothstep',
animated: true,
deletable: false,
style: {
stroke: 'hsl(var(--border-stronger))',
strokeWidth: 0.5,
},
}}
nodeTypes={nodeTypes}
minZoom={1}
maxZoom={1.8}
proOptions={{ hideAttribution: true }}
onInit={(instance) => {
instance.fitView()
}}
>
{mounted && (
<Background
gap={16}
className="[&>*]:stroke-foreground-muted opacity-[25%]"
variant={BackgroundVariant.Dots}
color={'inherit'}
/>
)}
</ReactFlow>
</div>
</>
)
}
const SchemaGraph = ({ tables }: SchemaGraphProps) => {
return (
<ReactFlowProvider>
<TablesGraph tables={tables} />
</ReactFlowProvider>
)
}
export default SchemaGraph