Files
Alaister YoungandAlaister Young 680633ee4f [FE-5108] (part 5) refactor(studio): migrate remaining interfaces off next/link (#54308)
Part 5 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 | Database, TableGridEditor, Storage, SQLEditor,
BranchManagement, Branching, Functions, Realtime |
| 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues,
Linter, Reports, QueryPerformance, QuerySources, ConfigDrift,
DiskManagement, Compute |
| **5** | **#54308 ← this PR** | **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 the remaining `components/interfaces/**` directories off
`next/link`, leaving zero `next/link` component imports in
`apps/studio`.

**Changed:**

- Replaced `next/link` across all 73 remaining interface files
(`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`,
`ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`,
`ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`,
`Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`)
- Converted the sole remaining `UrlObject` link (`<Link href={{
pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link
to="/sign-in-sso" search={query}>`
- Migrated `SupportLink.tsx` onto `DynamicLink`
(`createSupportFormUrl(...)`)
- Standardized external `target="_blank"` anchors with `rel="noreferrer
noopener"`, switched `OverviewMetrics.tsx` observability link to typed
`<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink`
/ `InlineLinkClassName` on inline paragraph links per review feedback

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

## To test

- [ ] Check Organization (billing, usage, team, documents, AWS
Marketplace), Auth (providers, templates, rate limits, users, OAuth
apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO
links
- [ ] Verify `SignInWithSSOButton` preserves query params when
navigating to `/sign-in-sso`
- [ ] Verify `SupportLink` pre-populates support form query parameters
cleanly

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 17:33:03 +08:00

337 lines
10 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { BookIcon, BookOpenIcon } from 'lucide-react'
import { Fragment, type ReactNode } from 'react'
import SVG from 'react-inlinesvg'
import { Button, cn } from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { navigateToSection } from './Content/Content.utils'
import { API_DOCS_CATEGORIES, DOCS_CONTENT, DOCS_MENU } from './ProjectAPIDocs.constants'
import { useApiDocsFunctions, useApiDocsTables } from './useApiDocsEntities'
import { InfiniteListDefault, type RowComponentBaseProps } from '@/components/ui/InfiniteList'
import { NotExposedEntitiesIndicator } from '@/components/ui/NotExposedEntitiesIndicator'
import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query'
import { usePaginatedBucketsQuery, type Bucket } from '@/data/storage/buckets-query'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { BASE_PATH, DOCS_URL } from '@/lib/constants'
import { useAppStateSnapshot } from '@/state/app-state'
type DocsSections = typeof DOCS_MENU
type DocsSection = DocsSections[number]
type DocsSectionsSubset = readonly DocsSection[]
type DocsCategory = DocsSection['key']
type DocsContentRegistry = typeof DOCS_CONTENT
type DocsSnippet = DocsContentRegistry[keyof DocsContentRegistry]
const Separator = () => <hr className="border-t mt-3! pb-1 mx-3" />
const MENU_BUTTON_CLASSES = cn(
'w-full px-4',
'text-left text-sm text-foreground-light',
'transition hover:text-foreground'
)
/**
* Gets the docs menu items based on feature flags.
* @returns An array of menu items to be displayed in the docs navigation.
*/
const useDocsMenu = (): DocsSectionsSubset => {
const {
projectAuthAll: authEnabled,
projectStorageAll: storageEnabled,
projectEdgeFunctionAll: edgeFunctionsEnabled,
realtimeAll: realtimeEnabled,
} = useIsFeatureEnabled([
'project_auth:all',
'project_storage:all',
'project_edge_function:all',
'realtime:all',
])
return DOCS_MENU.filter((item) => {
if (item.key === 'user-management') return authEnabled
if (item.key === 'storage') return storageEnabled
if (item.key === 'edge-functions') return edgeFunctionsEnabled
if (item.key === 'realtime') return realtimeEnabled
return true
})
}
/**
* Gets the content snippets for a given documentation category.
* @param category - The category of documentation to retrieve snippets for.
* @returns An array of content snippets belonging to the specified category.
*/
const getSectionSnippets = (category: DocsCategory): DocsSnippet[] =>
Object.values(DOCS_CONTENT).filter((snippet) => snippet.category === category)
export const FirstLevelNav = (): ReactNode => {
const { ref } = useParams()
const snap = useAppStateSnapshot()
const currentSection = snap.activeDocsSection[0]
const docsMenu = useDocsMenu()
return (
<>
<nav aria-labelledby="api-docs-rest-categories" className="px-2 py-4 border-b">
<h2 id="api-docs-rest-categories" className="sr-only">
REST API Docs
</h2>
{docsMenu.map((item) => {
const isActive = currentSection === item.key
return (
<Fragment key={item.key}>
<button
tabIndex={0}
aria-current={isActive ? 'page' : undefined}
className={cn(
'w-full px-3 py-2 rounded-md',
'text-left text-sm',
'transition',
isActive && 'bg-surface-300'
)}
onClick={() => snap.setActiveDocsSection([item.key])}
>
{item.name}
</button>
{isActive && <Subsections category={item.key} />}
</Fragment>
)
})}
</nav>
<div className="px-2 py-4 border-b">
<Button
block
asChild
variant="text"
size="small"
icon={
<SVG
src={`${BASE_PATH}/img/graphql.svg`}
style={{ width: `${16}px`, height: `${16}px` }}
className="text-foreground"
preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}
/>
}
onClick={() => snap.setShowProjectApiDocs(false)}
>
<Link
className="justify-start!"
to="/project/$ref/integrations/$id"
params={{ ref: ref ?? '_', id: 'graphiql' }}
>
GraphiQL
</Link>
</Button>
<Button block asChild variant="text" size="small" icon={<BookOpenIcon />}>
<a
href={`${DOCS_URL}/guides/graphql`}
target="_blank"
rel="noreferrer noopener"
className="justify-start!"
>
GraphQL guide
</a>
</Button>
</div>
<div className="px-2 py-4">
<Button block asChild variant="text" size="small" icon={<BookIcon />}>
<a
href={`${DOCS_URL}`}
target="_blank"
rel="noreferrer noopener"
className="justify-start!"
>
Documentation
</a>
</Button>
<Button block asChild variant="text" size="small" icon={<BookOpenIcon />}>
<a
href={`${DOCS_URL}/guides/api`}
target="_blank"
rel="noreferrer noopener"
className="justify-start!"
>
REST guide
</a>
</Button>
</div>
</>
)
}
type SubsectionsProps = {
category: DocsCategory
}
const Subsections = ({ category }: SubsectionsProps): ReactNode => {
const snippets = getSectionSnippets(category)
return (
<div className="space-y-2 py-2">
{snippets.map((snippet) => (
<button
key={snippet.key}
tabIndex={0}
className={MENU_BUTTON_CLASSES}
onClick={() => {
navigateToSection(snippet.key)
}}
>
{snippet.title}
</button>
))}
{category === API_DOCS_CATEGORIES.ENTITIES && <TablesSubsections />}
{category === API_DOCS_CATEGORIES.STORED_PROCEDURES && <DbFunctionsSubsections />}
{category === API_DOCS_CATEGORIES.STORAGE && <StorageSubsections />}
{category === API_DOCS_CATEGORIES.EDGE_FUNCTIONS && <EdgeFunctionsSubsections />}
</div>
)
}
const TablesSubsections = (): ReactNode => {
const snap = useAppStateSnapshot()
const { visibleEntities: tables, excludedCount, isLoading } = useApiDocsTables()
// TODO: handle infinite loading of tables
return (
<>
{isLoading && <LoadingIndicator />}
{(tables.length > 0 || excludedCount > 0) && <Separator />}
{tables.map((table) => (
<button
key={table.name}
tabIndex={0}
className={MENU_BUTTON_CLASSES}
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.ENTITIES, table.name])}
>
{table.name}
</button>
))}
<NotExposedEntitiesIndicator
count={excludedCount}
entityNoun="table"
entityNounPlural="tables"
onNavigate={() => snap.setShowProjectApiDocs(false)}
/>
</>
)
}
const DbFunctionsSubsections = (): ReactNode => {
const snap = useAppStateSnapshot()
const { visibleEntities: functions, excludedCount, isLoading } = useApiDocsFunctions()
// TODO: handle virtualization of DB functions
return (
<>
{isLoading && <LoadingIndicator />}
{(functions.length > 0 || excludedCount > 0) && <Separator />}
{functions.map((fn) => (
<button
key={fn.name}
tabIndex={0}
className={MENU_BUTTON_CLASSES}
onClick={() =>
snap.setActiveDocsSection([API_DOCS_CATEGORIES.STORED_PROCEDURES, fn.name])
}
>
{fn.name}
</button>
))}
<NotExposedEntitiesIndicator
count={excludedCount}
entityNoun="function"
entityNounPlural="functions"
onNavigate={() => snap.setShowProjectApiDocs(false)}
/>
</>
)
}
const BucketButton = ({ item: bucket, style }: RowComponentBaseProps<Bucket>) => {
const snap = useAppStateSnapshot()
return (
<button
key={bucket.name}
tabIndex={0}
className={cn(MENU_BUTTON_CLASSES, 'py-1')}
style={style}
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.STORAGE, bucket.name])}
>
{bucket.name}
</button>
)
}
const StorageSubsections = (): ReactNode => {
const { ref } = useParams()
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage } =
usePaginatedBucketsQuery({
projectRef: ref,
})
const buckets = data?.pages.flatMap((page) => page) ?? []
return (
<>
{isLoading && <LoadingIndicator />}
{buckets.length > 0 && <Separator />}
<InfiniteListDefault
className="max-h-80"
items={buckets}
getItemKey={(idx) => buckets[idx]?.name}
getItemSize={() => 28}
hasNextPage={!!hasNextPage}
isLoadingNextPage={isFetchingNextPage}
onLoadNextPage={fetchNextPage}
ItemComponent={BucketButton}
LoaderComponent={({ style }) => <LoadingIndicator style={{ ...style, width: '75%' }} />}
/>
</>
)
}
const EdgeFunctionsSubsections = (): ReactNode => {
const { ref } = useParams()
const snap = useAppStateSnapshot()
const { data: edgeFunctions, isLoading } = useEdgeFunctionsQuery({ projectRef: ref })
// TODO: handle virtualization of edge functions
return (
<>
{isLoading && <LoadingIndicator />}
{(edgeFunctions ?? []).length > 0 && <Separator />}
{(edgeFunctions ?? []).map((fn) => (
<button
key={fn.name}
tabIndex={0}
className={MENU_BUTTON_CLASSES}
onClick={() => snap.setActiveDocsSection([API_DOCS_CATEGORIES.EDGE_FUNCTIONS, fn.name])}
>
{fn.name}
</button>
))}
</>
)
}
type LoadingIndicatorProps = {
className?: string
style?: React.CSSProperties
}
const LoadingIndicator = ({ className, style }: LoadingIndicatorProps) => (
<ShimmeringLoader style={style} className={cn('mx-2', className)} />
)