mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 15:19:08 +03:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
135 lines
4.2 KiB
TypeScript
135 lines
4.2 KiB
TypeScript
import { useIntersectionObserver } from '@uidotdev/usehooks'
|
|
import { useParams } from 'common'
|
|
import { DatabaseIcon, Loader2Icon } from 'lucide-react'
|
|
import { useEffect, useMemo } from 'react'
|
|
|
|
import {
|
|
EmptyState,
|
|
ResultsList,
|
|
SkeletonResults,
|
|
type SearchResult,
|
|
} from './ContextSearchResults.shared'
|
|
import { useInfiniteTablesQuery } from '@/data/tables/tables-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
interface TableSearchResultsProps {
|
|
debouncedFilterString: string
|
|
}
|
|
|
|
export function TableSearchResults({ debouncedFilterString }: TableSearchResultsProps) {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const [sentinelRef, sentinelEntry] = useIntersectionObserver({
|
|
threshold: 0,
|
|
rootMargin: '200px 0px 200px 0px',
|
|
})
|
|
|
|
const {
|
|
data: tablesData,
|
|
isSuccess,
|
|
isError: isErrorTables,
|
|
isPending: isLoadingTables,
|
|
hasNextPage: hasNextTablesPage,
|
|
isFetchingNextPage: isFetchingNextTablesPage,
|
|
fetchNextPage: fetchNextTablesPage,
|
|
} = useInfiniteTablesQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
includeColumns: false,
|
|
pageSize: 50,
|
|
nameFilter: debouncedFilterString,
|
|
})
|
|
|
|
const tables = useMemo(() => tablesData?.pages.flat() ?? [], [tablesData])
|
|
|
|
const tableResults: SearchResult[] = useMemo(() => {
|
|
if (!tables) return []
|
|
|
|
return tables.map((table) => {
|
|
const displayName =
|
|
table.schema && table.schema !== 'public'
|
|
? `${table.schema}.${table.name}`
|
|
: table.name || 'Untitled Table'
|
|
|
|
const description = table.comment
|
|
? table.comment.length > 50
|
|
? `${table.comment.slice(0, 50)}...`
|
|
: table.comment
|
|
: undefined
|
|
|
|
return {
|
|
id: String(table.id),
|
|
name: displayName,
|
|
description,
|
|
}
|
|
})
|
|
}, [tables])
|
|
|
|
const totalTables = tables?.length ?? 0
|
|
|
|
useEffect(() => {
|
|
if (
|
|
sentinelEntry?.isIntersecting &&
|
|
hasNextTablesPage &&
|
|
!isFetchingNextTablesPage &&
|
|
isSuccess
|
|
) {
|
|
fetchNextTablesPage()
|
|
}
|
|
}, [
|
|
isSuccess,
|
|
sentinelEntry?.isIntersecting,
|
|
hasNextTablesPage,
|
|
isFetchingNextTablesPage,
|
|
fetchNextTablesPage,
|
|
])
|
|
|
|
return (
|
|
<div className="relative h-full flex flex-col">
|
|
<div className="flex-1 min-h-0 overflow-hidden">
|
|
{isLoadingTables ? (
|
|
<SkeletonResults />
|
|
) : isErrorTables ? (
|
|
<div className="h-full flex flex-col items-center justify-center py-12 px-4 gap-4 text-center text-foreground-lighter">
|
|
<DatabaseIcon className="h-6 w-6" strokeWidth={1.5} />
|
|
<p className="text-sm">Failed to load tables</p>
|
|
</div>
|
|
) : tableResults.length === 0 ? (
|
|
<EmptyState icon={DatabaseIcon} label="Database Tables" query={debouncedFilterString} />
|
|
) : (
|
|
<>
|
|
<ResultsList
|
|
results={tableResults}
|
|
icon={DatabaseIcon}
|
|
getRoute={(result) => {
|
|
const table = tables?.find((t) => String(t.id) === result.id)
|
|
if (!table || !projectRef) return `/project/${projectRef}/editor` as `/${string}`
|
|
|
|
const schemaParam = table.schema ? `?schema=${table.schema}` : ''
|
|
return `/project/${projectRef}/editor/${table.id}${schemaParam}` as `/${string}`
|
|
}}
|
|
infiniteLoadingObserverRef={sentinelRef}
|
|
className="pb-9"
|
|
/>
|
|
<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">
|
|
{isLoadingTables ? (
|
|
<span className="flex items-center gap-2">
|
|
<Loader2Icon size={14} className="animate-spin" /> Loading...
|
|
</span>
|
|
) : (
|
|
<span>
|
|
Total: {totalTables.toLocaleString()} table{totalTables !== 1 ? 's' : ''}
|
|
{hasNextTablesPage ? ' loaded' : ''}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|