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>
270 lines
12 KiB
TypeScript
270 lines
12 KiB
TypeScript
import { OAuthScope } from '@supabase/shared-types/out/constants'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { CheckCircle2Icon, ChevronRightIcon, ChevronsLeftRightIcon } from 'lucide-react'
|
|
import { toast } from 'sonner'
|
|
import { Button, cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
|
|
import { ScopeSection } from '../OAuthApps/AuthorizeRequesterDetails'
|
|
import { PERMISSIONS_DESCRIPTIONS } from '../OAuthApps/OAuthApps.constants'
|
|
import { ProjectClaimLayout } from './layout'
|
|
import { useApiAuthorizationApproveMutation } from '@/data/api-authorization/api-authorization-approve-mutation'
|
|
import { ApiAuthorizationResponse } from '@/data/api-authorization/api-authorization-query'
|
|
import { useOrganizationProjectClaimMutation } from '@/data/organizations/organization-project-claim-mutation'
|
|
import { OrganizationProjectClaimResponse } from '@/data/organizations/organization-project-claim-query'
|
|
import { useInvalidateProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query'
|
|
import { BASE_PATH } from '@/lib/constants'
|
|
import type { Organization } from '@/types'
|
|
|
|
export const ProjectClaimConfirm = ({
|
|
selectedOrganization,
|
|
projectClaim,
|
|
requester,
|
|
setStep,
|
|
}: {
|
|
selectedOrganization: Organization
|
|
projectClaim: OrganizationProjectClaimResponse
|
|
requester: ApiAuthorizationResponse
|
|
setStep: (step: 'choose-org' | 'benefits' | 'confirm') => void
|
|
}) => {
|
|
const navigate = useNavigate()
|
|
const { auth_id, token: claimToken } = useParams()
|
|
const { invalidateProjectsQuery } = useInvalidateProjectsInfiniteQuery()
|
|
|
|
const { mutateAsync: approveRequest, isPending: isApproving } =
|
|
useApiAuthorizationApproveMutation()
|
|
|
|
const { mutateAsync: claimProject, isPending: isClaiming } = useOrganizationProjectClaimMutation()
|
|
|
|
const onClaimProject = async () => {
|
|
try {
|
|
const response = await approveRequest({ id: auth_id!, slug: selectedOrganization.slug })
|
|
|
|
await claimProject({
|
|
slug: selectedOrganization.slug,
|
|
token: claimToken!,
|
|
})
|
|
|
|
toast.success('Project claimed successfully')
|
|
try {
|
|
// check if the redirect url is valid. If not, redirect the user to the org dashboard
|
|
const url = new URL(response.url)
|
|
window.location.href = url.toString()
|
|
} catch {
|
|
// invalidate the org projects to force them to be refetched
|
|
await invalidateProjectsQuery()
|
|
navigate({ to: '/org/$slug', params: { slug: selectedOrganization.slug } })
|
|
}
|
|
} catch (error: any) {
|
|
toast.error(`Failed to claim project ${error.message}`)
|
|
}
|
|
}
|
|
|
|
const isLoading = isApproving || isClaiming
|
|
|
|
return (
|
|
<ProjectClaimLayout
|
|
title={
|
|
<>
|
|
Claim a project <span className="text-primary">{projectClaim?.project?.name}</span> from{' '}
|
|
<span className="text-primary">{requester?.name}</span>
|
|
</>
|
|
}
|
|
>
|
|
<div className="py-6 space-y-8 text-sm">
|
|
<div className="flex flex-col items-center mt-6">
|
|
<div className="flex items-center">
|
|
<div
|
|
className={cn(
|
|
'w-8 h-8 bg-center bg-no-repeat bg-cover flex items-center justify-center rounded-md'
|
|
)}
|
|
style={{
|
|
backgroundImage: !!requester.icon ? `url('${requester.icon}')` : 'none',
|
|
}}
|
|
>
|
|
{!requester.icon && (
|
|
<p className="text-foreground-light text-lg">{requester.name?.[0] ?? '?'}</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex items-center justify-center w-28 relative">
|
|
<div className="h-0.5 w-full border-2 border-dashed border-stronger" />
|
|
<div className="rounded-full border flex items-center justify-center h-10 w-full shadow-xs">
|
|
<ChevronsLeftRightIcon className="text-muted-foreground" size={24} />
|
|
</div>
|
|
<div className="h-0.5 w-full border-2 border-dashed border-stronger z-10" />
|
|
</div>
|
|
|
|
<div className="w-8 h-8">
|
|
<img
|
|
src={`${BASE_PATH}/img/supabase-logo.svg`}
|
|
alt="Supabase Logo"
|
|
className="w-full h-full"
|
|
width={100}
|
|
height={100}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="space-y-4 text-foreground-light">
|
|
<p>
|
|
By claiming the <span className="text-foreground">{projectClaim?.project?.name}</span>{' '}
|
|
project from <span className="text-foreground">{requester?.name}</span>, the following
|
|
will happen:
|
|
</p>
|
|
<ul className="space-y-3">
|
|
<li className="flex space-x-2">
|
|
<span>
|
|
<CheckCircle2Icon className="text-primary h-5 w-5" />
|
|
</span>
|
|
<span>
|
|
The project will be transferred to your Supabase organization{' '}
|
|
<span className="text-foreground">{selectedOrganization.name}.</span>{' '}
|
|
<a
|
|
href="#"
|
|
onClick={() => setStep('choose-org')}
|
|
className="text-foreground-light underline"
|
|
>
|
|
Choose another organization?
|
|
</a>
|
|
</span>
|
|
</li>
|
|
<li className="flex space-x-2">
|
|
<span>
|
|
<CheckCircle2Icon className="text-primary h-5 w-5" />
|
|
</span>
|
|
<span>
|
|
<span className="text-foreground">{requester?.name}</span> will receive API access
|
|
(permissions listed below) to all projects within your organization to continue
|
|
providing its functionality to the application you've built.
|
|
</span>
|
|
</li>
|
|
<li className="flex space-x-2">
|
|
<span>
|
|
<CheckCircle2Icon className="text-primary h-5 w-5" />
|
|
</span>
|
|
<span>
|
|
You'll be responsible for maintaining the project, which may include additional
|
|
costs.
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
<Admonition type="caution">
|
|
<div className="text-foreground-light">
|
|
Upon claiming, the project may undergo a short downtime (less than 10 minutes) for
|
|
resizing.
|
|
</div>
|
|
</Admonition>
|
|
</div>
|
|
<div className="flex space-y-4 flex-col">
|
|
{requester.scopes.length === 0 ? (
|
|
<span className="text-foreground-light">
|
|
<span className="text-foreground">{requester?.name}</span> hasn't requested any
|
|
permissions to operate. This is normal and no action is needed from your side.
|
|
</span>
|
|
) : (
|
|
<Collapsible>
|
|
<CollapsibleTrigger className="pb-3 w-full flex items-center justify-between group">
|
|
<p className="text-sm text-foreground-light text-left">
|
|
<span className="font-foreground">List of permissions</span> that{' '}
|
|
<span className="text-foreground">{requester.name}</span> will have for the{' '}
|
|
<span className="text-amber-900">
|
|
selected organization and all of its projects.
|
|
</span>
|
|
</p>
|
|
|
|
<ChevronRightIcon
|
|
size={16}
|
|
className="text-foreground-light transition-all group-data-open:rotate-90 w-20"
|
|
strokeWidth={1}
|
|
/>
|
|
</CollapsibleTrigger>
|
|
<CollapsibleContent
|
|
className={cn(
|
|
'flex flex-col gap-8 transition-all',
|
|
'data-closed:animate-collapsible-up data-open:animate-collapsible-down'
|
|
)}
|
|
>
|
|
<div>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.ANALYTICS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.ANALYTICS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.ANALYTICS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.ANALYTICS_CONFIG}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.ANALYTICS_CONFIG_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.ANALYTICS_CONFIG_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.AUTH}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.AUTH_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.AUTH_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.DATABASE}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.DATABASE_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.DATABASE_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.DOMAINS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.DOMAINS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.DOMAINS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.EDGE_FUNCTIONS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.EDGE_FUNCTIONS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.EDGE_FUNCTIONS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.ENVIRONMENT}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.ENVIRONMENT_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.ENVIRONMENT_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.ORGANIZATIONS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.ORGANIZATIONS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.ORGANIZATIONS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.PROJECTS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.PROJECTS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.PROJECTS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.REST}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.REST_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.REST_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.SECRETS}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.SECRETS_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.SECRETS_WRITE)}
|
|
/>
|
|
<ScopeSection
|
|
description={PERMISSIONS_DESCRIPTIONS.STORAGE}
|
|
hasReadScope={requester.scopes.includes(OAuthScope.STORAGE_READ)}
|
|
hasWriteScope={requester.scopes.includes(OAuthScope.STORAGE_WRITE)}
|
|
/>
|
|
</div>
|
|
</CollapsibleContent>
|
|
</Collapsible>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="flex justify-center sticky bottom-0">
|
|
<Button
|
|
variant="primary"
|
|
size="medium"
|
|
loading={isLoading}
|
|
disabled={isLoading}
|
|
onClick={onClaimProject}
|
|
>
|
|
Claim project {projectClaim?.project?.name}
|
|
</Button>
|
|
</div>
|
|
</ProjectClaimLayout>
|
|
)
|
|
}
|