import React from 'react'; import Trash from '../assets/trash.svg'; import Arrow2 from '../assets/dropdown-arrow.svg'; import { Doc } from '../preferences/preferenceApi'; import { useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; type Props = { options: Doc[] | null; selectedDocs: Doc | null; setSelectedDocs: any; isDocsListOpen: boolean; setIsDocsListOpen: React.Dispatch>; handleDeleteClick: any; }; function SourceDropdown({ options, setSelectedDocs, selectedDocs, setIsDocsListOpen, isDocsListOpen, handleDeleteClick, }: Props) { const dispatch = useDispatch(); const { t } = useTranslation(); const dropdownRef = React.useRef(null); const embeddingsName = import.meta.env.VITE_EMBEDDINGS_NAME || 'huggingface_sentence-transformers/all-mpnet-base-v2'; const handleEmptyDocumentSelect = () => { dispatch(setSelectedDocs(null)); setIsDocsListOpen(false); }; const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setIsDocsListOpen(false); } }; React.useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, []); return (
{isDocsListOpen && (
{options ? ( options.map((option: any, index: number) => { if (option.model === embeddingsName) { return (
{ dispatch(setSelectedDocs(option)); setIsDocsListOpen(false); }} > { setIsDocsListOpen(false); }} className="ml-4 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap py-3" > {option.name} {option.location === 'local' && ( Delete { event.stopPropagation(); handleDeleteClick(option); }} /> )}
); } }) ) : ( <> )}
{t('none')}
)}
); } export default SourceDropdown;