mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +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>
157 lines
4.9 KiB
TypeScript
157 lines
4.9 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useNavigate } from '@tanstack/react-router'
|
|
import { useEffect, useMemo } from 'react'
|
|
import { SubmitHandler, useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Form,
|
|
Separator,
|
|
Sheet,
|
|
SheetContent,
|
|
SheetFooter,
|
|
SheetHeader,
|
|
SheetTitle,
|
|
} from 'ui'
|
|
|
|
import { usePgPartmanStatus } from '../usePgPartmanStatus'
|
|
import { CreateQueueForm, FormSchema } from './CreateQueueSheet.schema'
|
|
import { PartitionConfigFields } from './PartitionConfigFields'
|
|
import { PgPartmanCallout } from './PgPartmanCallout'
|
|
import { QueueNameField } from './QueueNameField'
|
|
import { QueueTypeSelector } from './QueueTypeSelector'
|
|
import { RlsSection } from './RlsSection'
|
|
import { DiscardChangesConfirmationDialog } from '@/components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'
|
|
import { useDatabaseQueueCreateMutation } from '@/data/database-queues/database-queues-create-mutation'
|
|
import { useQueuesExposePostgrestStatusQuery } from '@/data/database-queues/database-queues-expose-postgrest-status-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useConfirmOnClose } from '@/hooks/ui/useConfirmOnClose'
|
|
import { navigateToUrl } from '@/lib/navigation'
|
|
|
|
export interface CreateQueueSheetProps {
|
|
visible: boolean
|
|
onClose: () => void
|
|
}
|
|
|
|
const FORM_ID = 'create-queue-sidepanel'
|
|
|
|
export const CreateQueueSheet = ({ visible, onClose }: CreateQueueSheetProps) => {
|
|
const navigate = useNavigate()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { data: isExposed } = useQueuesExposePostgrestStatusQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const { mutate: createQueue, isPending } = useDatabaseQueueCreateMutation()
|
|
const { isInstalled: pgPartmanInstalled } = usePgPartmanStatus()
|
|
|
|
const defaultValues: CreateQueueForm = useMemo(
|
|
() =>
|
|
pgPartmanInstalled
|
|
? {
|
|
name: '',
|
|
enableRls: true,
|
|
values: { type: 'partitioned', partitionInterval: 10000, retentionInterval: 100000 },
|
|
}
|
|
: { name: '', enableRls: true, values: { type: 'basic' } },
|
|
[pgPartmanInstalled]
|
|
)
|
|
|
|
const form = useForm<CreateQueueForm>({
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues,
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (visible) {
|
|
form.reset(defaultValues)
|
|
}
|
|
}, [form, defaultValues, visible])
|
|
|
|
const checkIsDirty = () => form.formState.isDirty
|
|
|
|
const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({
|
|
checkIsDirty,
|
|
onClose,
|
|
})
|
|
|
|
const onSubmit: SubmitHandler<CreateQueueForm> = async ({ name, enableRls, values }) => {
|
|
if (!project?.ref) {
|
|
toast.error('Project not found')
|
|
return
|
|
}
|
|
|
|
createQueue(
|
|
{
|
|
projectRef: project.ref,
|
|
connectionString: project?.connectionString,
|
|
name,
|
|
enableRls,
|
|
type: values.type,
|
|
configuration:
|
|
values.type === 'partitioned'
|
|
? {
|
|
partitionInterval: values.partitionInterval,
|
|
retentionInterval: values.retentionInterval,
|
|
}
|
|
: undefined,
|
|
},
|
|
{
|
|
onSuccess: () => {
|
|
toast.success(`Successfully created queue ${name}`)
|
|
navigateToUrl(navigate, `/project/${project?.ref}/integrations/queues/queues/${name}`)
|
|
onClose()
|
|
},
|
|
}
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Sheet open={visible} onOpenChange={handleOpenChange}>
|
|
<SheetContent size="default" className="w-[35%]">
|
|
<div className="flex flex-col h-full" tabIndex={-1}>
|
|
<SheetHeader>
|
|
<SheetTitle>Create a new queue</SheetTitle>
|
|
</SheetHeader>
|
|
|
|
<div className="overflow-auto grow">
|
|
<Form {...form}>
|
|
<form
|
|
id={FORM_ID}
|
|
className="grow overflow-auto"
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
>
|
|
<QueueNameField form={form} />
|
|
<Separator />
|
|
<PgPartmanCallout />
|
|
<QueueTypeSelector form={form} />
|
|
<Separator />
|
|
<PartitionConfigFields form={form} />
|
|
<RlsSection form={form} isExposed={isExposed} projectRef={project?.ref} />
|
|
</form>
|
|
</Form>
|
|
</div>
|
|
<SheetFooter>
|
|
<Button size="tiny" type="button" onClick={confirmOnClose} disabled={isPending}>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
size="tiny"
|
|
variant="primary"
|
|
form={FORM_ID}
|
|
type="submit"
|
|
loading={isPending}
|
|
disabled={!project?.ref}
|
|
>
|
|
Create queue
|
|
</Button>
|
|
</SheetFooter>
|
|
</div>
|
|
<DiscardChangesConfirmationDialog {...modalProps} />
|
|
</SheetContent>
|
|
</Sheet>
|
|
)
|
|
}
|