import { Check, ChevronsUpDown, Loader2, Plus } from 'lucide-react' import { useEffect, useState } from 'react' import { ControllerRenderProps } from 'react-hook-form' import { Badge, Button, cn, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, Popover, PopoverContent, PopoverTrigger, ScrollArea, } from 'ui' import type { ReplicationPublication } from '@/data/replication/publications-query' interface PublicationsComboBoxProps { publications: ReplicationPublication[] isLoadingPublications: boolean onNewPublicationClick: () => void field: ControllerRenderProps } export const PublicationsComboBox = ({ publications, isLoadingPublications, onNewPublicationClick, field, }: PublicationsComboBoxProps) => { const [dropdownOpen, setDropdownOpen] = useState(false) const [selectedPublication, setSelectedPublication] = useState(field?.value || '') const [searchTerm, setSearchTerm] = useState('') function handlePublicationSelect(pub: string) { setSelectedPublication(pub) setDropdownOpen(false) field.onChange(pub) } useEffect(() => { setSelectedPublication(field?.value || '') }, [field?.value]) return ( { setDropdownOpen(open) if (!open && field?.onBlur) { field.onBlur() } }} >

Publications with no tables are hidden

{isLoadingPublications ? (
Loading...
) : ( 'No publications found' )}
{publications.length === 0 && (

No publications available

)} 7 ? 'h-[210px]' : ''}> {publications.map((pub) => ( { handlePublicationSelect(pub.name) }} onClick={() => { handlePublicationSelect(pub.name) }} > {pub.name}
{pub.tables.length} {pub.tables.length === 1 ? 'table' : 'tables'} {selectedPublication === pub.name && ( )}
))}

New publication

) }