import { PermissionAction } from '@supabase/shared-types/out/constants' import { Check, ChevronsUpDown, Plus } from 'lucide-react' import { useState } from 'react' import { useSchemasQuery } from 'data/database/schemas-query' import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, CommandSeparator_Shadcn_, Command_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, ScrollArea, Skeleton, } from 'ui' interface SchemaSelectorProps { className?: string disabled?: boolean size?: 'tiny' | 'small' showError?: boolean selectedSchemaName: string supportSelectAll?: boolean excludedSchemas?: string[] onSelectSchema: (name: string) => void onSelectCreateSchema?: () => void portal?: boolean align?: 'start' | 'end' } const SchemaSelector = ({ className, disabled = false, size = 'tiny', showError = true, selectedSchemaName, supportSelectAll = false, excludedSchemas = [], onSelectSchema, onSelectCreateSchema, portal = true, align = 'start', }: SchemaSelectorProps) => { const [open, setOpen] = useState(false) const { can: canCreateSchemas } = useAsyncCheckPermissions( PermissionAction.TENANT_SQL_ADMIN_WRITE, 'schemas' ) const { data: project } = useSelectedProjectQuery() const { data, isPending: isSchemasLoading, isSuccess: isSchemasSuccess, isError: isSchemasError, error: schemasError, refetch: refetchSchemas, } = useSchemasQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const schemas = (data || []) .filter((schema) => !excludedSchemas.includes(schema.name)) .sort((a, b) => a.name.localeCompare(b.name)) return (