mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 5 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 | `components/layouts/**` and `state/tabs.tsx` | | 4 | #54056 | Database, Branching, Compute, Edge Functions, Explorer, SQL Editor, Storage, Table Editor | | **5** | **#54057 ← this PR** | **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 remaining `apps/studio/components/interfaces/**` directories off `next/router`, including the last production `router.events` consumer (`QueryInsightsTable`) and the only default `next/router` import (`DiscordCTACard`). After this PR, zero files under `apps/studio/components/**` import `next/router` or `next/compat/router`. **Added:** - `apps/studio/components/interfaces/QueryInsights/QueryInsightsTable/QueryInsightsTable.test.tsx`: verifies that pathname changes clear selected query state without mutating destination or history search params, while same-pathname search updates preserve selection **Changed:** - Replaced the sole production `router.events.on('routeChangeStart', ...)` consumer in `QueryInsightsTable.tsx` with a `pathname` effect that clears `onCurrentSelectQuery` on pathname changes, and derived `searchQuery` directly from `nuqs` (`urlSearch`) instead of mirroring it in local state. Drops the legacy `setQueryStates({ search: null })` call on leave, which ran after `history.push` on TanStack Router (targeting the destination URL rather than the previous history entry, while browser Back is expected to restore previous search params). - Removed the `router: NextRouter` prop from `ReportWidgetRendererProps` in `Reports/ReportWidget.tsx` and updated its callers (`ChartBlock`, `ReportHeader`, `CreateReportModal`) - Updated `LOG_ROUTES_WITH_REPLICA_SUPPORT` in `Settings/Logs/Logs.constants.ts` from `[ref]` to `$ref` for TanStack route patterns - Replaced the default `import router from 'next/router'` in `Support/DiscordCTACard.tsx` with `useNavigate` - Replaced `useRouter` across `Account`, `Advisors`, `App`, `Auth`, `ErrorHandling`, `Home`, `HomePageActions`, `Integrations`, `Linter`, `LocalDropdown`, `Observability`, `Organization`, `OrganizationInvite`, `Platform/Webhooks`, `Project`, `ProjectCreation`, `ProjectHome`, `QueryPerformance`, `RedeemCredits`, `Settings`, `Sidebar`, `SignIn`, `Support`, `UnifiedLogs`, and `UserDropdown` - Updated affected tests (`Auth/Users/UserPanel`, `Home/ProjectList`, `LocalDropdown`, `Organization/*`, `OrganizationInvite`, `RedeemCredits`, `Settings/General/*`, `SignIn/SignInRecoveryCodeForm`, `UnifiedLogs/*`) **Simplified:** - `LocalDropdown`, `UserDropdown` and `RedeemCredits` build the current route from `location.href`, so the hash keeps its leading `#` - `NewOrgForm` navigates to the `returnTo` path instead of an absolute URL, which was being treated as external. It also uses a typed `/new/$slug` navigate. - Read search params from `useParams()` instead of `location.search` casts (`CronJobPage`, `QueuePage`, `LogsPreviewer`, `LinkSupportTicketPage`, `MarketplaceSidebar`, `PlanCards`, `SignUpForm`) - Dropped the dead `isReady`/`isRouterReady` constants and the `navigate<AnyRouter, string>` casts where typed routes work (`ForgotPasswordWizard`, `SignInPartner`, `ReportWidget`, `ProjectUpgradeAlert`) - Linter, `ReportHeader` and `LogsPreviewer` use `to: '.'` instead of a separate pathname subscription. `CreateReportModal` builds the preserved query params in `onSuccess` instead of a `useMemo`. - Tests use the shared `createTestRouter` and `customRender` router. `LocalDropdown` now tests that the hash is kept. Addresses [FE-5109](https://linear.app/supabase/issue/FE-5109/replace-the-nextrouter-shims-with-tanstack-router-hooks) ## To test - [x] Query Insights: select a query and confirm search/filter updates keep selection while switching projects/routes clears it; navigating to Logs keeps Logs' query params intact and pressing Back restores Query Insights' `?search=` param cleanly - [x] Auth / Sign-in flows: sign in, sign up, MFA, recovery code, forgot/reset password, and partner sign-in preserve `returnTo` and redirect as expected - [x] Organization & Project flows: creating an org/project, accepting an org invite, claiming a project, redeeming credits, and deleting/pausing/restarting a project or branch navigate cleanly - [ ] Logs & Reports: replica selector appears on supported log routes (`LOG_ROUTES_WITH_REPLICA_SUPPORT`), saved log queries open, and custom reports create/navigate properly - [ ] Sidebar, LocalDropdown, UserDropdown, Integrations (Cron/Queues/Marketplace), Advisors/Linter, and Unified Logs navigate cleanly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
126 lines
3.8 KiB
TypeScript
126 lines
3.8 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
|
|
import {
|
|
getOrganizationInviteContent,
|
|
getOrganizationInviteStatus,
|
|
type OrganizationInviteStatus,
|
|
} from './OrganizationInvite.utils'
|
|
import type { OrganizationInviteByToken } from '@/data/organization-members/organization-invitation-token-query'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
|
|
const READY_INVITE: OrganizationInviteByToken = {
|
|
authorized_user: true,
|
|
email_match: true,
|
|
expired_token: false,
|
|
invite_id: 42,
|
|
organization_name: 'Acme Corp',
|
|
sso_mismatch: false,
|
|
token_does_not_exist: false,
|
|
}
|
|
|
|
const responseError = (message: string, code = 500) => ({ message, code }) as StudioError
|
|
type StatusOverrides = Partial<Parameters<typeof getOrganizationInviteStatus>[0]>
|
|
|
|
const getStatus = (overrides: StatusOverrides = {}) =>
|
|
getOrganizationInviteStatus({
|
|
data: READY_INVITE,
|
|
error: null,
|
|
isErrorInvitation: false,
|
|
isLoadingInvitation: false,
|
|
isLoadingProfile: false,
|
|
isLoggedIn: true,
|
|
isSuccessInvitation: true,
|
|
profileExists: true,
|
|
...overrides,
|
|
})
|
|
|
|
describe('OrganizationInvite utils', () => {
|
|
test.each<[string, OrganizationInviteStatus, StatusOverrides]>([
|
|
['signed out when there is no current user', 'signed-out', { isLoggedIn: false }],
|
|
['loading while the profile is loading', 'loading', { isLoadingProfile: true }],
|
|
['loading while the invite is loading', 'loading', { isLoadingInvitation: true }],
|
|
[
|
|
'no longer valid for accepted or declined invites',
|
|
'no-longer-valid',
|
|
{
|
|
data: undefined,
|
|
error: responseError('Failed to retrieve organization', 401),
|
|
isErrorInvitation: true,
|
|
isSuccessInvitation: false,
|
|
},
|
|
],
|
|
[
|
|
'invalid when the API returns a missing token response',
|
|
'invalid',
|
|
{
|
|
data: { ...READY_INVITE, token_does_not_exist: true },
|
|
},
|
|
],
|
|
[
|
|
'invalid when the invite lookup 404s',
|
|
'invalid',
|
|
{
|
|
data: undefined,
|
|
error: responseError('Not Found', 404),
|
|
isErrorInvitation: true,
|
|
isSuccessInvitation: false,
|
|
},
|
|
],
|
|
[
|
|
'error for other API failures',
|
|
'error',
|
|
{
|
|
data: undefined,
|
|
error: responseError('Failed to retrieve token', 500),
|
|
isErrorInvitation: true,
|
|
isSuccessInvitation: false,
|
|
},
|
|
],
|
|
[
|
|
'expired when the token has expired',
|
|
'expired',
|
|
{
|
|
data: { ...READY_INVITE, expired_token: true },
|
|
},
|
|
],
|
|
[
|
|
'wrong account when the invite email does not match',
|
|
'wrong-account',
|
|
{
|
|
data: { ...READY_INVITE, email_match: false },
|
|
},
|
|
],
|
|
['ready when the invite can be accepted', 'ready', {}],
|
|
])('returns %s', (_name, expected, overrides) => {
|
|
expect(getStatus(overrides)).toBe(expected)
|
|
})
|
|
|
|
test.each<[OrganizationInviteStatus, string, string | undefined]>([
|
|
['signed-out', 'View invitation', 'Sign in or create an account to view this invitation'],
|
|
['ready', 'Join Acme Corp', 'You have been invited to join this Supabase organization'],
|
|
['wrong-account', 'Wrong account', undefined],
|
|
['expired', 'Invite expired', undefined],
|
|
['invalid', 'Invalid invitation', undefined],
|
|
['no-longer-valid', 'Invite no longer available', undefined],
|
|
['error', 'Unable to load invitation', undefined],
|
|
])('returns content for %s', (status, title, description) => {
|
|
expect(
|
|
getOrganizationInviteContent({
|
|
data: READY_INVITE,
|
|
isSignUpEnabled: true,
|
|
status,
|
|
})
|
|
).toEqual({ title, ...(description ? { description } : {}) })
|
|
})
|
|
|
|
test('omits sign-up copy when sign-up is disabled', () => {
|
|
expect(
|
|
getOrganizationInviteContent({
|
|
data: READY_INVITE,
|
|
isSignUpEnabled: false,
|
|
status: 'signed-out',
|
|
}).description
|
|
).toBe('Sign in to view this invitation')
|
|
})
|
|
})
|