mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
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>
101 lines
3.4 KiB
TypeScript
101 lines
3.4 KiB
TypeScript
import { Link, useLocation } from '@tanstack/react-router'
|
|
import { FlaskConicalIcon, SettingsIcon } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import {
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
singleThemes,
|
|
} from 'ui'
|
|
|
|
import { ButtonTooltip } from '../ui/ButtonTooltip'
|
|
import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
|
|
import { DevToolbarMenuGroup } from './DevToolbarMenuGroup'
|
|
import { ProfileImage } from '@/components/ui/ProfileImage'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export const LocalDropdown = ({
|
|
triggerClassName,
|
|
contentClassName,
|
|
}: {
|
|
triggerClassName?: string
|
|
contentClassName?: string
|
|
}) => {
|
|
const pathname = useLocation({ select: (location) => location.pathname })
|
|
const currentRoute = useLocation({ select: (location) => location.href })
|
|
const { theme, setTheme } = useTheme()
|
|
const appStateSnapshot = useAppStateSnapshot()
|
|
const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
|
|
const track = useTrack()
|
|
|
|
return (
|
|
<DropdownMenu
|
|
onOpenChange={(open) => {
|
|
if (open) track('header_local_dropdown_opened')
|
|
}}
|
|
>
|
|
<DropdownMenuTrigger className={cn('border shrink-0 px-3', triggerClassName)} asChild>
|
|
<ButtonTooltip
|
|
className="[&>span]:flex px-0 py-0 rounded-full overflow-hidden h-8 w-8"
|
|
tooltip={{ content: { text: 'Settings' } }}
|
|
>
|
|
<ProfileImage className="w-8 h-8 rounded-md" />
|
|
<span className="sr-only">Settings</span>
|
|
</ButtonTooltip>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align="end" className={cn('w-44', contentClassName)}>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
to="/account/me"
|
|
onClick={() => {
|
|
if (pathname !== '/account/me') {
|
|
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(currentRoute)
|
|
}
|
|
}}
|
|
>
|
|
<SettingsIcon size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Preferences
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 cursor-pointer"
|
|
onClick={() => toggleFeaturePreviewModal(true)}
|
|
onSelect={() => toggleFeaturePreviewModal(true)}
|
|
>
|
|
<FlaskConicalIcon size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Feature previews
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DevToolbarMenuGroup />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel>Theme</DropdownMenuLabel>
|
|
<DropdownMenuRadioGroup
|
|
value={theme}
|
|
onValueChange={(value) => {
|
|
setTheme(value)
|
|
}}
|
|
>
|
|
{singleThemes.map((theme) => (
|
|
<DropdownMenuRadioItem
|
|
key={theme.value}
|
|
value={theme.value}
|
|
className="cursor-pointer"
|
|
>
|
|
{theme.name}
|
|
</DropdownMenuRadioItem>
|
|
))}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|