mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Moves the remaining `next/navigation` imports in Studio onto TanStack
Router hooks (and `useParams` from `common`), finishes migrating the
remaining `next/link` and `next/router` usages in the touched
components, and removes the `compat/next/navigation.ts` shim and its
Vite alias. Shared packages (`packages/**`) no longer import
`next/navigation`, so the alias can be dropped now.
**Removed:**
- `apps/studio/compat/next/navigation.ts` and the `'next/navigation'`
entry in `apps/studio/vite.config.ts`
- Global `next/navigation` mock in `apps/studio/tests/vitestSetup.ts`
and the obsolete `apps/studio/tests/lib/route-mock.test.tsx`
**Changed:**
- Replaced `usePathname` (12 files) and `useSearchParams` (3 files) with
`useLocation({ select })` from `@tanstack/react-router`
- Replaced `useRouter` in Storage bucket tables, SQL Editor commands,
and `SignInMfaForm` with `useNavigate` from `@tanstack/react-router`,
and updated `createNavigationHandler` in `lib/navigation.ts` to accept
either `NextRouter` or TanStack's `useNavigate`
- Replaced remaining `next/link` imports in touched components
(`SignInMfaForm`, `Restriction`, `DownloadLogsButton`,
`DownloadResultsButton`, `AuthEmailsLayout`, `AuthProvidersLayout`,
`JWTKeysLayout`, `StorageBucketsLayout`) with TanStack Router's `Link`
- Replaced `useParams` in `CreatePublishableAPIKeyDialog` with
`useParams` from `common` (matching `CreateSecretAPIKeyDialog`)
- Wrapped `CustomWrapper` (`tests/lib/custom-render.tsx`) in a default
TanStack `RouterContextProvider` (with optional `router` / `initialUrl`
overrides) and updated affected component tests to drop their
`next/navigation` mocks
Addresses
[FE-5110](https://linear.app/supabase/issue/FE-5110/replace-the-nextnavigation-shim-with-tanstack-router-hooks)
## To test
1. Check active tab highlighting and navigation across Auth Emails, Auth
Providers, JWT Keys, Storage Buckets, and Editor layouts
2. Verify clicking, Cmd/Ctrl-clicking, middle-clicking, and pressing
Enter on Storage bucket rows (Files, Analytics, Vector) navigates as
before
3. Run "Query a table..." and open SQL snippets from the Command Menu
and confirm `/project/$ref/sql/$id` opens with multi-line SQL preserved
in `?content=`
4. In the MFA sign-in flow, verify the recovery code link and
`forgot-password` completion preserve query params (`returnTo`,
`context=forgot-password`), and Cancel signs out and replaces history
with `/sign-in`
5. Confirm Table Editor sort/filter URL sync persists filters per table
without leaking across table switches
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
200 lines
6.7 KiB
TypeScript
200 lines
6.7 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { FilesBucket as FilesBucketIcon } from 'icons'
|
|
import { ChevronRightIcon } from 'lucide-react'
|
|
import {
|
|
Badge,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
|
|
import { useIsStorageVersioningEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { BucketVersioningPill } from '@/components/interfaces/Storage/BucketVersioningPill'
|
|
import { PUBLIC_BUCKET_TOOLTIP } from '@/components/interfaces/Storage/Storage.constants'
|
|
import { getBucketVersioningState } from '@/components/interfaces/Storage/StorageVersioning.constants'
|
|
import { useBucketPolicyCount } from '@/components/interfaces/Storage/useBucketPolicyCount'
|
|
import { TableRowNoResults } from '@/components/ui/TableRowNoResults'
|
|
import {
|
|
VirtualizedTableCell,
|
|
VirtualizedTableHead,
|
|
VirtualizedTableHeader,
|
|
VirtualizedTableRow,
|
|
} from '@/components/ui/VirtualizedTable'
|
|
import { Bucket } from '@/data/storage/buckets-query'
|
|
import { formatBytes } from '@/lib/helpers'
|
|
import { createNavigationHandler } from '@/lib/navigation'
|
|
|
|
type BucketTableMode = 'standard' | 'virtualized'
|
|
|
|
export const useVersioningColumnSpan = () => (useIsStorageVersioningEnabled() ? 1 : 0)
|
|
|
|
const BucketVersioningCell = ({ bucket }: { bucket: Bucket }) => {
|
|
if (getBucketVersioningState(bucket) === 'disabled')
|
|
return <span className="text-foreground-muted">-</span>
|
|
return <BucketVersioningPill bucket={bucket} showPrefix={false} />
|
|
}
|
|
|
|
type BucketTableHeaderProps = {
|
|
mode: BucketTableMode
|
|
hasBuckets?: boolean
|
|
}
|
|
|
|
export const BucketTableHeader = ({ mode, hasBuckets = true }: BucketTableHeaderProps) => {
|
|
const isStorageVersioningEnabled = useIsStorageVersioningEnabled()
|
|
const BucketTableHeader = mode === 'standard' ? TableHeader : VirtualizedTableHeader
|
|
const BucketTableRow = mode === 'standard' ? TableRow : VirtualizedTableRow
|
|
const BucketTableHead = mode === 'standard' ? TableHead : VirtualizedTableHead
|
|
|
|
const stickyClasses = 'sticky top-0 z-10 bg-200'
|
|
|
|
return (
|
|
<BucketTableHeader>
|
|
<BucketTableRow>
|
|
{hasBuckets && (
|
|
<BucketTableHead className={`${stickyClasses} w-2 pr-1`}>
|
|
<span className="sr-only">Icon</span>
|
|
</BucketTableHead>
|
|
)}
|
|
<BucketTableHead className={stickyClasses}>Name</BucketTableHead>
|
|
<BucketTableHead className={stickyClasses}>Policies</BucketTableHead>
|
|
<BucketTableHead className={stickyClasses}>File size limit</BucketTableHead>
|
|
<BucketTableHead className={stickyClasses}>Allowed MIME types</BucketTableHead>
|
|
{isStorageVersioningEnabled && (
|
|
<BucketTableHead className={stickyClasses}>Versioning</BucketTableHead>
|
|
)}
|
|
<BucketTableHead className={stickyClasses}>
|
|
<span className="sr-only">Actions</span>
|
|
</BucketTableHead>
|
|
</BucketTableRow>
|
|
</BucketTableHeader>
|
|
)
|
|
}
|
|
|
|
type BucketTableEmptyStateProps = {
|
|
mode: BucketTableMode
|
|
filterString: string
|
|
}
|
|
|
|
export const BucketTableEmptyState = ({ mode, filterString }: BucketTableEmptyStateProps) => {
|
|
const versioningColumnSpan = useVersioningColumnSpan()
|
|
|
|
if (mode === 'standard') {
|
|
return (
|
|
<TableRowNoResults
|
|
className="[&>td]:hover:bg-inherit"
|
|
colSpan={5 + versioningColumnSpan}
|
|
search={filterString}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<VirtualizedTableRow className="[&>td]:hover:bg-inherit">
|
|
<VirtualizedTableCell colSpan={5 + versioningColumnSpan}>
|
|
<p className="text-sm text-foreground">No results found</p>
|
|
<p className="text-sm text-foreground-lighter">
|
|
Your search for “{filterString}” did not return any results
|
|
</p>
|
|
</VirtualizedTableCell>
|
|
</VirtualizedTableRow>
|
|
)
|
|
}
|
|
|
|
type BucketTableRowProps = {
|
|
mode: BucketTableMode
|
|
bucket: Bucket
|
|
projectRef: string
|
|
formattedGlobalUploadLimit: string
|
|
}
|
|
|
|
export const BucketTableRow = ({
|
|
mode,
|
|
bucket,
|
|
projectRef,
|
|
formattedGlobalUploadLimit,
|
|
}: BucketTableRowProps) => {
|
|
const navigate = useNavigate()
|
|
const { getPolicyCount } = useBucketPolicyCount()
|
|
const isStorageVersioningEnabled = useIsStorageVersioningEnabled()
|
|
|
|
const BucketTableRow = mode === 'standard' ? TableRow : VirtualizedTableRow
|
|
const BucketTableCell = mode === 'standard' ? TableCell : VirtualizedTableCell
|
|
|
|
const handleBucketNavigation = createNavigationHandler(
|
|
`/project/${projectRef}/storage/files/buckets/${encodeURIComponent(bucket.id)}`,
|
|
navigate
|
|
)
|
|
|
|
return (
|
|
<BucketTableRow
|
|
key={bucket.id}
|
|
data-bucket-id={bucket.id}
|
|
className="relative cursor-pointer h-16 group focus-inset"
|
|
onClick={handleBucketNavigation}
|
|
onAuxClick={handleBucketNavigation}
|
|
onKeyDown={handleBucketNavigation}
|
|
tabIndex={0}
|
|
>
|
|
<BucketTableCell className="w-2 pr-1">
|
|
<FilesBucketIcon aria-label="bucket icon" size={16} className="text-foreground-muted" />
|
|
</BucketTableCell>
|
|
<BucketTableCell className="flex-1">
|
|
<div className="flex items-center gap-2.5">
|
|
<p className="whitespace-nowrap max-w-[512px] truncate">{bucket.id}</p>
|
|
{bucket.public && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Badge variant="warning" className="flex">
|
|
Public
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">{PUBLIC_BUCKET_TOOLTIP}</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p className="text-foreground-light">{getPolicyCount(bucket.id)}</p>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p
|
|
className={`whitespace-nowrap ${bucket.file_size_limit ? 'text-foreground-light' : 'text-foreground-muted'}`}
|
|
>
|
|
{bucket.file_size_limit
|
|
? formatBytes(bucket.file_size_limit)
|
|
: `Unset (${formattedGlobalUploadLimit})`}
|
|
</p>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p
|
|
className={bucket.allowed_mime_types ? 'text-foreground-light' : 'text-foreground-muted'}
|
|
>
|
|
{bucket.allowed_mime_types ? bucket.allowed_mime_types.join(', ') : 'Any'}
|
|
</p>
|
|
</BucketTableCell>
|
|
|
|
{isStorageVersioningEnabled && (
|
|
<BucketTableCell>
|
|
<BucketVersioningCell bucket={bucket} />
|
|
</BucketTableCell>
|
|
)}
|
|
|
|
<BucketTableCell>
|
|
<div className="flex justify-end items-center h-full">
|
|
<ChevronRightIcon aria-hidden={true} size={14} className="text-foreground-muted/60" />
|
|
</div>
|
|
<button tabIndex={-1} className="sr-only">
|
|
Go to bucket details
|
|
</button>
|
|
</BucketTableCell>
|
|
</BucketTableRow>
|
|
)
|
|
}
|