mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 2 of a 6-PR stack migrating all `next/router` and `next/compat/router` imports in `apps/studio` onto TanStack Router hooks and removing the router shims. | Part | PR | Scope | | --- | --- | --- | | 1 | #54053 | Core navigation helpers, `hooks/**`, `lib/**`, `data/prefetchers/**` | | **2** | **#54054 ← this PR** | **`components/ui/**`** | | 3 | #54055 | `components/layouts/**` and `state/tabs.tsx` | | 4 | #54056 | Database, Branching, Compute, Edge Functions, Explorer, SQL Editor, Storage, Table Editor | | 5 | #54057 | Remaining `components/interfaces/**` and `QueryInsightsTable` router events | | 6 | #54058 | Remove `next/router` & `next/compat/router` shims, `_router-events.ts`, Vite aliases, and test mocks | Migrates all 15 `apps/studio/components/ui/**` files off `next/router`. **Changed:** - Replaced `useRouter` across `AIAssistantPanel` (`AIAssistant`, `ModelSelector`), `Charts/ComposedChartHandler`, `EditorPanel`, `ErrorBoundary` (`ClientSideExceptionHandler`, `GlobalErrorBoundaryState`, `InsertBeforeRemoveChildErrorHandler`), `GlobalShortcuts/ShortcutsReferenceSheet`, `HelpPanel` (`HelpOptionsList`, `HelpPanel`), `ProductMenu/ProductMenuShortcuts`, `QueryBlock/EditQueryButton`, and `ResourceExhaustionWarningBanner` with TanStack's `useNavigate`, `useLocation`, `useRoutePattern`, and `useParams` from `common` - Updated `AIAssistant.test.tsx`, `HelpOptionsList.test.tsx`, and `ProductMenuShortcuts.test.tsx` to use TanStack Router instead of `next/router` mocks **Simplified:** - `EditQueryButton` and `ShortcutsReferenceSheet` match against `useRoutePattern()` instead of the real pathname, as `router.pathname` did before. A ref or slug containing `sql` or `advisors` no longer misfires. - Removed the unused `restrictToRoutes` field from `ResourceExhaustionWarningBanner` (no warning sets it) - `AIAssistant` clears the handoff param with `navigate({ to: '.' })`, dropping a pathname subscription and an `AnyRouter` cast - `ProductMenuShortcuts` inlines its handler (`useShortcut` always calls the latest callback) - Moved the `AdvisorsNavigationShortcuts.test.tsx` fix into this PR so it passes on its own - Tests use the shared `createTestRouter` and `customRender` router Addresses [FE-5109](https://linear.app/supabase/issue/FE-5109/replace-the-nextrouter-shims-with-tanstack-router-hooks) ## To test - [ ] AI Assistant panel links, model selector navigation, and "Edit in SQL Editor" (`EditQueryButton`) navigate cleanly - [ ] Keyboard shortcuts in `ProductMenuShortcuts` and the shortcuts reference sheet (`?`) match the active section and navigate as expected - [ ] Error boundary recovery ("Reload page" / navigation actions) and Help panel links still work - [ ] Resource exhaustion warning banner matches project routes as before --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
148 lines
4.6 KiB
TypeScript
148 lines
4.6 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { ActivityIcon, BookOpenIcon, ChevronRightIcon, MailIcon, WrenchIcon } from 'lucide-react'
|
|
import type { ReactNode } from 'react'
|
|
import SVG from 'react-inlinesvg'
|
|
import { AiIconAnimation } from 'ui'
|
|
|
|
import type { HelpOptionId } from './HelpPanel.constants'
|
|
import { HELP_OPTION_IDS } from './HelpPanel.constants'
|
|
import type { SupportFormUrlKeys } from '@/components/interfaces/Support/SupportForm.utils'
|
|
import { createSupportFormUrl } from '@/components/interfaces/Support/SupportForm.utils'
|
|
import { ResourceItem } from '@/components/ui/Resource/ResourceItem'
|
|
import { ResourceList } from '@/components/ui/Resource/ResourceList'
|
|
import { takeBreadcrumbSnapshot } from '@/lib/breadcrumbs'
|
|
import { BASE_PATH, DOCS_URL } from '@/lib/constants'
|
|
import { navigateToUrl } from '@/lib/navigation'
|
|
|
|
const DISCORD_URL = 'https://discord.supabase.com'
|
|
const STATUS_URL = 'https://status.supabase.com'
|
|
|
|
type HelpOptionsListProps = {
|
|
excludeIds?: HelpOptionId[]
|
|
isPlatform: boolean
|
|
projectRef: string | undefined
|
|
supportLinkQueryParams: Partial<SupportFormUrlKeys> | undefined
|
|
onAssistantClick?: () => void
|
|
onSupportClick?: () => boolean | void
|
|
}
|
|
|
|
type HelpOption = {
|
|
media: ReactNode
|
|
title: string
|
|
description: string
|
|
href?: string
|
|
onClick?: () => void
|
|
}
|
|
|
|
export const HelpOptionsList = ({
|
|
excludeIds = [],
|
|
isPlatform,
|
|
projectRef,
|
|
supportLinkQueryParams,
|
|
onAssistantClick,
|
|
onSupportClick,
|
|
}: HelpOptionsListProps) => {
|
|
const navigate = useNavigate()
|
|
|
|
const ids = HELP_OPTION_IDS.filter((id) => !excludeIds.includes(id))
|
|
|
|
const include = (id: HelpOptionId): boolean => {
|
|
if (id === 'assistant') return !!projectRef
|
|
if (id === 'status' || id === 'support') return isPlatform
|
|
return true
|
|
}
|
|
|
|
const filteredIds = ids.filter(include)
|
|
|
|
const handleSupportClick = () => {
|
|
const shouldNavigate = onSupportClick?.()
|
|
if (shouldNavigate === false) {
|
|
return
|
|
}
|
|
|
|
takeBreadcrumbSnapshot()
|
|
void navigateToUrl(navigate, createSupportFormUrl(supportLinkQueryParams ?? {}))
|
|
}
|
|
|
|
const renderOption = (title: string, description: string) => (
|
|
<div className="flex flex-col gap-0.5">
|
|
<p className="text-sm text-foreground">{title}</p>
|
|
<p className="text-xs text-foreground-lighter">{description}</p>
|
|
</div>
|
|
)
|
|
|
|
const options: Record<HelpOptionId, HelpOption> = {
|
|
assistant: {
|
|
media: <AiIconAnimation allowHoverEffect size={14} />,
|
|
title: 'Supabase Assistant',
|
|
description: 'Get guided help with your project directly in Studio.',
|
|
onClick: onAssistantClick,
|
|
},
|
|
docs: {
|
|
media: <BookOpenIcon strokeWidth={1.5} size={14} />,
|
|
title: 'Docs',
|
|
description: 'Browse guides, references, and product documentation.',
|
|
href: `${DOCS_URL}/`,
|
|
},
|
|
troubleshooting: {
|
|
media: <WrenchIcon strokeWidth={1.5} size={14} />,
|
|
title: 'Troubleshooting',
|
|
description: 'Find fixes for common platform issues and errors.',
|
|
href: `${DOCS_URL}/guides/troubleshooting?products=platform`,
|
|
},
|
|
discord: {
|
|
media: <SVG src={`${BASE_PATH}/img/discord-icon.svg`} className="h-4 w-4" />,
|
|
title: 'Ask on Discord',
|
|
description: 'Get help from the community on code-related questions.',
|
|
href: DISCORD_URL,
|
|
},
|
|
status: {
|
|
media: <ActivityIcon strokeWidth={1.5} size={14} />,
|
|
title: 'Supabase status',
|
|
description: 'Check incidents, maintenance, and uptime updates.',
|
|
href: STATUS_URL,
|
|
},
|
|
support: {
|
|
media: <MailIcon strokeWidth={1.5} size={14} />,
|
|
title: 'Contact support',
|
|
description: 'Reach support for account and platform issues.',
|
|
onClick: handleSupportClick,
|
|
},
|
|
}
|
|
|
|
return (
|
|
<ResourceList className="rounded-none border-0 bg-transparent shadow-none">
|
|
{filteredIds.map((id) => {
|
|
const option = options[id]
|
|
|
|
if (option.href) {
|
|
return (
|
|
<ResourceItem
|
|
key={id}
|
|
className="!border-b"
|
|
media={option.media}
|
|
meta={<ChevronRightIcon strokeWidth={1.5} size={16} />}
|
|
href={option.href}
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
>
|
|
{renderOption(option.title, option.description)}
|
|
</ResourceItem>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ResourceItem
|
|
key={id}
|
|
className="!border-b"
|
|
media={option.media}
|
|
onClick={option.onClick}
|
|
>
|
|
{renderOption(option.title, option.description)}
|
|
</ResourceItem>
|
|
)
|
|
})}
|
|
</ResourceList>
|
|
)
|
|
}
|