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

132 lines
4.9 KiB
TypeScript

import { Link, useNavigate } from '@tanstack/react-router'
import { useParams } from 'common'
import { Badge, Menu } from 'ui'
import { BUCKET_TYPES } from './Storage.constants'
import { useStorageV2Page } from './Storage.utils'
import { DynamicLink } from '@/components/ui/DynamicLink'
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import {
useIsAnalyticsBucketsEnabled,
useIsVectorBucketsEnabled,
} from '@/data/config/project-storage-config-query'
import { useDeploymentMode } from '@/hooks/misc/useDeploymentMode'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { navigateToUrl } from '@/lib/navigation'
import { SHORTCUT_IDS, type ShortcutId } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
const BUCKET_TYPE_SHORTCUTS: Record<keyof typeof BUCKET_TYPES, ShortcutId> = {
files: SHORTCUT_IDS.NAV_STORAGE_FILES,
analytics: SHORTCUT_IDS.NAV_STORAGE_ANALYTICS,
vectors: SHORTCUT_IDS.NAV_STORAGE_VECTORS,
}
export const StorageMenuV2 = () => {
const navigate = useNavigate()
const { ref } = useParams()
const page = useStorageV2Page()
const { isCli, isPlatform } = useDeploymentMode()
const { storageAnalytics, storageVectors } = useIsFeatureEnabled([
'storage:analytics',
'storage:vectors',
])
const isAnalyticsBucketsEnabled = useIsAnalyticsBucketsEnabled({ projectRef: ref })
const isVectorBucketsEnabled = useIsVectorBucketsEnabled({ projectRef: ref })
const showAnalytics = isPlatform && storageAnalytics
const showVectors = (isPlatform && storageVectors) || isCli
const goTo = (path: string) => () =>
void navigateToUrl(navigate, `/project/${ref}/storage/${path}`)
useShortcut(SHORTCUT_IDS.NAV_STORAGE_FILES, goTo('files'))
useShortcut(SHORTCUT_IDS.NAV_STORAGE_ANALYTICS, goTo('analytics'), { enabled: showAnalytics })
useShortcut(SHORTCUT_IDS.NAV_STORAGE_VECTORS, goTo('vectors'), { enabled: showVectors })
useShortcut(SHORTCUT_IDS.NAV_STORAGE_S3, goTo('s3'), { enabled: isPlatform })
useShortcut(SHORTCUT_IDS.NAV_STORAGE_SIGNING_KEYS, goTo('signing-keys'), { enabled: isPlatform })
const bucketTypes = Object.entries(BUCKET_TYPES).filter(([key]) => {
if (key === 'analytics') return showAnalytics
if (key === 'vectors') return showVectors
return true
})
return (
<Menu type="pills" className="my-2 md:my-4 flex grow flex-col">
<div className="space-y-4">
<div className="md:mx-3">
<Menu.Group title={<span className="uppercase font-mono">Manage</span>} />
{bucketTypes.map(([type, config]) => {
const isSelected = page === type
const isAlphaEnabled =
(type === 'analytics' && isAnalyticsBucketsEnabled) ||
(type === 'vectors' && isVectorBucketsEnabled)
const shortcutId = BUCKET_TYPE_SHORTCUTS[type as keyof typeof BUCKET_TYPES]
const item = (
<DynamicLink href={`/project/${ref}/storage/${type}`}>
<Menu.Item rounded active={isSelected}>
<div className="flex items-center justify-between">
<p className="truncate">{config.displayName}</p>
{isAlphaEnabled && <Badge variant="success">New</Badge>}
</div>
</Menu.Item>
</DynamicLink>
)
return (
<div key={type}>
{shortcutId ? (
<ShortcutTooltip shortcutId={shortcutId} side="right" delayDuration={1000}>
{item}
</ShortcutTooltip>
) : (
item
)}
</div>
)
})}
</div>
{isPlatform && (
<>
<div className="h-px w-[calc(100%-1.5rem)] mx-auto md:w-full bg-border" />
<div className="md:mx-3">
<Menu.Group title={<span className="uppercase font-mono">Configuration</span>} />
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.NAV_STORAGE_S3}
side="right"
delayDuration={1000}
>
<Link to="/project/$ref/storage/s3" params={{ ref: ref ?? '_' }}>
<Menu.Item rounded active={page === 's3'}>
<p className="truncate">S3</p>
</Menu.Item>
</Link>
</ShortcutTooltip>
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.NAV_STORAGE_SIGNING_KEYS}
side="right"
delayDuration={1000}
>
<Link to="/project/$ref/storage/signing-keys" params={{ ref: ref ?? '_' }}>
<Menu.Item rounded active={page === 'signing-keys'}>
<p className="truncate">URL signing keys</p>
</Menu.Item>
</Link>
</ShortcutTooltip>
</div>
</>
)}
</div>
</Menu>
)
}