The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
schema visualizer styles moved to UI package (#19313)
Jonathan Summers-Muir903be591de74
diff --git a/apps/database-new/components/SchemaGraph/TableNode.tsx b/apps/database-new/components/SchemaGraph/TableNode.tsxindex c3fa4c22b49..ed6dd823489 100644--- a/apps/database-new/components/SchemaGraph/TableNode.tsx+++ b/apps/database-new/components/SchemaGraph/TableNode.tsx@@ -1,6 +1,6 @@-import { Diamond, DiamondIcon, Fingerprint, Hash, Key, Table, Table2 } from 'lucide-react'-import { IconHash, IconKey, cn } from 'ui'+import { DiamondIcon, Fingerprint, Hash, Key, Table2 } from 'lucide-react'import { Handle, NodeProps } from 'reactflow'+import { cn } from 'ui'import { NODE_WIDTH } from './SchemaGraph.constants'export type TableNodeData = {diff --git a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsxindex 10bec6ce186..d7afde35073 100644--- a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx+++ b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx@@ -1,28 +1,24 @@import dagre from '@dagrejs/dagre'-import clsx from 'clsx'import { uniqBy } from 'lodash'-import { Diamond, Fingerprint } from 'lucide-react'import { observer } from 'mobx-react-lite'import { useEffect, useMemo } from 'react'import ReactFlow, {Background,BackgroundVariant,Edge,- Handle,MiniMap,Node,- NodeProps,Position,ReactFlowProvider,useReactFlow,} from 'reactflow'import { PostgresTable } from '@supabase/postgres-meta'-import { useTheme } from 'next-themes'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { useTablesQuery } from 'data/tables/tables-query'+import { useTheme } from 'next-themes'import 'reactflow/dist/style.css'-import { IconHash, IconKey, IconLoader, IconLock } from 'ui'+import { IconLoader, TABLE_NODE_ROW_HEIGHT, TABLE_NODE_WIDTH, TableNode } from 'ui'type TableNodeData = {name: string@@ -174,8 +170,8 @@ const getLayoutedElements = (nodes: Node[], edges: Edge[]) => {nodes.forEach((node) => {dagreGraph.setNode(node.id, {- width: NODE_WIDTH / 2,- height: (NODE_ROW_HEIGHT / 2) * (node.data.columns.length + 1), // columns + header+ width: TABLE_NODE_WIDTH / 2,+ height: (TABLE_NODE_ROW_HEIGHT / 2) * (node.data.columns.length + 1), // columns + header})})@@ -202,104 +198,6 @@ const getLayoutedElements = (nodes: Node[], edges: Edge[]) => {return { nodes, edges }}-// ReactFlow is scaling everything by the factor of 2-const NODE_WIDTH = 320-const NODE_ROW_HEIGHT = 40--function TableNode({ data, targetPosition, sourcePosition }: NodeProps<TableNodeData>) {- // Important styles is a nasty hack to use Handles (required for edges calculations), but do not show them in the UI.- // ref: https://github.com/wbkd/react-flow/discussions/2698- const hiddenNodeConnector = '!h-px !w-px !min-w-0 !min-h-0 !cursor-grab !border-0 !opacity-0'-- return (- <>- {data.isForeign ? (- <div className="rounded-lg overflow-hidden">- <header className="text-[0.5rem] leading-5 font-bold px-2 text-center bg-brand text-gray-300">- {data.name}- {targetPosition && (- <Handle- type="target"- id={data.name}- position={targetPosition}- className={clsx(hiddenNodeConnector, '!left-0')}- />- )}- </header>- </div>- ) : (- <div className="rounded-lg overflow-hidden" style={{ width: NODE_WIDTH / 2 }}>- <header className="text-[0.5rem] leading-5 font-bold px-2 text-center bg-brand text-background-surface-100">- {data.name}- </header>-- {data.columns.map((column) => (- <div- className="text-[8px] leading-5 relative flex flex-row justify-items-start odd:bg-surface-100 even:bg-surface-200"- key={column.id}- >- <div className="gap-[0.24rem] flex mx-2 align-middle basis-1/5 items-center justify-start">- {column.isPrimary && (- <IconKey- size={8}- strokeWidth={2}- className="sb-grid-column-header__inner__primary-key flex-shrink-0"- />- )}- {column.isNullable && (- <Diamond size={8} strokeWidth={2} className="flex-shrink-0" />- )}- {!column.isNullable && (- <Diamond size={8} strokeWidth={2} fill="currentColor" className="flex-shrink-0" />- )}- {column.isUnique && (- <Fingerprint size={8} strokeWidth={2} className="flex-shrink-0" />- )}- {column.isIdentity && (- <IconHash size={8} strokeWidth={2} className="flex-shrink-0" />- )}- {!column.isUpdateable && (- <IconLock size={8} strokeWidth={2} className="flex-shrink-0" />- )}- </div>- <div className="flex w-full justify-between">- <span className="text-ellipsis overflow-hidden whitespace-nowrap">- {column.name}- </span>- <span- className={clsx(- column.isPrimary && 'pl-[6px]',- 'absolute top-0 left-0 right-0 pl-2 bg-surface-300 text-ellipsis overflow-hidden whitespace-nowrap opacity-0 hover:opacity-100'- )}- >- {column.name}- </span>- <span className="px-2 inline-flex justify-end">{column.format}</span>- </div>- {targetPosition && (- <Handle- type="target"- id={column.id}- position={targetPosition}- className={clsx(hiddenNodeConnector, '!left-0')}- />- )}- {sourcePosition && (- <Handle- type="source"- id={column.id}- position={sourcePosition}- className={clsx(hiddenNodeConnector, '!right-0')}- />- )}- </div>- ))}- </div>- )}- </>- )-}-const TablesGraph = ({ tables }: { tables: PostgresTable[] }) => {const { resolvedTheme } = useTheme()const backgroundPatternColor = resolvedTheme?.includes('dark') ? '#2e2e2e' : '#e6e8eb'@@ -337,7 +235,8 @@ const TablesGraph = ({ tables }: { tables: PostgresTable[] }) => {animated: true,deletable: false,style: {- stroke: edgeStrokeColor,+ stroke: 'hsl(var(--border-stronger))',+ strokeWidth: 0.5,},}}nodeTypes={nodeTypes}@@ -346,13 +245,18 @@ const TablesGraph = ({ tables }: { tables: PostgresTable[] }) => {maxZoom={1.8}proOptions={{ hideAttribution: true }}>- <Background gap={16} color={backgroundPatternColor} variant={BackgroundVariant.Lines} />+ <Background+ gap={16}+ className="[&>*]:stroke-foreground-muted opacity-[25%]"+ variant={BackgroundVariant.Dots}+ color={'inherit'}+ /><MiniMappannablezoomablenodeColor={miniMapNodeColor}maskColor={miniMapMaskColor}- className="border border-control rounded-md shadow-sm"+ className="border rounded-md shadow-sm"/></ReactFlow></div>diff --git a/packages/ui/index.tsx b/packages/ui/index.tsxindex 5f0b4553e56..a2f981243be 100644--- a/packages/ui/index.tsx+++ b/packages/ui/index.tsx@@ -181,6 +181,8 @@ export { Separator } from './src/components/shadcn/ui/separator'// patterns++export * from './src/patterns/SchemaTableNode'export { AssistantChatForm } from './src/patterns/AssistantChatForm'// linksdiff --git a/packages/ui/src/patterns/SchemaTableNode.tsx b/packages/ui/src/patterns/SchemaTableNode.tsxnew file mode 100644index 00000000000..b2658b68e37--- /dev/null+++ b/packages/ui/src/patterns/SchemaTableNode.tsx@@ -0,0 +1,135 @@+import { DiamondIcon, Fingerprint, Hash, Key, Table2 } from 'lucide-react'+import { Handle, NodeProps } from 'reactflow'+import { cn } from 'ui'++// ReactFlow is scaling everything by the factor of 2+const TABLE_NODE_WIDTH = 320+const TABLE_NODE_ROW_HEIGHT = 40++export type TableNodeData = {+ name: string+ isForeign: boolean+ columns: {+ id: string+ isPrimary: boolean+ isNullable: boolean+ isUnique: boolean+ isIdentity: boolean+ name: string+ format: string+ }[]+}++const TableNode = ({ data, targetPosition, sourcePosition }: NodeProps<TableNodeData>) => {+ // Important styles is a nasty hack to use Handles (required for edges calculations), but do not show them in the UI.+ // ref: https://github.com/wbkd/react-flow/discussions/2698+ const hiddenNodeConnector = '!h-px !w-px !min-w-0 !min-h-0 !cursor-grab !border-0 !opacity-0'++ const itemHeight = 'h-[22px]'++ return (+ <>+ {data.isForeign ? (+ <header className="text-[0.55rem] px-2 py-1 border-[0.5px] rounded-[4px] bg-alternative text-default flex gap-1 items-center">+ {data.name}+ {targetPosition && (+ <Handle+ type="target"+ id={data.name}+ position={targetPosition}+ className={cn(hiddenNodeConnector)}+ />+ )}+ </header>+ ) : (+ <div+ className="border-[0.5px] overflow-hidden rounded-[4px] shadow-sm"+ style={{ width: TABLE_NODE_WIDTH / 2 }}+ >+ <header+ className={cn(+ 'text-[0.55rem] px-2 bg-alternative text-default flex gap-1 items-center',+ itemHeight+ )}+ >+ <Table2 strokeWidth={1} size={12} className="text-light" />+ {data.name}+ </header>++ {data.columns.map((column) => (+ <div+ className={cn(+ 'text-[8px] leading-5 relative flex flex-row justify-items-start',+ 'bg-surface-100',+ 'border-t',+ 'border-t-[0.5px]',+ // 'odd:bg-scale-300',+ // 'even:bg-scale-400',+ 'hover:bg-scale-500 transition cursor-default',+ itemHeight+ )}+ key={column.id}+ >+ <div className="gap-[0.24rem] flex mx-2 align-middle basis-1/5 items-center justify-start">+ {column.isPrimary && (+ <Key+ size={8}+ strokeWidth={1}+ className={cn(+ // 'sb-grid-column-header__inner__primary-key'+ 'flex-shrink-0',+ 'text-light'+ )}+ />+ )}+ {column.isNullable && (+ <DiamondIcon size={8} strokeWidth={1} className="flex-shrink-0 text-light" />+ )}+ {!column.isNullable && (+ <DiamondIcon+ size={8}+ strokeWidth={1}+ fill="currentColor"+ className="flex-shrink-0 text-light"+ />+ )}+ {column.isUnique && (+ <Fingerprint size={8} strokeWidth={1} className="flex-shrink-0 text-light" />+ )}+ {column.isIdentity && (+ <Hash size={8} strokeWidth={1} className="flex-shrink-0 text-light" />+ )}+ </div>+ <div className="flex w-full justify-between">+ <span className="text-ellipsis overflow-hidden whitespace-nowrap">+ {column.name}+ </span>+ <span className="px-2 inline-flex justify-end font-mono text-lighter text-[0.4rem]">+ {column.format}+ </span>+ </div>+ {targetPosition && (+ <Handle+ type="target"+ id={column.id}+ position={targetPosition}+ className={cn(hiddenNodeConnector, '!left-0')}+ />+ )}+ {sourcePosition && (+ <Handle+ type="source"+ id={column.id}+ position={sourcePosition}+ className={cn(hiddenNodeConnector, '!right-0')}+ />+ )}+ </div>+ ))}+ </div>+ )}+ </>+ )+}++export { TableNode, TABLE_NODE_WIDTH, TABLE_NODE_ROW_HEIGHT }