mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 3 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 | `components/ui/**` | | **3** | **#54055 ← this PR** | **`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 `apps/studio/components/layouts/**` files and the studio tab router integration off `next/router`. **Added:** - `useTabRouter()` in `apps/studio/state/tabs.tsx` so tab state actions navigate via TanStack's `useNavigate` + `navigateToUrl` instead of taking a `NextRouter` instance **Changed:** - Replaced `useRouter` across all layout directories (`AccountLayout`, `AdvisorsLayout`, `AppLayout`, `AuthLayout`, `BranchLayout`, `ComputeLayout`, `DatabaseLayout`, `DefaultLayout`, `EdgeFunctionsLayout`, `ExplorerLayout`, `LogsLayout`, `Navigation/*`, `ObservabilityLayout`, `OrganizationLayout`, `ProjectLayout`, `ProjectNeedsSecuring`, `ProjectSettingsLayout`, `RealtimeLayout`, `SQLEditorLayout`, `SignInLayout`, and `Tabs`) with TanStack Router hooks (`useNavigate`, `useLocation`, `useRoutePattern`) and `useParams` from `common` - Updated `ProjectDropdown.utils.ts` and `ProjectDropdown.test.ts` to work with TanStack `$param` route templates - Updated layout component tests (`AccountLayout.selfhosted.test.tsx`, `AdvisorsNavigationShortcuts.test.tsx`, `BranchLink.test.tsx`, `ExplorerLayout.test.tsx`, `ExplorerNavChats.test.tsx`, `ObservabilityMenu.utils.test.tsx`, `MobileIssuesNavigation.platform.test.tsx`, `ProjectLayout/index.test.tsx`, `ProjectNeedsSecuring.test.tsx`, `ProjectDropdown.test.tsx`) **Simplified:** - `OrganizationLayout` and `SettingsLayout` match against `useRoutePattern()` instead of the real pathname. An org slug ending in a settings segment (e.g. `acmeapps`) no longer gets the settings title. - `ProjectSettings.Commands` opens the Connect sheet through nuqs, the same way `Connect.Commands` does - `OrgMenuContent`, `OrganizationSettingsMenu` and `useTabRouter` read `orgSlug`/`schema` from `useParams` instead of casting `location.search` - Removed the dead `getPathnameWithoutQuery` helpers and their tests - `usePreservedQueryParams` builds its string in the `useLocation` selector (no `useMemo`), and `UnhealthyState` only navigates when `ref` is set - Moved `MobileIssuesNavigation.platform.test.tsx` onto a TanStack test router. It now covers the active-route logic again. - 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 - [ ] Switching projects, organizations, and branches from the top header dropdowns preserves the current sub-route where supported - [ ] Opening, switching, and closing Table Editor / SQL Editor tabs updates the URL and active tab cleanly - [ ] Active sidebar item highlighting works across Database, Auth, Edge Functions, Observability, Logs, Realtime, Explorer, and Project Settings layouts - [ ] Mobile navigation menu and floating toolbar sheets open and navigate properly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
280 lines
9.3 KiB
TypeScript
280 lines
9.3 KiB
TypeScript
import { useFlag, useParams } from 'common'
|
|
import { parseAsBoolean, useQueryState } from 'nuqs'
|
|
import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'
|
|
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
|
|
import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
|
|
|
|
import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
|
|
import { useIsPlatformWebhooksEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useIsAwsCloudProvider } from '@/hooks/misc/useSelectedProject'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export function useProjectSettingsGotoCommands(options?: CommandOptions) {
|
|
const [, setShowConnect] = useQueryState('showConnect', parseAsBoolean.withDefault(false))
|
|
const setIsOpen = useSetCommandMenuOpen()
|
|
let { ref, slug } = useParams()
|
|
const platformWebhooksEnabled = useIsPlatformWebhooksEnabled()
|
|
const showConfigDrift = useFlag('ConfigDrift')
|
|
ref ||= '_'
|
|
const hasOrgSlug = typeof slug === 'string' && slug.length > 0 && slug !== '_'
|
|
const isAws = useIsAwsCloudProvider()
|
|
|
|
const {
|
|
logsAll,
|
|
projectSettingsLogDrains,
|
|
projectSettingsCustomDomains,
|
|
authenticationSignInProviders,
|
|
infrastructureReadReplicas,
|
|
projectAddonsDedicatedIpv4Address,
|
|
} = useIsFeatureEnabled([
|
|
'logs:all',
|
|
'project_settings:log_drains',
|
|
'project_settings:custom_domains',
|
|
'authentication:sign_in_providers',
|
|
'infrastructure:read_replicas',
|
|
'project_addons:dedicated_ipv4_address',
|
|
])
|
|
|
|
// Log drains depend on the analytics backend, gated by logs:all (see SettingsMenu.utils).
|
|
const showLogDrains = logsAll && projectSettingsLogDrains
|
|
|
|
useRegisterCommands(
|
|
COMMAND_MENU_SECTIONS.NAVIGATE,
|
|
[
|
|
{
|
|
id: 'nav-project-settings-add-ons',
|
|
name: 'Add-ons',
|
|
keywords: ['addons', 'add ons', 'add on', 'add-on'],
|
|
route: `/project/${ref}/settings/addons`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-infrastructure',
|
|
name: 'Infrastructure',
|
|
route: `/project/${ref}/settings/infrastructure`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-compute-size',
|
|
name: 'Compute size',
|
|
keywords: ['compute', 'instance size', 'cpu', 'memory', 'ram', 'upgrade compute'],
|
|
route: `/project/${ref}/settings/infrastructure#compute`,
|
|
defaultHidden: true,
|
|
},
|
|
...(infrastructureReadReplicas
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-read-replicas',
|
|
name: 'Read replicas',
|
|
keywords: ['replica', 'replicas', 'read replica', 'replication', 'multi region'],
|
|
route: `/project/${ref}/settings/infrastructure#read-replicas`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
...(isAws
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-advanced-disk',
|
|
name: 'Advanced disk',
|
|
keywords: ['disk', 'iops', 'throughput', 'disk size', 'disk performance'],
|
|
route: `/project/${ref}/settings/infrastructure#advanced`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
...(projectAddonsDedicatedIpv4Address
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-dedicated-ipv4',
|
|
name: 'Dedicated IPv4 address',
|
|
keywords: ['ipv4', 'ip address', 'static ip', 'dedicated ip'],
|
|
route: `/project/${ref}/settings/addons?panel=ipv4`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-general',
|
|
name: 'General settings',
|
|
route: `/project/${ref}/settings/general`,
|
|
defaultHidden: true,
|
|
},
|
|
...(IS_PLATFORM && showConfigDrift
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-code-configuration',
|
|
name: 'Code configuration',
|
|
route: `/project/${ref}/settings/code-configuration`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-database',
|
|
name: 'Database settings',
|
|
route: `/project/${ref}/database/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-auth',
|
|
name: 'Auth settings',
|
|
route: authenticationSignInProviders
|
|
? `/project/${ref}/auth/providers`
|
|
: `/project/${ref}/database/policies`,
|
|
defaultHidden: true,
|
|
},
|
|
...(platformWebhooksEnabled
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-webhooks',
|
|
name: 'Project webhooks',
|
|
route: `/project/${ref}/settings/webhooks`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
...(hasOrgSlug
|
|
? [
|
|
{
|
|
id: 'nav-organization-settings-webhooks',
|
|
name: 'Organization Webhooks',
|
|
route: `/org/${slug}/webhooks`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-api',
|
|
name: 'API settings',
|
|
route: `/project/${ref}/integrations/data_api/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-integration',
|
|
name: 'Project Integrations',
|
|
keywords: [
|
|
'Branch integration',
|
|
'Vercel integration',
|
|
'GitHub integration',
|
|
'AWS PrivateLink',
|
|
],
|
|
route: `/project/${ref}/settings/integrations`,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-storage',
|
|
name: 'Storage settings',
|
|
route: `/project/${ref}/storage/settings`,
|
|
defaultHidden: true,
|
|
},
|
|
...(projectSettingsCustomDomains
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-custom-domains',
|
|
name: 'Custom domains',
|
|
keywords: ['custom domain', 'domain', 'vanity domain', 'cname'],
|
|
route: `/project/${ref}/settings/general#custom-domains`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
{
|
|
id: 'nav-project-settings-restart-project',
|
|
name: 'Project availability',
|
|
keywords: ['restart project', 'pause project', 'resume project'],
|
|
route: `/project/${ref}/settings/general#restart-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-pause-project',
|
|
name: 'Pause project',
|
|
route: `/project/${ref}/settings/general#pause-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-transfer-project',
|
|
name: 'Transfer project',
|
|
route: `/project/${ref}/settings/general#transfer-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-delete-project',
|
|
name: 'Delete project',
|
|
route: `/project/${ref}/settings/general#delete-project`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-database-password',
|
|
name: 'Database password',
|
|
route: `/project/${ref}/database/settings#database-password`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-reset-database-password',
|
|
name: 'Reset database password',
|
|
route: `/project/${ref}/database/settings#database-password`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-connection-string',
|
|
name: 'Connection string',
|
|
action: () => {
|
|
setShowConnect(true)
|
|
setIsOpen(false)
|
|
},
|
|
defaultHidden: true,
|
|
} as ICommand,
|
|
{
|
|
id: 'nav-project-settings-connection-pooling',
|
|
name: 'Connection pooling',
|
|
route: `/project/${ref}/database/settings#connection-pooler`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-ssl-configuration',
|
|
name: 'SSL configuration',
|
|
route: `/project/${ref}/database/settings#ssl-configuration`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-network-restrictions',
|
|
name: 'Network restrictions',
|
|
route: `/project/${ref}/database/settings#network-restrictions`,
|
|
defaultHidden: true,
|
|
},
|
|
{
|
|
id: 'nav-project-settings-banned-ips',
|
|
name: 'Banned IPs',
|
|
route: `/project/${ref}/database/settings#banned-ips`,
|
|
defaultHidden: true,
|
|
},
|
|
...(showLogDrains
|
|
? [
|
|
{
|
|
id: 'nav-project-settings-log-drains',
|
|
name: 'Log drains',
|
|
keywords: ['log drain', 'export logs', 'logs export'],
|
|
route: `/project/${ref}/settings/log-drains`,
|
|
defaultHidden: true,
|
|
} as IRouteCommand,
|
|
]
|
|
: []),
|
|
],
|
|
{
|
|
...options,
|
|
deps: [
|
|
platformWebhooksEnabled,
|
|
showLogDrains,
|
|
showConfigDrift,
|
|
projectSettingsCustomDomains,
|
|
infrastructureReadReplicas,
|
|
projectAddonsDedicatedIpv4Address,
|
|
isAws,
|
|
ref,
|
|
slug,
|
|
],
|
|
}
|
|
)
|
|
}
|