import { Checkbox } from '@langgenius/dify-ui/checkbox' import { CheckboxGroup } from '@langgenius/dify-ui/checkbox-group' import { cn } from '@langgenius/dify-ui/cn' import { Popover, PopoverContent, PopoverTrigger } from '@langgenius/dify-ui/popover' import { useDebounceFn } from 'ahooks' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { Tag03 } from '@/app/components/base/icons/src/vender/line/financeAndECommerce' import Input from '@/app/components/base/input' import { useTags } from '@/app/components/plugins/hooks' type LabelSelectorProps = { value: string[] onChange: (v: string[]) => void } function LabelSelector({ value, onChange }: LabelSelectorProps) { const { t } = useTranslation() const [open, setOpen] = useState(false) const { tags: labelList } = useTags() const [keywords, setKeywords] = useState('') const [searchKeywords, setSearchKeywords] = useState('') const { run: handleSearch } = useDebounceFn( () => { setSearchKeywords(keywords) }, { wait: 500 }, ) const handleKeywordsChange = (value: string) => { setKeywords(value) handleSearch() } const filteredLabelList = labelList.filter((label) => label.name.includes(searchKeywords)) const selectedLabels = value.map((v) => labelList.find((l) => l.name === v)?.label).join(', ') return (
{!value.length && t(($) => $['createTool.toolInput.labelPlaceholder'], { ns: 'tools' })} {!!value.length && selectedLabels}
handleKeywordsChange(e.target.value)} onClear={() => handleKeywordsChange('')} />
$['createTool.toolInput.labelPlaceholder'], { ns: 'tools' })} value={value} onValueChange={(nextValue) => onChange(nextValue)} className="max-h-[264px] overflow-y-auto p-1" > {filteredLabelList.map((label) => ( ))} {!filteredLabelList.length && (
{t(($) => $['tag.noTag'], { ns: 'common' })}
)}
) } export default LabelSelector