Files
supabase/apps/studio/components/layouts/Navigation/NavigationBar/MobileNavigationBar.tsx
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

92 lines
3.8 KiB
TypeScript

import { useParams } from 'common'
import { ChevronLeftIcon, MenuIcon } from 'lucide-react'
import { useState } from 'react'
import { Button, cn } from 'ui'
import { MobileSheetNav } from 'ui-patterns/MobileSheetNav'
import { HomeIcon } from '../LayoutHeader/HomeIcon'
import { MobileProjectSwitcher } from './MobileProjectSwitcher'
import { useMobileSheet } from './MobileSheetContext'
import { OrgSelector } from './OrgSelector'
import { ConnectButton } from '@/components/interfaces/ConnectButton/ConnectButton'
import { LocalDropdown } from '@/components/interfaces/LocalDropdown'
import { SidebarContent } from '@/components/interfaces/Sidebar'
import { UserDropdown } from '@/components/interfaces/UserDropdown'
import { FloatingMobileToolbar } from '@/components/layouts/Navigation/FloatingMobileToolbar/FloatingMobileToolbar'
import { DynamicLink } from '@/components/ui/DynamicLink'
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { IS_PLATFORM } from '@/lib/constants'
export const ICON_SIZE = 20
export const ICON_STROKE_WIDTH = 1.5
export const MobileNavigationBar = ({
hideMobileMenu,
backToDashboardURL,
}: {
hideMobileMenu?: boolean
backToDashboardURL?: string
}) => {
const [isSheetOpen, setIsSheetOpen] = useState(false)
const { ref: projectRef, slug } = useParams()
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const { isPending: isLoadingOrganizations } = useOrganizationsQuery()
const isProjectScope = !!projectRef
const showOrgSelection = slug || isLoadingOrganizations || (selectedOrganization && projectRef)
const { openMenu } = useMobileSheet()
return (
<div className="w-full flex flex-row md:hidden">
<nav
className={cn(
'group pr-3 pl-2 z-10 w-full h-12 gap-2',
'border-b bg-dash-sidebar border-default shadow-[0_0_30px_0_rgba(0,0,0,0.07)]',
'transition-width duration-200',
'hide-scrollbar flex flex-row items-center justify-between overflow-x-auto'
)}
>
<div className={cn('flex min-w-0 shrink items-center gap-2', !IS_PLATFORM && 'pl-2')}>
{backToDashboardURL && (
<div className="flex items-center justify-center ml-1 flex-0 md:hidden h-full aspect-square">
<DynamicLink
href={backToDashboardURL}
className="flex items-center justify-center bg-transparent! rounded-md min-w-[30px] w-[30px] h-[30px] border text-foreground-lighter hover:text-foreground transition-colors"
>
<ChevronLeftIcon strokeWidth={1.5} size={16} />
</DynamicLink>
</div>
)}
{!IS_PLATFORM && <HomeIcon />}
{isProjectScope ? (
<>
<MobileProjectSwitcher />
<ConnectButton iconOnly className="w-8 h-8" />
</>
) : IS_PLATFORM && showOrgSelection ? (
<OrgSelector />
) : (
<HomeIcon className="ml-1" />
)}
</div>
<div className="flex shrink-0 gap-2">
{IS_PLATFORM ? <UserDropdown /> : <LocalDropdown />}
{!hideMobileMenu && (
<Button
aria-label="Open menu"
title="Menu dropdown button"
className="flex lg:hidden border-default bg-surface-100/75 text-foreground-light rounded-md min-w-[30px] w-[30px] h-[30px] data-open:bg-overlay-hover/30"
icon={<MenuIcon />}
onClick={() => openMenu()}
/>
)}
</div>
</nav>
<MobileSheetNav open={isSheetOpen} onOpenChange={setIsSheetOpen} data-state="expanded">
<SidebarContent />
</MobileSheetNav>
<FloatingMobileToolbar hideMobileMenu={hideMobileMenu} />
</div>
)
}