Files
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

127 lines
4.2 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { CircleAlertIcon, DatabaseIcon, DownloadIcon, Loader2Icon, WindIcon } from 'lucide-react'
import { toast } from 'sonner'
import { Button, Card, CardContent, CardHeader, CardTitle, Skeleton } from 'ui'
import { DiffEditor } from '@/components/ui/DiffEditor'
interface DatabaseDiffPanelProps {
diffContent?: string
isLoading: boolean
error?: any
showRefreshButton?: boolean
currentBranchRef?: string
}
export const DatabaseDiffPanel = ({
diffContent,
isLoading,
error,
currentBranchRef,
}: DatabaseDiffPanelProps) => {
if (isLoading) {
return (
<div className="flex flex-1 min-h-0 flex-col">
<div className="flex flex-1 min-h-[400px] flex-col rounded-md border border-border bg-surface-100">
<div className="flex shrink-0 items-center gap-2 border-b border-border px-4 py-3">
<Loader2Icon
size={16}
strokeWidth={1.5}
className="animate-spin text-foreground-muted"
aria-hidden
/>
<span className="text-sm text-foreground-light">Loading database diff…</span>
</div>
<div className="min-h-0 flex-1 p-4">
<Skeleton className="h-full w-full rounded-sm" />
</div>
</div>
</div>
)
}
if (error)
return (
<div className="p-6 text-center">
<CircleAlertIcon
size={32}
strokeWidth={1.5}
className="text-foreground-muted mx-auto mb-8"
/>
<h3 className="mb-1">Error loading branch diff</h3>
<p className="text-sm text-foreground-light">
Please try again in a few minutes and contact support if the problem persists.
</p>
</div>
)
if (!diffContent || diffContent.trim() === '') {
return (
<div className="p-6 text-center">
<WindIcon size={32} strokeWidth={1.5} className="text-foreground-muted mx-auto mb-8" />
<h3 className="mb-1">No changes detected between branches</h3>
<p className="text-sm text-foreground-light">
Any changes to your database schema will be shown here for review
</p>
</div>
)
}
return (
<Card className="flex flex-1 min-h-0 flex-col">
<CardHeader className="flex shrink-0 flex-row items-center justify-between space-y-0 py-3">
<CardTitle>
<Link
to="/project/$ref/database/schemas"
params={{ ref: currentBranchRef ?? '_' }}
className="flex items-center gap-2"
>
<DatabaseIcon strokeWidth={1.5} size={16} className="text-foreground-muted" />
Schema Changes
</Link>
</CardTitle>
<Button
size="tiny"
icon={<DownloadIcon strokeWidth={1.5} size={14} className="text-foreground-light" />}
className="mt-0"
onClick={() => {
if (!diffContent) return
const now = new Date()
const pad = (n: number) => n.toString().padStart(2, '0')
const timestamp =
now.getFullYear().toString() +
pad(now.getMonth() + 1) +
pad(now.getDate()) +
pad(now.getHours()) +
pad(now.getMinutes()) +
pad(now.getSeconds())
const filename = `${timestamp}_migration.sql`
const blob = new Blob([diffContent], { type: 'text/plain;charset=utf-8;' })
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.setAttribute('download', filename)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
window.URL.revokeObjectURL(url)
toast.success('Migration file downloaded!')
}}
>
Download as migration
</Button>
</CardHeader>
<CardContent className="flex min-h-0 flex-1 flex-col p-0">
<div className="min-h-0 flex-1">
<DiffEditor
language="sql"
original=""
modified={diffContent}
options={{ readOnly: true }}
/>
</div>
</CardContent>
</Card>
)
}