Files
supabase/apps/studio/components/interfaces/TableGridEditor/TableDefinition.tsx
Alaister YoungandAlaister Young e0635f2f38 [FE-5108] (part 3) refactor(studio): migrate database, editors & storage off next/link (#54306)
Part 3 of a 6-PR stack migrating all `next/link` imports in
`apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known
external URLs) and removing `compat/next/link.tsx`.

| Part | PR | Scope |
| --- | --- | --- |
| 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and
`components/ui/**` |
| 2 | #54305 | `components/layouts/**` and top-level shell components |
| **3** | **#54306 ← this PR** | **Database, TableGridEditor, Storage,
SQLEditor, BranchManagement, Branching, Functions, Realtime** |
| 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues,
Linter, Reports, QueryPerformance, QuerySources, ConfigDrift,
DiskManagement, Compute |
| 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth,
Support, Home, SignIn, ConnectSheet, etc.) |
| 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and
update basePath tests/docs |

Migrates
`components/interfaces/{Database,TableGridEditor,Storage,SQLEditor,BranchManagement,Branching,Functions,Realtime}/`
off `next/link`.

**Changed:**

- Replaced `next/link` across all 60 importing files in Database,
TableGridEditor, Storage, SQLEditor, BranchManagement, Branching,
Functions, and Realtime interfaces
- Updated legacy permanent-redirect hrefs (`/reports` →
`/observability`, `/database/schema` → `/database/schemas`) to their
canonical TanStack routes
- Dropped legacy `passHref` in `GridHeaderActions.tsx`, removed
duplicate `RouterLink` alias in `ChooseFunctionForm.tsx`, and removed
`vi.mock('next/link', ...)` in `ReplicationPipelineLayout.test.tsx`

Addresses
[FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link)

## To test

- [ ] Check Table Editor, SQL Editor, Database (tables, policies,
functions, triggers, replication, backups), Storage
(files/analytics/vector buckets), Edge Functions, Branching, and
Realtime links
- [ ] Verify SQL Editor and Table Editor links with query parameters
(`schema`, `content`, `search`) do not double-encode values

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 16:43:56 +08:00

88 lines
2.4 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { useMemo } from 'react'
import { Button, FloatingPlate } from 'ui'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { Footer } from '@/components/grid/components/footer/Footer'
import { CodeEditor } from '@/components/ui/CodeEditor/CodeEditor'
import { useTableDefinitionQuery } from '@/data/database/table-definition-query'
import { useViewDefinitionQuery } from '@/data/database/view-definition-query'
import { Entity, isTableLike, isViewLike } from '@/data/table-editor/table-editor-types'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { formatSql } from '@/lib/formatSql'
export interface TableDefinitionProps {
entity?: Entity
}
export const TableDefinition = ({ entity }: TableDefinitionProps) => {
const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const viewResult = useViewDefinitionQuery(
{
id: entity?.id,
includeCreateStatement: true,
projectRef: project?.ref,
connectionString: project?.connectionString,
},
{
enabled: isViewLike(entity),
}
)
const tableResult = useTableDefinitionQuery(
{
id: entity?.id,
projectRef: project?.ref,
connectionString: project?.connectionString,
},
{
enabled: isTableLike(entity),
}
)
const { data: definition, isLoading } = isViewLike(entity) ? viewResult : tableResult
const formattedDefinition = useMemo(
() => (definition ? formatSql(definition) : undefined),
[definition]
)
if (isLoading) {
return (
<div className="h-full grid">
<div className="p-4">
<GenericSkeletonLoader />
</div>
<div className="mt-auto">
<Footer />
</div>
</div>
)
}
return (
<>
<div className="grow overflow-y-auto border-t border-muted relative">
<FloatingPlate className="absolute top-2 right-5 z-10">
<Button asChild>
<Link
to="/project/$ref/sql/$id"
params={{ ref: ref ?? '_', id: 'new' }}
search={{ content: formattedDefinition ?? '' }}
>
Open in SQL Editor
</Link>
</Button>
</FloatingPlate>
<CodeEditor isReadOnly language="pgsql" value={formattedDefinition} />
</div>
<Footer />
</>
)
}