mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.
Addresses FE-3107.
**Removed:**
- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector
**Changed:**
- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`
**Added:**
- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps
## To test
- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
324 lines
9.7 KiB
TypeScript
324 lines
9.7 KiB
TypeScript
import { useDebounce } from '@uidotdev/usehooks'
|
|
import { useParams } from 'common'
|
|
import { AnalyticsBucket as AnalyticsBucketIcon, FilesBucket, Storage, VectorBucket } from 'icons'
|
|
import { Loader2Icon } from 'lucide-react'
|
|
import { useCallback, useMemo } from 'react'
|
|
|
|
import {
|
|
EmptyState,
|
|
ResultsList,
|
|
SkeletonResults,
|
|
type SearchResult,
|
|
} from './ContextSearchResults.shared'
|
|
import {
|
|
useIsAnalyticsBucketsEnabled,
|
|
useIsVectorBucketsEnabled,
|
|
} from '@/data/config/project-storage-config-query'
|
|
import {
|
|
useAnalyticsBucketsQuery,
|
|
type AnalyticsBucket,
|
|
} from '@/data/storage/analytics-buckets-query'
|
|
import {
|
|
useBucketNumberEstimateQuery,
|
|
usePaginatedBucketsQuery,
|
|
type Bucket,
|
|
} from '@/data/storage/buckets-query'
|
|
import { useVectorBucketsQuery } from '@/data/storage/vector-buckets-query'
|
|
|
|
interface StorageSearchResultsProps {
|
|
query: string
|
|
}
|
|
|
|
type ExtendedSearchResult = SearchResult & {
|
|
bucketType?: 'file' | 'analytics' | 'vector'
|
|
bucket?: unknown
|
|
}
|
|
|
|
function filterBuckets<T>(
|
|
buckets: T[] | null | undefined,
|
|
query: string,
|
|
filterFn: (bucket: T, searchLower: string) => boolean,
|
|
mapFn: (bucket: T) => ExtendedSearchResult
|
|
): ExtendedSearchResult[] {
|
|
if (!buckets) return []
|
|
|
|
const trimmedQuery = query.trim()
|
|
const filtered = trimmedQuery
|
|
? buckets.filter((bucket) => filterFn(bucket, trimmedQuery.toLowerCase()))
|
|
: buckets
|
|
|
|
return filtered.slice(0, 10).map(mapFn)
|
|
}
|
|
|
|
export function StorageSearchResults({ query }: StorageSearchResultsProps) {
|
|
const { ref: projectRef } = useParams()
|
|
|
|
const isAnalyticsBucketsEnabled = useIsAnalyticsBucketsEnabled({ projectRef })
|
|
const isVectorBucketsEnabled = useIsVectorBucketsEnabled({ projectRef })
|
|
|
|
// Debounce the search query to avoid excessive API calls
|
|
const debouncedQuery = useDebounce(query.trim(), 300)
|
|
|
|
const {
|
|
data: fileBucketsData,
|
|
isLoading: isLoadingFileBuckets,
|
|
isError: isErrorFileBuckets,
|
|
} = usePaginatedBucketsQuery(
|
|
{
|
|
projectRef: projectRef ?? undefined,
|
|
limit: 10,
|
|
search: debouncedQuery.length > 0 ? debouncedQuery : undefined,
|
|
},
|
|
{
|
|
enabled: !!projectRef,
|
|
}
|
|
)
|
|
const fileBuckets = useMemo(
|
|
() => fileBucketsData?.pages.flatMap((page) => page) ?? [],
|
|
[fileBucketsData]
|
|
)
|
|
|
|
const {
|
|
data: analyticsBuckets,
|
|
isLoading: isLoadingAnalyticsBuckets,
|
|
isError: isErrorAnalyticsBuckets,
|
|
} = useAnalyticsBucketsQuery(
|
|
{
|
|
projectRef: projectRef ?? undefined,
|
|
},
|
|
{
|
|
enabled: !!projectRef && isAnalyticsBucketsEnabled,
|
|
}
|
|
)
|
|
|
|
const {
|
|
data: vectorBucketsData,
|
|
isLoading: isLoadingVectorBuckets,
|
|
isError: isErrorVectorBuckets,
|
|
} = useVectorBucketsQuery(
|
|
{
|
|
projectRef: projectRef ?? undefined,
|
|
},
|
|
{
|
|
enabled: !!projectRef && isVectorBucketsEnabled,
|
|
}
|
|
)
|
|
|
|
const vectorBuckets = useMemo(() => vectorBucketsData?.vectorBuckets ?? [], [vectorBucketsData])
|
|
|
|
const { data: fileBucketsEstimate } = useBucketNumberEstimateQuery({
|
|
projectRef,
|
|
})
|
|
|
|
const isLoading =
|
|
isLoadingFileBuckets ||
|
|
(isAnalyticsBucketsEnabled && isLoadingAnalyticsBuckets) ||
|
|
(isVectorBucketsEnabled && isLoadingVectorBuckets)
|
|
const isError =
|
|
isErrorFileBuckets ||
|
|
(isAnalyticsBucketsEnabled && isErrorAnalyticsBuckets) ||
|
|
(isVectorBucketsEnabled && isErrorVectorBuckets)
|
|
|
|
const fileBucketResults: ExtendedSearchResult[] = useMemo(() => {
|
|
// Server-side search is already applied, no need for client-side filtering
|
|
if (!fileBuckets) return []
|
|
|
|
return fileBuckets.map((bucket) => {
|
|
const displayName = bucket.name || bucket.id || 'Untitled Bucket'
|
|
const visibility = bucket.public ? 'Public' : 'Private'
|
|
const description = `File bucket • ${visibility}`
|
|
|
|
return {
|
|
id: `file-bucket-${bucket.id || bucket.name}`,
|
|
name: displayName,
|
|
description,
|
|
bucketType: 'file' as const,
|
|
bucket,
|
|
}
|
|
})
|
|
}, [fileBuckets])
|
|
|
|
const analyticsBucketResults: ExtendedSearchResult[] = useMemo(() => {
|
|
return filterBuckets(
|
|
analyticsBuckets,
|
|
debouncedQuery, // Use debounced query for consistency
|
|
(bucket, searchLower) => {
|
|
const bucketName = bucket.name?.toLowerCase() || ''
|
|
return bucketName.includes(searchLower)
|
|
},
|
|
(bucket) => {
|
|
const displayName = bucket.name || 'Untitled Bucket'
|
|
const description = 'Analytics bucket'
|
|
|
|
return {
|
|
id: `analytics-bucket-${bucket.name}`,
|
|
name: displayName,
|
|
description,
|
|
bucketType: 'analytics' as const,
|
|
bucket,
|
|
}
|
|
}
|
|
)
|
|
}, [analyticsBuckets, debouncedQuery])
|
|
|
|
const vectorBucketResults: ExtendedSearchResult[] = useMemo(() => {
|
|
return filterBuckets(
|
|
vectorBuckets,
|
|
debouncedQuery, // Use debounced query for consistency
|
|
(bucket, searchLower) => {
|
|
const bucketName = bucket.vectorBucketName?.toLowerCase() || ''
|
|
return bucketName.includes(searchLower)
|
|
},
|
|
(bucket) => {
|
|
const displayName = bucket.vectorBucketName || 'Untitled Bucket'
|
|
const description = 'Vector bucket'
|
|
|
|
return {
|
|
id: `vector-bucket-${bucket.vectorBucketName}`,
|
|
name: displayName,
|
|
description,
|
|
bucketType: 'vector' as const,
|
|
bucket,
|
|
}
|
|
}
|
|
)
|
|
}, [vectorBuckets, debouncedQuery])
|
|
|
|
const allResults: ExtendedSearchResult[] = useMemo(() => {
|
|
const results = [fileBucketResults]
|
|
if (isAnalyticsBucketsEnabled) {
|
|
results.push(analyticsBucketResults)
|
|
}
|
|
if (isVectorBucketsEnabled) {
|
|
results.push(vectorBucketResults)
|
|
}
|
|
return results.flat().slice(0, 20)
|
|
}, [
|
|
fileBucketResults,
|
|
analyticsBucketResults,
|
|
vectorBucketResults,
|
|
isAnalyticsBucketsEnabled,
|
|
isVectorBucketsEnabled,
|
|
])
|
|
|
|
const getRoute = useCallback(
|
|
(result: SearchResult) => {
|
|
if (!projectRef) return '/storage/files' as `/${string}`
|
|
|
|
const extendedResult = result as ExtendedSearchResult
|
|
|
|
if (extendedResult.bucketType && extendedResult.bucket) {
|
|
const bucketType = extendedResult.bucketType
|
|
|
|
if (bucketType === 'file') {
|
|
const fileBucket = extendedResult.bucket as Bucket
|
|
return `/project/${projectRef}/storage/files/buckets/${encodeURIComponent(fileBucket.name)}` as `/${string}`
|
|
}
|
|
|
|
if (bucketType === 'analytics') {
|
|
const analyticsBucket = extendedResult.bucket as AnalyticsBucket
|
|
return `/project/${projectRef}/storage/analytics/buckets/${encodeURIComponent(analyticsBucket.name)}` as `/${string}`
|
|
}
|
|
|
|
if (bucketType === 'vector') {
|
|
const vectorBucket = extendedResult.bucket as { vectorBucketName: string }
|
|
return `/project/${projectRef}/storage/vectors/buckets/${encodeURIComponent(vectorBucket.vectorBucketName)}` as `/${string}`
|
|
}
|
|
}
|
|
|
|
return `/project/${projectRef}/storage/files` as `/${string}`
|
|
},
|
|
[projectRef]
|
|
)
|
|
|
|
const totalBucketsEstimate = useMemo(() => {
|
|
const fileBucketCount = fileBucketsEstimate ?? 0
|
|
const analyticsBucketCount = isAnalyticsBucketsEnabled ? (analyticsBuckets?.length ?? 0) : 0
|
|
const vectorBucketCount = isVectorBucketsEnabled ? (vectorBuckets?.length ?? 0) : 0
|
|
|
|
return fileBucketCount + analyticsBucketCount + vectorBucketCount
|
|
}, [
|
|
fileBucketsEstimate,
|
|
analyticsBuckets?.length,
|
|
vectorBuckets?.length,
|
|
isAnalyticsBucketsEnabled,
|
|
isVectorBucketsEnabled,
|
|
])
|
|
|
|
const getIcon = useCallback((result: SearchResult) => {
|
|
const extendedResult = result as ExtendedSearchResult
|
|
if (extendedResult.bucketType === 'file') return FilesBucket
|
|
if (extendedResult.bucketType === 'analytics') return AnalyticsBucketIcon
|
|
if (extendedResult.bucketType === 'vector') return VectorBucket
|
|
return Storage
|
|
}, [])
|
|
|
|
const renderFooter = () => (
|
|
<div className="absolute bottom-0 left-0 right-0 flex items-center justify-between min-h-9 h-9 px-4 border-t bg-surface-200 text-xs text-foreground-light z-10">
|
|
<div className="flex items-center gap-x-2">
|
|
{isLoading ? (
|
|
<span className="flex items-center gap-2">
|
|
<Loader2Icon size={14} className="animate-spin" /> Loading...
|
|
</span>
|
|
) : (
|
|
<span>
|
|
Total: {totalBucketsEstimate.toLocaleString()} bucket
|
|
{totalBucketsEstimate !== 1 ? <span>s</span> : ''} <span>(estimate)</span>
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="relative h-full flex flex-col">
|
|
<div className="flex-1 min-h-0 overflow-hidden">
|
|
<SkeletonResults />
|
|
</div>
|
|
{renderFooter()}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (isError) {
|
|
return (
|
|
<div className="relative h-full flex flex-col">
|
|
<div className="flex-1 min-h-0 overflow-hidden">
|
|
<div className="h-full flex flex-col items-center justify-center py-12 px-4 gap-4 text-center text-foreground-lighter">
|
|
<Storage className="h-6 w-6" strokeWidth={1.5} />
|
|
<p className="text-sm">Failed to load storage buckets</p>
|
|
</div>
|
|
</div>
|
|
{renderFooter()}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (allResults.length === 0) {
|
|
return (
|
|
<div className="relative h-full flex flex-col">
|
|
<div className="flex-1 min-h-0 overflow-hidden">
|
|
<EmptyState icon={Storage} label="Storage" query={debouncedQuery} />
|
|
</div>
|
|
{renderFooter()}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="relative h-full flex flex-col">
|
|
<div className="flex-1 min-h-0 overflow-hidden">
|
|
<ResultsList
|
|
results={allResults}
|
|
icon={Storage}
|
|
getIcon={getIcon}
|
|
getRoute={getRoute}
|
|
className="pb-9"
|
|
/>
|
|
</div>
|
|
{renderFooter()}
|
|
</div>
|
|
)
|
|
}
|