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

186 lines
7.1 KiB
TypeScript

import { Link, useNavigate } from '@tanstack/react-router'
import { useParams } from 'common'
import dayjs from 'dayjs'
import { useState } from 'react'
import {
Alert,
AlertDescription,
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertTitle,
Button,
DialogSection,
DialogSectionSeparator,
WarningIcon,
} from 'ui'
import { BackupsEmpty } from '../BackupsEmpty'
import { BackupsStorageAlert } from '../BackupsStorageAlert'
import { getClientTimezone } from './PITR.utils'
import { PITRForm } from './PITRForm'
import PITRStatus from './PITRStatus'
import { FormHeader } from '@/components/ui/Forms/FormHeader'
import { useBackupsQuery } from '@/data/database/backups-query'
import { usePitrRestoreMutation } from '@/data/database/pitr-restore-mutation'
import { useSetProjectStatus } from '@/data/projects/project-detail-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { PROJECT_STATUS } from '@/lib/constants'
import { getTimezoneLabel, type Timezone } from '@/lib/constants/timezones'
export const PITRSelection = () => {
const navigate = useNavigate()
const { ref } = useParams()
const { data: backups } = useBackupsQuery({ projectRef: ref })
const { data: databases } = useReadReplicasQuery({ projectRef: ref })
const { setProjectStatus } = useSetProjectStatus()
const [showConfiguration, setShowConfiguration] = useState(false)
const [showConfirmation, setShowConfirmation] = useState(false)
const [selectedTimezone, setSelectedTimezone] = useState<Timezone>(getClientTimezone())
const [selectedRecoveryPoint, setSelectedRecoveryPoint] = useState<{
selectedTimezone: Timezone
recoveryTimeTargetUnix: number
recoveryTimeString: string
recoveryTimeStringUtc: string
}>()
const hasReadReplicas = (databases ?? []).length > 1
const { mutateAsync: restoreFromPitr } = usePitrRestoreMutation({
onSuccess: (_, variables) => {
setTimeout(() => {
setShowConfirmation(false)
setProjectStatus({ ref: variables.ref, status: PROJECT_STATUS.RESTORING })
void navigate({ to: '/project/$ref', params: { ref: variables.ref } })
}, 3000)
},
})
const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =
backups?.physicalBackupData ?? {}
const hasNoBackupsAvailable = !earliestPhysicalBackupDateUnix || !latestPhysicalBackupDateUnix
const onConfirmRestore = async () => {
if (!ref) return console.error('Project ref is required')
if (!selectedRecoveryPoint?.recoveryTimeTargetUnix)
return console.error('Recovery time target unix is required')
await restoreFromPitr({
ref,
recovery_time_target_unix: selectedRecoveryPoint.recoveryTimeTargetUnix,
})
}
return (
<>
<FormHeader
title="Restore your database from a backup"
description="Database changes are watched and recorded, so that you can restore your database to any point in time"
/>
<BackupsStorageAlert />
{hasNoBackupsAvailable ? (
<BackupsEmpty />
) : (
<>
{hasReadReplicas && (
<Alert variant="warning">
<WarningIcon />
<AlertTitle>
Unable to restore from PITR as project has read replicas enabled
</AlertTitle>
<AlertDescription>
You will need to remove all read replicas first from your project's infrastructure
settings prior to starting a PITR restore.
</AlertDescription>
<div className="flex items-center gap-x-2 mt-2">
<Button asChild>
<Link to="/project/$ref/settings/infrastructure" params={{ ref: ref ?? '_' }}>
Manage read replicas
</Link>
</Button>
</div>
</Alert>
)}
{!showConfiguration ? (
<PITRStatus
selectedTimezone={selectedTimezone}
onUpdateTimezone={setSelectedTimezone}
onSetConfiguration={() => setShowConfiguration(true)}
/>
) : (
<PITRForm
earliestAvailableBackupUnix={earliestPhysicalBackupDateUnix}
latestAvailableBackupUnix={latestPhysicalBackupDateUnix}
onSubmit={(recoveryPoint) => {
setSelectedRecoveryPoint(recoveryPoint)
setShowConfirmation(true)
}}
/>
)}
</>
)}
<AlertDialog open={showConfirmation} onOpenChange={(open) => setShowConfirmation(open)}>
<AlertDialogContent size="medium">
<AlertDialogHeader>
<AlertDialogTitle>Point in time recovery review</AlertDialogTitle>
<AlertDialogDescription asChild>
<div className="flex flex-col space-y-2">
<p className="text-sm text-foreground-light">Your database will be restored to:</p>
<div className="py-2 flex flex-col gap-3">
<div>
<p className="text-sm font-mono text-foreground-lighter">
{selectedRecoveryPoint &&
getTimezoneLabel(
selectedRecoveryPoint.selectedTimezone,
dayjs.unix(selectedRecoveryPoint.recoveryTimeTargetUnix)
)}
</p>
<p className="text-2xl">{selectedRecoveryPoint?.recoveryTimeString}</p>
</div>
<div>
<p className="text-sm font-mono text-foreground-lighter">(UTC+00:00)</p>
<p className="text-2xl">{selectedRecoveryPoint?.recoveryTimeStringUtc}</p>
</div>
</div>
</div>
</AlertDialogDescription>
<DialogSectionSeparator />
<DialogSection>
<Alert variant="warning">
<WarningIcon />
<AlertTitle>This action cannot be undone, not canceled once started</AlertTitle>
<AlertDescription>
Any changes made to your database after this point in time will be lost. This
includes any changes to your project's storage and authentication.
</AlertDescription>
</Alert>
</DialogSection>
<DialogSectionSeparator />
<DialogSection>
<p className="text-sm text-foreground-light">
Restores may take from a few minutes up to several hours depending on the size of
your database. During this period, your project will not be available, until the
restoration is completed.
</p>
</DialogSection>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction variant="warning" onClick={onConfirmRestore}>
I understand, begin restore
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogHeader>
</AlertDialogContent>
</AlertDialog>
</>
)
}