import { Check, ChevronsUpDown } from 'lucide-react' import { useMemo, useState } from 'react' import { Button, cn, Command_Shadcn_, CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, Popover_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, ScrollArea, } from 'ui' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { useSchemasQuery } from '@/data/database/schemas-query' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { INTERNAL_SCHEMAS } from '@/hooks/useProtectedSchemas' import { pluralize } from '@/lib/helpers' interface ExposedSchemaSelectorProps { disabled?: boolean selectedSchemas: string[] onToggleSchema: (schema: string) => void } export const ExposedSchemaSelector = ({ disabled = false, selectedSchemas, onToggleSchema, }: ExposedSchemaSelectorProps) => { const [open, setOpen] = useState(false) const { data: project } = useSelectedProjectQuery() const { data: allSchemas, isPending, isError, isSuccess, } = useSchemasQuery({ projectRef: project?.ref, connectionString: project?.connectionString, }) const schemas = useMemo( () => (allSchemas ?? []) .filter((s) => { if (s.name === 'graphql_public') return true return !INTERNAL_SCHEMAS.includes(s.name) }) .sort((a, b) => a.name.localeCompare(b.name)), [allSchemas] ) const selectedSet = useMemo(() => new Set(selectedSchemas), [selectedSchemas]) const selectedCount = schemas.filter((s) => selectedSet.has(s.name)).length return ( {isPending ? ( <>
) : isError ? (

Failed to retrieve schemas

) : ( <>

No schemas found

7 ? 'h-[210px]' : ''}> {schemas.map((schema) => { const isExposed = selectedSet.has(schema.name) return ( { onToggleSchema(schema.name) }} >
{isExposed && } {schema.name}
) })}
)}
) }