Files
Alaister YoungandAlaister Young 6dd7062496 [FE-5108] (part 2) refactor(studio): migrate layouts & shell off next/link (#54305)
Part 2 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 ← this PR** | **`components/layouts/**` and top-level
shell components** |
| 3 | #54306 | 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 all `apps/studio/components/layouts/**` files and top-level
navigation shell components off `next/link`.

**Changed:**

- Replaced `next/link` across `components/layouts/**` (`AccountLayout`,
`AppLayout`, `AuthLayout`, `BranchLayout`, `DatabaseLayout`,
`EdgeFunctionsLayout`, `ExplorerLayout`, `IssuesLayout`, `LogsLayout`,
`Navigation`, `ObservabilityLayout`, `ProjectLayout`,
`ProjectNeedsSecuring`, `SQLEditorLayout`, `SignInLayout`,
`TableEditorLayout`, `Tabs`) and top-level shell components
(`Sidebar.tsx`, `UserDropdown.tsx`, `LocalDropdown.tsx`,
`HomePageActions.tsx`)
- Removed `vi.mock('next/link', ...)` from `LocalDropdown.test.tsx` and
`ProjectNeedsSecuring.test.tsx`
- Added accessible labels where external icon/logo links switched from
`<Link>` to plain `<a>` (`AdminStudioButton.tsx`,
`ForgotPasswordLayout.tsx`)

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

## To test

- [ ] Navigate across top header, left sidebar, user/local dropdown, and
project/org/branch switchers
- [ ] Verify mobile navigation menu items and recent-tab links navigate
with expected query params
- [ ] Verify sign-in and forgot-password layout links work cleanly

---------

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

114 lines
2.9 KiB
TypeScript

import {
CopyIcon,
CornerDownRightIcon,
DownloadIcon,
EditIcon,
LockIcon,
TrashIcon,
} from 'lucide-react'
import { Fragment, type ReactNode } from 'react'
import {
ContextMenuItem,
ContextMenuSeparator,
ContextMenuSub,
ContextMenuSubContent,
ContextMenuSubTrigger,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
} from 'ui'
import type { EntityAction, EntityActionGroup, EntityActionId } from './EntityActions.utils'
import { DynamicLink } from '@/components/ui/DynamicLink'
const ICONS: Partial<Record<EntityActionId, ReactNode>> = {
'copy-name': <CopyIcon size={12} className="shrink-0" />,
'copy-schema': <CopyIcon size={12} className="shrink-0" />,
'copy-definition': <CopyIcon size={12} className="shrink-0" />,
'duplicate-table': <CopyIcon size={12} className="shrink-0" />,
'edit-table': <EditIcon size={12} className="shrink-0" />,
'view-policies': <LockIcon size={12} className="shrink-0" />,
export: <DownloadIcon size={12} className="shrink-0" />,
'view-partitions': <CornerDownRightIcon size={12} className="shrink-0" />,
delete: <TrashIcon size={12} className="shrink-0" />,
}
const MENU_COMPONENTS = {
dropdown: {
Item: DropdownMenuItem,
Separator: DropdownMenuSeparator,
Sub: DropdownMenuSub,
SubTrigger: DropdownMenuSubTrigger,
SubContent: DropdownMenuSubContent,
},
context: {
Item: ContextMenuItem,
Separator: ContextMenuSeparator,
Sub: ContextMenuSub,
SubTrigger: ContextMenuSubTrigger,
SubContent: ContextMenuSubContent,
},
}
interface EntityActionMenuItemsProps {
variant: keyof typeof MENU_COMPONENTS
groups: EntityActionGroup[]
onSelectAction: (id: EntityActionId) => void
}
export const EntityActionMenuItems = ({
variant,
groups,
onSelectAction,
}: EntityActionMenuItemsProps) => {
const { Item, Separator, Sub, SubTrigger, SubContent } = MENU_COMPONENTS[variant]
const renderAction = (action: EntityAction) => {
if (action.children) {
return (
<Sub key={action.id}>
<SubTrigger className="gap-x-2">
{ICONS[action.id]}
{action.label}
</SubTrigger>
<SubContent>{action.children.map(renderAction)}</SubContent>
</Sub>
)
}
const content = (
<>
{ICONS[action.id]}
<span>{action.label}</span>
</>
)
if (action.href !== undefined) {
return (
<Item key={action.id} className="gap-x-2" asChild>
<DynamicLink href={action.href}>{content}</DynamicLink>
</Item>
)
}
return (
<Item key={action.id} className="gap-x-2" onSelect={() => onSelectAction(action.id)}>
{content}
</Item>
)
}
return (
<>
{groups.map((group, index) => (
<Fragment key={group[0].id}>
{index > 0 && <Separator />}
{group.map(renderAction)}
</Fragment>
))}
</>
)
}