Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): command search entities (#41554)

Francesco Sansalvadore5bef19528b4f
diff --git a/apps/studio/components/interfaces/App/CommandMenu/CommandMenu.tsx b/apps/studio/components/interfaces/App/CommandMenu/CommandMenu.tsx
index fbbbd80df0f..a24b3e33bb4 100644
--- a/apps/studio/components/interfaces/App/CommandMenu/CommandMenu.tsx
+++ b/apps/studio/components/interfaces/App/CommandMenu/CommandMenu.tsx
@@ -17,6 +17,7 @@ import { useApiUrlCommand } from './ApiUrl'
import { useProjectSwitchCommand, useConfigureOrganizationCommand } from './OrgProjectSwitcher'
import { useSupportCommands } from './Support'
import { orderCommandSectionsByPriority } from './ordering'
+import { useContextSearchCommands } from './ContextSearchCommands'
import { useCreateCommands } from './CreateCommands'
export default function StudioCommandMenu() {
@@ -40,6 +41,7 @@ export default function StudioCommandMenu() {
useChangelogCommand({ enabled: IS_PLATFORM })
useThemeSwitcherCommands()
useCreateCommands()
+ useContextSearchCommands()
return (
<CommandMenu>
diff --git a/apps/studio/components/interfaces/App/CommandMenu/ContextSearchCommands.tsx b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchCommands.tsx
new file mode 100644
index 00000000000..9cd507530de
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchCommands.tsx
@@ -0,0 +1,152 @@
+'use client'
+
+import { useMemo } from 'react'
+import { Database } from 'lucide-react'
+import { Auth, EdgeFunctions, Storage } from 'icons'
+import type { ICommand } from 'ui-patterns/CommandMenu'
+import {
+ CommandHeader,
+ CommandInput,
+ CommandWrapper,
+ PageType,
+ useRegisterCommands,
+ useRegisterPage,
+ useSetPage,
+ useQuery,
+} from 'ui-patterns/CommandMenu'
+import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { orderCommandSectionsByPriority } from './ordering'
+import { ContextSearchResults } from './ContextSearchResults'
+import { useFlag, IS_PLATFORM } from 'common'
+import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
+import type { SearchContextValue } from './SearchContext.types'
+
+interface SearchContextOption {
+ value: SearchContextValue
+ label: string
+ pageName: string
+ placeholder: string
+ icon: React.ComponentType<React.SVGProps<SVGSVGElement>>
+}
+
+const SEARCH_CONTEXT_OPTIONS: SearchContextOption[] = [
+ {
+ value: 'database-tables',
+ label: 'Database Tables',
+ pageName: 'Search Database Tables',
+ placeholder: 'Search database tables...',
+ icon: Database,
+ },
+ {
+ value: 'auth-policies',
+ label: 'RLS Policies',
+ pageName: 'Search RLS Policies',
+ placeholder: 'Search rls policies...',
+ icon: Auth,
+ },
+ {
+ value: 'edge-functions',
+ label: 'Edge Functions',
+ pageName: 'Search Edge Functions',
+ placeholder: 'Search edge functions...',
+ icon: EdgeFunctions,
+ },
+ {
+ value: 'storage',
+ label: 'Storage',
+ pageName: 'Search Storage',
+ placeholder: 'Search buckets...',
+ icon: Storage,
+ },
+]
+
+function ContextSearchPage({
+ context,
+ placeholder,
+}: {
+ context: SearchContextValue
+ placeholder: string
+}) {
+ const query = useQuery()
+
+ return (
+ <CommandWrapper>
+ <CommandHeader>
+ <CommandInput placeholder={placeholder} />
+ </CommandHeader>
+ <ContextSearchResults context={context} query={query} />
+ </CommandWrapper>
+ )
+}
+
+export function useContextSearchCommands() {
+ const enableSearchEntitiesCommandMenu = useFlag('enableSearchEntitiesCommandMenu')
+ const { data: project } = useSelectedProjectQuery()
+ const setPage = useSetPage()
+
+ const {
+ projectAuthAll: authEnabled,
+ projectEdgeFunctionAll: edgeFunctionsEnabled,
+ projectStorageAll: storageEnabled,
+ } = useIsFeatureEnabled(['project_auth:all', 'project_edge_function:all', 'project_storage:all'])
+
+ const pageDefinitions = [
+ { title: 'Search Database Tables', context: 'database-tables' as const },
+ { title: 'Search RLS Policies', context: 'auth-policies' as const },
+ { title: 'Search Edge Functions', context: 'edge-functions' as const },
+ { title: 'Search Storage', context: 'storage' as const },
+ ]
+
+ // Register pages - pageDefinitions is constant, so hooks are called in consistent order
+ for (const { title, context } of pageDefinitions) {
+ const placeholder =
+ SEARCH_CONTEXT_OPTIONS.find((opt) => opt.value === context)?.placeholder ?? ''
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ useRegisterPage(title, {
+ type: PageType.Component,
+ component: () => <ContextSearchPage context={context} placeholder={placeholder} />,
+ })
+ }
+
+ const contextCommands = useMemo(() => {
+ return SEARCH_CONTEXT_OPTIONS.filter((option) => {
+ let isFeatureEnabled = false
+ switch (option.value) {
+ case 'database-tables':
+ isFeatureEnabled = true
+ break
+ case 'auth-policies':
+ isFeatureEnabled = authEnabled
+ break
+ case 'edge-functions':
+ isFeatureEnabled = edgeFunctionsEnabled
+ break
+ case 'storage':
+ isFeatureEnabled = storageEnabled
+ break
+ }
+
+ if (!isFeatureEnabled) return false
+
+ // If self-hosted, show if feature is enabled
+ if (!IS_PLATFORM) {
+ return true
+ }
+
+ // only show when inside a project if not self-hosted
+ return !!project
+ }).map((option) => ({
+ id: `search-${option.value}`,
+ name: `Search ${option.label}...`,
+ action: () => setPage(option.pageName),
+ icon: () => <option.icon className="h-4 w-4" strokeWidth={1.5} />,
+ })) as ICommand[]
+ }, [setPage, authEnabled, edgeFunctionsEnabled, storageEnabled, project])
+
+ useRegisterCommands(COMMAND_MENU_SECTIONS.QUERY, contextCommands, {
+ orderSection: orderCommandSectionsByPriority,
+ sectionMeta: { priority: 3 },
+ enabled: !IS_PLATFORM || (enableSearchEntitiesCommandMenu && !!project),
+ })
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.shared.tsx b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.shared.tsx
new file mode 100644
index 00000000000..8a511334f94
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.shared.tsx
@@ -0,0 +1,111 @@
+'use client'
+
+import { CommandList_Shadcn_, cn } from 'ui'
+import { ShimmeringLoader } from 'ui-patterns'
+import { CommandItem } from 'ui-patterns/CommandMenu/internal/Command'
+import { CommandGroup } from 'ui-patterns/CommandMenu/internal/CommandGroup'
+import { TextHighlighter } from 'ui-patterns/CommandMenu'
+import type { IRouteCommand, IActionCommand } from 'ui-patterns/CommandMenu/internal/types'
+
+export interface SearchResult {
+ id: string
+ name: string
+ description?: string
+}
+
+export function SkeletonResults() {
+ return (
+ <div className="p-2 space-y-1">
+ {[0, 1, 2, 3].map((i) => (
+ <div key={i} className="flex items-center gap-3 px-2 py-2">
+ <ShimmeringLoader className="!w-4 !h-4 !py-0 rounded" delayIndex={i} />
+ <div className="flex-1 space-y-1">
+ <ShimmeringLoader className="!w-32 !py-1.5" delayIndex={i} />
+ <ShimmeringLoader className="!w-48 !py-1" delayIndex={i + 1} />
+ </div>
+ </div>
+ ))}
+ </div>
+ )
+}
+
+interface EmptyStateProps {
+ icon: React.ComponentType<React.SVGProps<SVGSVGElement>>
+ label: string
+ query: string
+}
+
+export function EmptyState({ icon: Icon, label, query }: EmptyStateProps) {
+ return (
+ <div className="h-full flex flex-col items-center justify-center py-12 px-4 gap-4 text-center text-foreground-lighter">
+ <Icon className="h-6 w-6" strokeWidth={1.5} />
+ <p className="text-sm">
+ {query ? `No results found for "${query}"` : `Type to search in ${label}`}
+ </p>
+ </div>
+ )
+}
+
+interface ResultsListProps {
+ results: SearchResult[]
+ icon: React.ComponentType<React.SVGProps<SVGSVGElement>>
+ getIcon?: (result: SearchResult) => React.ComponentType<React.SVGProps<SVGSVGElement>>
+ onResultClick?: (result: SearchResult) => void
+ getRoute?: (result: SearchResult) => `/${string}` | `http${string}`
+ className?: string
+}
+
+export function ResultsList({
+ results,
+ icon: Icon,
+ getIcon,
+ onResultClick,
+ getRoute,
+ className,
+}: ResultsListProps) {
+ const commands = results.map((result): IRouteCommand | IActionCommand => {
+ const ResultIcon = getIcon ? getIcon(result) : Icon
+ const baseCommand = {
+ id: result.id,
+ name: result.name,
+ value: result.description ? `${result.name} ${result.description}` : result.name,
+ icon: () => <ResultIcon className="h-4 w-4" strokeWidth={1.5} />,
+ }
+
+ if (getRoute) {
+ return {
+ ...baseCommand,
+ route: getRoute(result),
+ } as IRouteCommand
+ }
+
+ return {
+ ...baseCommand,
+ action: () => onResultClick?.(result),
+ } as IActionCommand
+ })
+
+ return (
+ <CommandList_Shadcn_
+ className={cn(
+ '!max-h-full flex-1 min-h-0 overflow-y-auto overflow-x-hidden bg-transparent',
+ className
+ )}
+ >
+ <CommandGroup>
+ {commands.map((command) => (
+ <CommandItem key={command.id} command={command}>
+ <div className="flex flex-col min-w-0 text-foreground-light">
+ <TextHighlighter>{command.name}</TextHighlighter>
+ {command.value && command.value !== command.name && (
+ <p className="text-xs text-foreground-lighter/70 truncate mt-0.5">
+ {command.value.replace(command.name, '').trim()}
+ </p>
+ )}
+ </div>
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </CommandList_Shadcn_>
+ )
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.tsx b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.tsx
new file mode 100644
index 00000000000..30a19b6894f
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/ContextSearchResults.tsx
@@ -0,0 +1,119 @@
+'use client'
+
+import dynamic from 'next/dynamic'
+import { Database } from 'lucide-react'
+import { Auth, EdgeFunctions, Storage } from 'icons'
+import type { SearchContextValue } from './SearchContext.types'
+import { SkeletonResults, EmptyState } from './ContextSearchResults.shared'
+
+const TableSearchResults = dynamic(
+ () => import('./TableSearchResults').then((mod) => ({ default: mod.TableSearchResults })),
+ {
+ loading: () => <SkeletonResults />,
+ ssr: false,
+ }
+)
+
+const PolicySearchResults = dynamic(
+ () => import('./PolicySearchResults').then((mod) => ({ default: mod.PolicySearchResults })),
+ {
+ loading: () => <SkeletonResults />,
+ ssr: false,
+ }
+)
+
+const EdgeFunctionSearchResults = dynamic(
+ () =>
+ import('./EdgeFunctionSearchResults').then((mod) => ({
+ default: mod.EdgeFunctionSearchResults,
+ })),
+ {
+ loading: () => <SkeletonResults />,
+ ssr: false,
+ }
+)
+
+const StorageSearchResults = dynamic(
+ () => import('./StorageSearchResults').then((mod) => ({ default: mod.StorageSearchResults })),
+ {
+ loading: () => <SkeletonResults />,
+ ssr: false,
+ }
+)
+
+interface ContextSearchResultsProps {
+ context: SearchContextValue
+ query: string
+}
+
+const CONTEXT_CONFIG: Record<
+ SearchContextValue,
+ {
+ icon: React.ComponentType<React.SVGProps<SVGSVGElement>>
+ label: string
+ requiresInput?: boolean // requires user input before showing results
+ }
+> = {
+ 'database-tables': {
+ icon: Database,
+ label: 'Database Tables',
+ requiresInput: false,
+ },
+ 'auth-policies': {
+ icon: Auth,
+ label: 'RLS Policies',
+ requiresInput: false,
+ },
+ 'edge-functions': {
+ icon: EdgeFunctions,
+ label: 'Edge Functions',
+ requiresInput: false,
+ },
+ storage: {
+ icon: Storage,
+ label: 'Storage',
+ requiresInput: false,
+ },
+}
+
+export function ContextSearchResults({ context, query }: ContextSearchResultsProps) {
+ const config = CONTEXT_CONFIG[context]
+
+ if (context === 'database-tables') {
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <TableSearchResults query={query} />
+ </div>
+ )
+ }
+
+ if (context === 'auth-policies') {
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <PolicySearchResults query={query} />
+ </div>
+ )
+ }
+
+ if (context === 'edge-functions') {
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <EdgeFunctionSearchResults query={query} />
+ </div>
+ )
+ }
+
+ if (context === 'storage') {
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <StorageSearchResults query={query} />
+ </div>
+ )
+ }
+
+ return (
+ <div className="flex-1 min-h-0 flex flex-col">
+ <EmptyState icon={config.icon} label={config.label} query={query} />
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/EdgeFunctionSearchResults.tsx b/apps/studio/components/interfaces/App/CommandMenu/EdgeFunctionSearchResults.tsx
new file mode 100644
index 00000000000..3a184435a7f
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/EdgeFunctionSearchResults.tsx
@@ -0,0 +1,135 @@
+'use client'
+
+import { useMemo } from 'react'
+import { EdgeFunctions } from 'icons'
+import { Loader2 } from 'lucide-react'
+import { useParams } from 'common'
+import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
+import {
+ SkeletonResults,
+ EmptyState,
+ ResultsList,
+ type SearchResult,
+} from './ContextSearchResults.shared'
+
+interface EdgeFunctionSearchResultsProps {
+ query: string
+}
+
+export function EdgeFunctionSearchResults({ query }: EdgeFunctionSearchResultsProps) {
+ const { ref: projectRef } = useParams()
+
+ const trimmedQuery = query.trim()
+
+ const {
+ data: functions,
+ isLoading: isLoadingFunctions,
+ isError: isErrorFunctions,
+ } = useEdgeFunctionsQuery(
+ {
+ projectRef,
+ },
+ {
+ enabled: !!projectRef,
+ }
+ )
+
+ const functionResults: SearchResult[] = useMemo(() => {
+ if (!functions) return []
+
+ const filtered = trimmedQuery
+ ? functions.filter((func) => {
+ const searchLower = trimmedQuery.toLowerCase()
+ const functionName = func.name?.toLowerCase() || ''
+ const functionSlug = func.slug?.toLowerCase() || ''
+
+ return functionName.includes(searchLower) || functionSlug.includes(searchLower)
+ })
+ : functions
+
+ // Limit results for performance
+ return filtered.slice(0, 20).map((func) => {
+ const displayName = func.name || func.slug || 'Untitled Function'
+ const description = func.version ? `Version ${func.version}` : undefined
+
+ return {
+ id: String(func.id),
+ name: displayName,
+ description,
+ }
+ })
+ }, [functions, trimmedQuery])
+
+ const totalFunctions = functions?.length ?? 0
+
+ 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">
+ {isLoadingFunctions ? (
+ <span className="flex items-center gap-2">
+ <Loader2 size={14} className="animate-spin" /> Loading...
+ </span>
+ ) : (
+ <span>
+ Total: {totalFunctions.toLocaleString()} function{totalFunctions !== 1 ? 's' : ''}
+ </span>
+ )}
+ </div>
+ </div>
+ )
+
+ if (isLoadingFunctions) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <SkeletonResults />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (isErrorFunctions) {
+ 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">
+ <EdgeFunctions className="h-6 w-6" strokeWidth={1.5} />
+ <p className="text-sm">Failed to load edge functions</p>
+ </div>
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (functionResults.length === 0) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <EmptyState icon={EdgeFunctions} label="Edge Functions" query={query} />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <ResultsList
+ results={functionResults}
+ icon={EdgeFunctions}
+ getRoute={(result) => {
+ const func = functions?.find((f) => String(f.id) === result.id)
+ if (!func || !projectRef) return `/project/${projectRef}/functions` as `/${string}`
+
+ return `/project/${projectRef}/functions/${func.slug}` as `/${string}`
+ }}
+ className="pb-9"
+ />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/PolicySearchResults.tsx b/apps/studio/components/interfaces/App/CommandMenu/PolicySearchResults.tsx
new file mode 100644
index 00000000000..46bfd9c54dc
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/PolicySearchResults.tsx
@@ -0,0 +1,158 @@
+'use client'
+
+import { useMemo } from 'react'
+import { Auth } from 'icons'
+import { Loader2 } from 'lucide-react'
+import { useParams } from 'common'
+import { useDatabasePoliciesQuery } from 'data/database-policies/database-policies-query'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import {
+ SkeletonResults,
+ EmptyState,
+ ResultsList,
+ type SearchResult,
+} from './ContextSearchResults.shared'
+
+interface PolicySearchResultsProps {
+ query: string
+}
+
+export function PolicySearchResults({ query }: PolicySearchResultsProps) {
+ const { ref: projectRef } = useParams()
+ const { data: project } = useSelectedProjectQuery()
+
+ const trimmedQuery = query.trim()
+
+ const {
+ data: policies,
+ isLoading: isLoadingPolicies,
+ isError: isErrorPolicies,
+ } = useDatabasePoliciesQuery(
+ {
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ },
+ {
+ enabled: !!project?.ref,
+ }
+ )
+
+ const policyResults: SearchResult[] = useMemo(() => {
+ if (!policies) return []
+
+ const filtered = trimmedQuery
+ ? policies.filter((policy) => {
+ const searchLower = trimmedQuery.toLowerCase()
+ const policyName = policy.name?.toLowerCase() || ''
+ const tableName = policy.table?.toLowerCase() || ''
+ const schemaName = policy.schema?.toLowerCase() || ''
+ const fullTableName = `${schemaName}.${tableName}`
+ const command = policy.command?.toLowerCase() || ''
+
+ return (
+ policyName.includes(searchLower) ||
+ tableName.includes(searchLower) ||
+ schemaName.includes(searchLower) ||
+ fullTableName.includes(searchLower) ||
+ command.includes(searchLower)
+ )
+ })
+ : policies
+
+ // Limit results for performance
+ return filtered.slice(0, 20).map((policy) => {
+ const displayName = policy.name || 'Untitled Policy'
+ const tableDisplay =
+ policy.schema && policy.schema !== 'public'
+ ? `${policy.schema}.${policy.table}`
+ : policy.table || 'unknown table'
+ const commandDisplay = policy.command || 'ALL'
+ const description = `${commandDisplay} on ${tableDisplay}`
+
+ return {
+ id: String(policy.id),
+ name: displayName,
+ description,
+ }
+ })
+ }, [policies, trimmedQuery])
+
+ const totalPolicies = policies?.length ?? 0
+
+ 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">
+ {isLoadingPolicies ? (
+ <span className="flex items-center gap-2">
+ <Loader2 size={14} className="animate-spin" /> Loading...
+ </span>
+ ) : (
+ <span>
+ Total: {totalPolicies.toLocaleString()} polic{totalPolicies !== 1 ? 'ies' : 'y'}
+ </span>
+ )}
+ </div>
+ </div>
+ )
+
+ if (isLoadingPolicies) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <SkeletonResults />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (isErrorPolicies) {
+ 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">
+ <Auth className="h-6 w-6" strokeWidth={1.5} />
+ <p className="text-sm">Failed to load policies</p>
+ </div>
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (policyResults.length === 0) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <EmptyState icon={Auth} label="RLS Policies" query={query} />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <ResultsList
+ results={policyResults}
+ icon={Auth}
+ getRoute={(result) => {
+ const policy = policies?.find((p) => String(p.id) === result.id)
+ if (!policy || !projectRef)
+ return `/project/${projectRef}/auth/policies` as `/${string}`
+
+ const params = new URLSearchParams()
+ params.set('edit', String(policy.id))
+ if (policy.schema) {
+ params.set('schema', policy.schema)
+ }
+ return `/project/${projectRef}/auth/policies?${params.toString()}` as `/${string}`
+ }}
+ className="pb-9"
+ />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/SearchContext.types.ts b/apps/studio/components/interfaces/App/CommandMenu/SearchContext.types.ts
new file mode 100644
index 00000000000..7521c396855
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/SearchContext.types.ts
@@ -0,0 +1 @@
+export type SearchContextValue = 'database-tables' | 'auth-policies' | 'edge-functions' | 'storage'
diff --git a/apps/studio/components/interfaces/App/CommandMenu/StorageSearchResults.tsx b/apps/studio/components/interfaces/App/CommandMenu/StorageSearchResults.tsx
new file mode 100644
index 00000000000..ad61654641f
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/StorageSearchResults.tsx
@@ -0,0 +1,314 @@
+'use client'
+
+import { useMemo, useCallback } from 'react'
+import { Storage, FilesBucket, AnalyticsBucket as AnalyticsBucketIcon, VectorBucket } from 'icons'
+import { Loader2 } from 'lucide-react'
+import { useParams } from 'common'
+import { useBucketsQuery, type Bucket } from 'data/storage/buckets-query'
+import {
+ useAnalyticsBucketsQuery,
+ type AnalyticsBucket,
+} from 'data/storage/analytics-buckets-query'
+import { useVectorBucketsQuery } from 'data/storage/vector-buckets-query'
+import {
+ useIsAnalyticsBucketsEnabled,
+ useIsVectorBucketsEnabled,
+} from 'data/config/project-storage-config-query'
+import {
+ SkeletonResults,
+ EmptyState,
+ ResultsList,
+ type SearchResult,
+} from './ContextSearchResults.shared'
+
+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 })
+
+ const {
+ data: fileBuckets,
+ isLoading: isLoadingFileBuckets,
+ isError: isErrorFileBuckets,
+ } = useBucketsQuery(
+ {
+ projectRef: projectRef ?? undefined,
+ },
+ {
+ enabled: !!projectRef,
+ }
+ )
+
+ 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 isLoading =
+ isLoadingFileBuckets ||
+ (isAnalyticsBucketsEnabled && isLoadingAnalyticsBuckets) ||
+ (isVectorBucketsEnabled && isLoadingVectorBuckets)
+ const isError =
+ isErrorFileBuckets ||
+ (isAnalyticsBucketsEnabled && isErrorAnalyticsBuckets) ||
+ (isVectorBucketsEnabled && isErrorVectorBuckets)
+
+ const fileBucketResults: ExtendedSearchResult[] = useMemo(() => {
+ return filterBuckets(
+ fileBuckets,
+ query,
+ (bucket, searchLower) => {
+ const bucketName = bucket.name?.toLowerCase() || ''
+ const bucketId = bucket.id?.toLowerCase() || ''
+ return bucketName.includes(searchLower) || bucketId.includes(searchLower)
+ },
+ (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, query])
+
+ const analyticsBucketResults: ExtendedSearchResult[] = useMemo(() => {
+ return filterBuckets(
+ analyticsBuckets,
+ query,
+ (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, query])
+
+ const vectorBucketResults: ExtendedSearchResult[] = useMemo(() => {
+ return filterBuckets(
+ vectorBuckets,
+ query,
+ (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, query])
+
+ 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 totalBuckets = useMemo(() => {
+ let total = fileBuckets?.length ?? 0
+ if (isAnalyticsBucketsEnabled) {
+ total += analyticsBuckets?.length ?? 0
+ }
+ if (isVectorBucketsEnabled) {
+ total += vectorBuckets?.length ?? 0
+ }
+ return total
+ }, [
+ fileBuckets?.length,
+ 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">
+ <Loader2 size={14} className="animate-spin" /> Loading...
+ </span>
+ ) : (
+ <span>
+ Total: {totalBuckets.toLocaleString()} bucket{totalBuckets !== 1 ? 's' : ''}
+ </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={query} />
+ </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>
+ )
+}
diff --git a/apps/studio/components/interfaces/App/CommandMenu/TableSearchResults.tsx b/apps/studio/components/interfaces/App/CommandMenu/TableSearchResults.tsx
new file mode 100644
index 00000000000..6f2ba0845f0
--- /dev/null
+++ b/apps/studio/components/interfaces/App/CommandMenu/TableSearchResults.tsx
@@ -0,0 +1,153 @@
+'use client'
+
+import { useMemo } from 'react'
+import { Database, Loader2 } from 'lucide-react'
+import { useParams } from 'common'
+import { useTablesQuery } from 'data/tables/tables-query'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import {
+ SkeletonResults,
+ EmptyState,
+ ResultsList,
+ type SearchResult,
+} from './ContextSearchResults.shared'
+
+interface TableSearchResultsProps {
+ query: string
+}
+
+export function TableSearchResults({ query }: TableSearchResultsProps) {
+ const { ref: projectRef } = useParams()
+ const { data: project } = useSelectedProjectQuery()
+
+ const trimmedQuery = query.trim()
+
+ const {
+ data: tables,
+ isLoading: isLoadingTables,
+ isError: isErrorTables,
+ } = useTablesQuery(
+ {
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ includeColumns: false,
+ sortByProperty: 'name',
+ },
+ {
+ enabled: !!project?.ref,
+ }
+ )
+
+ const tableResults: SearchResult[] = useMemo(() => {
+ if (!tables) return []
+
+ const filtered = trimmedQuery
+ ? tables.filter((table) => {
+ const searchLower = trimmedQuery.toLowerCase()
+ const tableName = table.name?.toLowerCase() || ''
+ const schemaName = table.schema?.toLowerCase() || ''
+ const fullName = `${schemaName}.${tableName}`
+
+ return (
+ tableName.includes(searchLower) ||
+ schemaName.includes(searchLower) ||
+ fullName.includes(searchLower)
+ )
+ })
+ : tables
+
+ // Limit results for performance
+ return filtered.slice(0, 20).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, trimmedQuery])
+
+ const totalTables = tables?.length ?? 0
+
+ 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">
+ {isLoadingTables ? (
+ <span className="flex items-center gap-2">
+ <Loader2 size={14} className="animate-spin" /> Loading...
+ </span>
+ ) : (
+ <span>
+ Total: {totalTables.toLocaleString()} table{totalTables !== 1 ? 's' : ''}
+ </span>
+ )}
+ </div>
+ </div>
+ )
+
+ if (isLoadingTables) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <SkeletonResults />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (isErrorTables) {
+ 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">
+ <Database className="h-6 w-6" strokeWidth={1.5} />
+ <p className="text-sm">Failed to load tables</p>
+ </div>
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ if (tableResults.length === 0) {
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <EmptyState icon={Database} label="Database Tables" query={query} />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+ }
+
+ return (
+ <div className="relative h-full flex flex-col">
+ <div className="flex-1 min-h-0 overflow-hidden">
+ <ResultsList
+ results={tableResults}
+ icon={Database}
+ 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}`
+ }}
+ className="pb-9"
+ />
+ </div>
+ {renderFooter()}
+ </div>
+ )
+}
diff --git a/packages/ui-patterns/src/CommandMenu/api/CommandInput.tsx b/packages/ui-patterns/src/CommandMenu/api/CommandInput.tsx
index 37b38e81450..eb1b20d12a2 100644
--- a/packages/ui-patterns/src/CommandMenu/api/CommandInput.tsx
+++ b/packages/ui-patterns/src/CommandMenu/api/CommandInput.tsx
@@ -113,24 +113,26 @@ const CommandInput = forwardRef<
}, [inputValue, imeComposing])
return (
- <CommandInput_Shadcn_
- // Focus needs to be manually handled to check breakpoint first, due to
- // delays from useEffect
- autoFocus={false}
- ref={inputRef}
- value={inputValue}
- onValueChange={handleValueChange}
- placeholder="Run a command or search..."
- onCompositionStart={() => setImeComposing(true)}
- onCompositionEnd={() => setImeComposing(false)}
- className={cn(
- 'flex h-11 w-full rounded-md bg-transparent px-2 py-7 outline-none',
- 'focus:shadow-none focus:ring-transparent',
- 'text-base text-foreground-light placeholder:text-foreground-muted disabled:cursor-not-allowed disabled:opacity-50 border-0',
- className
- )}
- {...props}
- />
+ <div className="relative w-full" cmdk-input-wrapper="">
+ <CommandInput_Shadcn_
+ // Focus needs to be manually handled to check breakpoint first, due to
+ // delays from useEffect
+ autoFocus={false}
+ ref={inputRef}
+ value={inputValue}
+ onValueChange={handleValueChange}
+ placeholder="Run a command or search..."
+ onCompositionStart={() => setImeComposing(true)}
+ onCompositionEnd={() => setImeComposing(false)}
+ className={cn(
+ 'flex h-11 w-full rounded-md bg-transparent px-2 py-7 outline-none',
+ 'focus:shadow-none focus:ring-transparent',
+ 'text-base text-foreground-light placeholder:text-foreground-muted disabled:cursor-not-allowed disabled:opacity-50 border-0',
+ className
+ )}
+ {...props}
+ />
+ </div>
)
})