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

154 lines
5.6 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { TableEditor } from 'icons'
import { MoreVerticalIcon, RotateCcwIcon } from 'lucide-react'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
TableCell,
TableRow,
} from 'ui'
import { ErroredTableDetails } from '../ErroredTableDetails'
import { SlotLagMetrics as SlotLagMetricsType, TableState } from './ReplicationPipelineStatus.types'
import { getStatusConfig, getTableSyncLagLabel } from './ReplicationPipelineStatus.utils'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { StateDot } from '@/components/ui/StateDot'
import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query'
interface TableReplicationRowProps {
table: ReplicationPipelineTableStatus
isRestarting: boolean
showDisabledState: boolean
disabledStateMessage: string
isAnyRestartInProgress: boolean
isPipelineStopped: boolean
onSelectRestart: () => void
onSelectShowError: () => void
}
export const TableReplicationRow = ({
table,
isRestarting,
showDisabledState,
disabledStateMessage,
isAnyRestartInProgress,
isPipelineStopped,
onSelectRestart,
onSelectShowError,
}: TableReplicationRowProps) => {
const { ref } = useParams()
const statusConfig = getStatusConfig(table.state as TableState['state'])
const tableName = `${table.schema}.${table.name}`
const canRestart = !showDisabledState && !isRestarting && !isAnyRestartInProgress
const resetDescription = isPipelineStopped
? 'Resetting saved progress. The pipeline stays stopped until you start it.'
: 'Resetting saved progress. The pipeline restarts automatically.'
const isErrorState = table.state.name === 'error'
const canShowError =
isErrorState && 'reason' in table.state && !showDisabledState && !isRestarting
// A table copying during the initial sync reports its own slot metrics. Shown as one line rather
// than a grid, so the detail survives without a table cell turning into a dashboard.
const syncLag = table.table_sync_lag as SlotLagMetricsType | null | undefined
const syncLagParts = syncLag == null ? undefined : getTableSyncLagLabel(syncLag)
const syncLagLabel =
syncLagParts !== undefined && syncLagParts.length > 0 ? syncLagParts.join(' · ') : undefined
// Status column already names the state (Copying, Queued, …). Prefer the sync line when we have
// one; keep the description only when it adds something the status label doesn't say.
const detailsLine =
syncLagLabel !== undefined ? syncLagLabel : isErrorState ? undefined : statusConfig.description
return (
<TableRow>
<TableCell>
<span className="text-foreground-lighter">{table.schema}.</span>
<span className="text-foreground">{table.name}</span>
</TableCell>
<TableCell>
{isRestarting ? (
<StateDot variant="warning" isPulsing>
Resetting
</StateDot>
) : showDisabledState ? (
<StateDot variant="default">Not available</StateDot>
) : (
<StateDot
variant={statusConfig.variant}
isPulsing={statusConfig.isPulsing}
pulseDelayMs={statusConfig.isPulsing ? (table.id % 8) * 55 : undefined}
>
{statusConfig.label}
</StateDot>
)}
</TableCell>
<TableCell>
{isRestarting ? (
<p className="text-sm text-foreground-lighter">{resetDescription}</p>
) : showDisabledState ? (
<p className="text-sm text-foreground-lighter">{disabledStateMessage}</p>
) : isErrorState ? (
<div className="flex flex-col gap-y-3 text-sm text-foreground-lighter">
<p>{statusConfig.description}.</p>
<ErroredTableDetails table={table} />
</div>
) : (
<p className="text-sm text-foreground-lighter">{detailsLine}</p>
)}
</TableCell>
<TableCell>
<div className="flex items-center justify-end gap-x-2">
{canShowError && (
<Button variant="default" onClick={onSelectShowError}>
View error
</Button>
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="default"
className="px-1.25 hit-area-2"
aria-label={`Options for ${tableName}`}
icon={<MoreVerticalIcon />}
/>
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className="w-44">
<DropdownMenuItemTooltip
className="gap-x-2"
disabled={!canRestart}
onClick={onSelectRestart}
tooltip={{
content: {
side: 'left',
text: canRestart ? undefined : disabledStateMessage,
},
}}
>
<RotateCcwIcon size={14} />
<span>Reset table</span>
</DropdownMenuItemTooltip>
<DropdownMenuItem className="gap-x-2" asChild>
<Link
target="_blank"
rel="noopener noreferrer"
to="/project/$ref/editor/$id"
params={{ ref: ref ?? '_', id: String(table.id) }}
>
<TableEditor size={14} />
<span>View in Table Editor</span>
</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</TableCell>
</TableRow>
)
}