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>
225 lines
7.9 KiB
TypeScript
225 lines
7.9 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { RefreshCwIcon, SearchIcon, XIcon } from 'lucide-react'
|
|
import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'
|
|
import { useMemo, useRef, useState } from 'react'
|
|
import DataGrid, { Row } from 'react-data-grid'
|
|
import { Button, cn, LoadingLine, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
import { PageSection } from 'ui-patterns/PageSection'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { ConstrainedIntegrationTabScaffold } from '../ConstrainedIntegrationTabScaffold'
|
|
import { useIntegrationDetail } from '../Landing/useIntegrationDetail'
|
|
import { CreateQueueSheet } from './CreateQueueSheet'
|
|
import { formatQueueColumns, prepareQueuesForDataGrid } from './Queues.utils'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { useQueuesQuery } from '@/data/database-queues/database-queues-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { onSearchInputEscape } from '@/lib/keyboard'
|
|
import { navigateToUrl } from '@/lib/navigation'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
|
|
export const QueuesTab = () => {
|
|
const navigate = useNavigate()
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { isInstalled } = useIntegrationDetail()
|
|
|
|
const [searchQuery, setSearchQuery] = useQueryState('search', parseAsString.withDefault(''))
|
|
const [search, setSearch] = useState(searchQuery)
|
|
|
|
const [createQueueSheetShown, setCreateQueueSheetShown] = useQueryState(
|
|
'new',
|
|
parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true })
|
|
)
|
|
|
|
const searchInputRef = useRef<HTMLInputElement>(null)
|
|
|
|
const clearSearch = () => {
|
|
setSearch('')
|
|
setSearchQuery('')
|
|
}
|
|
|
|
useShortcut(
|
|
SHORTCUT_IDS.LIST_PAGE_FOCUS_SEARCH,
|
|
() => {
|
|
searchInputRef.current?.focus()
|
|
searchInputRef.current?.select()
|
|
},
|
|
{ label: 'Search queues' }
|
|
)
|
|
useShortcut(SHORTCUT_IDS.LIST_PAGE_RESET_FILTERS, clearSearch)
|
|
useShortcut(SHORTCUT_IDS.LIST_PAGE_NEW_ITEM, () => setCreateQueueSheetShown(true), {
|
|
label: 'Create queue',
|
|
})
|
|
|
|
const {
|
|
data: queues,
|
|
error,
|
|
isPending: isLoading,
|
|
isError,
|
|
isRefetching,
|
|
refetch,
|
|
} = useQueuesQuery(
|
|
{
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
},
|
|
{ enabled: isInstalled }
|
|
)
|
|
|
|
// Filter queues based on search query
|
|
const filteredQueues = useMemo(() => {
|
|
if (!queues) return []
|
|
if (!searchQuery) return queues
|
|
return queues.filter((queue) =>
|
|
queue.queue_name.toLowerCase().includes(searchQuery.toLowerCase())
|
|
)
|
|
}, [queues, searchQuery])
|
|
|
|
// Prepare queues for DataGrid
|
|
const queueData = useMemo(() => prepareQueuesForDataGrid(filteredQueues), [filteredQueues])
|
|
|
|
// Get columns configuration
|
|
const columns = useMemo(() => formatQueueColumns(), [])
|
|
|
|
if (!isInstalled) {
|
|
return (
|
|
<div className="mx-auto w-full max-w-6xl px-6 xl:px-10">
|
|
<ConstrainedIntegrationTabScaffold>
|
|
<PageSection className="py-0">
|
|
<Admonition type="default" description="Queues is not installed." />
|
|
</PageSection>
|
|
</ConstrainedIntegrationTabScaffold>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="h-full w-full space-y-4">
|
|
<div className="h-full w-full flex flex-col relative">
|
|
<div className="bg-surface-200 py-3 px-10 flex items-center justify-between flex-wrap">
|
|
<Input
|
|
ref={searchInputRef}
|
|
size="tiny"
|
|
className="w-52"
|
|
placeholder="Search for a queue"
|
|
icon={<SearchIcon />}
|
|
value={search ?? ''}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
onSearchInputEscape(search ?? '', clearSearch)(e)
|
|
if (e.code === 'Enter' || e.code === 'NumpadEnter') setSearchQuery(search.trim())
|
|
}}
|
|
actions={[
|
|
search && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
key="clear"
|
|
size="tiny"
|
|
variant="text"
|
|
icon={<XIcon />}
|
|
onClick={clearSearch}
|
|
className="p-0 h-5 w-5"
|
|
aria-label="Clear search"
|
|
// Tooltip repeats the label; screen readers would read it twice
|
|
aria-describedby={undefined}
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">Clear search</TooltipContent>
|
|
</Tooltip>
|
|
),
|
|
]}
|
|
/>
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
<Button icon={<RefreshCwIcon />} loading={isRefetching} onClick={() => refetch()}>
|
|
Refresh
|
|
</Button>
|
|
<Button variant="primary" onClick={() => setCreateQueueSheetShown(true)}>
|
|
Create queue
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<LoadingLine loading={isLoading || isRefetching} />
|
|
|
|
<DataGrid
|
|
className="grow border-t-0! border-b-0!"
|
|
rowHeight={44}
|
|
headerRowHeight={36}
|
|
columns={columns}
|
|
rows={queueData}
|
|
rowKeyGetter={(row) => row.id}
|
|
rowClass={() => {
|
|
return cn(
|
|
'cursor-pointer',
|
|
'[&>.rdg-cell]:border-box [&>.rdg-cell]:outline-hidden [&>.rdg-cell]:shadow-none',
|
|
'[&>.rdg-cell:first-child>div]:ml-8'
|
|
)
|
|
}}
|
|
renderers={{
|
|
renderRow(_, props) {
|
|
return (
|
|
<Row
|
|
key={props.row.queue_name}
|
|
{...props}
|
|
onClick={() => {
|
|
const { queue_name } = props.row
|
|
const url = `/project/${ref}/integrations/queues/queues/${queue_name}`
|
|
navigateToUrl(navigate, url)
|
|
}}
|
|
/>
|
|
)
|
|
},
|
|
}}
|
|
/>
|
|
|
|
{/* Render 0 rows state outside of the grid */}
|
|
{queueData.length === 0 ? (
|
|
isLoading ? (
|
|
<div className="absolute top-28 px-10 w-full">
|
|
<GenericSkeletonLoader />
|
|
</div>
|
|
) : isError ? (
|
|
<div className="absolute top-28 px-10 flex flex-col items-center justify-center w-full">
|
|
<AlertError subject="Failed to retrieve database queues" error={error} />
|
|
</div>
|
|
) : (
|
|
<div className="absolute top-32 px-6 w-full">
|
|
<div className="text-center text-sm flex flex-col gap-y-1">
|
|
<p className="text-foreground">
|
|
{!!searchQuery ? 'No queues found' : 'No queues created yet'}
|
|
</p>
|
|
<p className="text-foreground-light">
|
|
{!!searchQuery
|
|
? 'There are currently no queues based on the search applied'
|
|
: 'There are currently no queues created yet in your project'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
) : null}
|
|
|
|
<div className="flex justify-between min-h-9 h-9 overflow-hidden items-center px-6 w-full border-t text-xs text-foreground-light">
|
|
{`Total: ${queueData.length} queues`}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<CreateQueueSheet
|
|
visible={createQueueSheetShown}
|
|
onClose={() => {
|
|
setCreateQueueSheetShown(false)
|
|
}}
|
|
/>
|
|
</>
|
|
)
|
|
}
|