Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Support opening tables in table editor via schema visualizer (#30052)

Joshen Limceee53a8d1c1
diff --git a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
index 5efc751fca3..83610ce74b7 100644
--- a/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
+++ b/apps/studio/components/interfaces/Database/Schemas/SchemaGraph.tsx
@@ -5,6 +5,7 @@ import { useEffect, useMemo, useState } from 'react'
import ReactFlow, { Background, BackgroundVariant, MiniMap, useReactFlow } from 'reactflow'
import 'reactflow/dist/style.css'
+import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import AlertError from 'components/ui/AlertError'
import SchemaSelector from 'components/ui/SchemaSelector'
@@ -13,10 +14,9 @@ import { useTablesQuery } from 'data/tables/tables-query'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
import { Button, Tooltip_Shadcn_, TooltipContent_Shadcn_, TooltipTrigger_Shadcn_ } from 'ui'
-import { TableNode } from 'ui-patterns/SchemaTableNode'
+import { TableNode } from './SchemaTableNode'
import { SchemaGraphLegend } from './SchemaGraphLegend'
import { getGraphDataFromTables, getLayoutedElementsViaDagre } from './Schemas.utils'
-import { useParams } from 'common'
// [Joshen] Persisting logic: Only save positions to local storage WHEN a node is moved OR when explicitly clicked to reset layout
diff --git a/packages/ui-patterns/SchemaTableNode.tsx b/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
similarity index 83%
rename from packages/ui-patterns/SchemaTableNode.tsx
rename to apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
index 76424665157..f3f9597eabe 100644
--- a/packages/ui-patterns/SchemaTableNode.tsx
+++ b/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
@@ -1,13 +1,17 @@
-import { DiamondIcon, Fingerprint, Hash, Key, Table2 } from 'lucide-react'
+import { DiamondIcon, ExternalLink, Fingerprint, Hash, Key, Link2, Table2 } from 'lucide-react'
import { Handle, NodeProps } from 'reactflow'
-import { cn } from 'ui'
+import Link from 'next/link'
+
+import { Button, cn, Tooltip_Shadcn_, TooltipContent_Shadcn_, TooltipTrigger_Shadcn_ } 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 = {
+ id?: number
name: string
+ ref: string
isForeign: boolean
columns: {
id: string
@@ -48,12 +52,21 @@ const TableNode = ({ data, targetPosition, sourcePosition }: NodeProps<TableNode
>
<header
className={cn(
- 'text-[0.55rem] px-2 bg-alternative text-default flex gap-1 items-center',
+ 'text-[0.55rem] pl-2 pr-1 bg-alternative text-default flex items-center justify-between',
itemHeight
)}
>
- <Table2 strokeWidth={1} size={12} className="text-light" />
- {data.name}
+ <div className="flex gap-x-1 items-center">
+ <Table2 strokeWidth={1} size={12} className="text-light" />
+ {data.name}
+ </div>
+ {data.id && (
+ <Button asChild type="text" className="px-0 w-[16px] h-[16px] rounded">
+ <Link href={`/project/${data.ref}/editor/${data.id}`}>
+ <ExternalLink size={10} className="text-foreground-light" />
+ </Link>
+ </Button>
+ )}
</header>
{data.columns.map((column) => (
@@ -63,8 +76,6 @@ const TableNode = ({ data, targetPosition, sourcePosition }: NodeProps<TableNode
'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
)}
diff --git a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
index 87e4341f609..f3d557f9129 100644
--- a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
+++ b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
@@ -6,22 +6,7 @@ import 'reactflow/dist/style.css'
import { LOCAL_STORAGE_KEYS } from 'lib/constants'
import { tryParseJson } from 'lib/helpers'
-import { TABLE_NODE_ROW_HEIGHT, TABLE_NODE_WIDTH } from 'ui-patterns/SchemaTableNode'
-
-type TableNodeData = {
- name: string
- isForeign: boolean
- columns: {
- id: string
- isPrimary: boolean
- isNullable: boolean
- isUnique: boolean
- isUpdateable: boolean
- isIdentity: boolean
- name: string
- format: string
- }[]
-}
+import { TABLE_NODE_ROW_HEIGHT, TABLE_NODE_WIDTH, TableNodeData } from './SchemaTableNode'
const NODE_SEP = 25
const RANK_SEP = 50
@@ -56,10 +41,12 @@ export async function getGraphDataFromTables(
id: `${table.id}`,
type: 'table',
data: {
+ ref,
+ id: table.id,
name: table.name,
isForeign: false,
columns,
- },
+ } as TableNodeData,
position: { x: 0, y: 0 },
}
})
@@ -83,10 +70,11 @@ export async function getGraphDataFromTables(
id: rel.constraint_name,
type: 'table',
data: {
+ ref,
name: `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`,
isForeign: true,
columns: [],
- },
+ } as TableNodeData,
position: { x: 0, y: 0 },
})
diff --git a/apps/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.tsx b/apps/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.tsx
index bf527528b39..ec80389df06 100644
--- a/apps/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.tsx
+++ b/apps/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.tsx
@@ -98,6 +98,12 @@ export const generateDatabaseMenu = (
},
]
: []),
+ {
+ name: 'Migrations',
+ key: 'migrations',
+ url: `/project/${ref}/database/migrations`,
+ items: [],
+ },
{
name: 'Wrappers',
key: 'wrappers',
@@ -105,12 +111,6 @@ export const generateDatabaseMenu = (
rightIcon: <ArrowUpRight strokeWidth={1} className="h-4 w-4" />,
items: [],
},
- {
- name: 'Migrations',
- key: 'migrations',
- url: `/project/${ref}/database/migrations`,
- items: [],
- },
...(!!pgNetExtensionExists
? [
{
diff --git a/packages/ui-patterns/index.tsx b/packages/ui-patterns/index.tsx
index d9a2048be60..c77dbacf424 100644
--- a/packages/ui-patterns/index.tsx
+++ b/packages/ui-patterns/index.tsx
@@ -9,7 +9,6 @@ export * from './ExpandableVideo'
export * from './GlassPanel'
export * from './IconPanel'
export * from './PrivacySettings'
-export * from './SchemaTableNode'
export * from './ThemeToggle'
export * from './TweetCard'
export * from './InnerSideMenu'