import { type FC } from 'react' import clsx from 'clsx'; import { Select, type SelectProps } from 'antd' import type { Suggestion } from '../Editor/plugin/AutocompletePlugin' type LabelRender = SelectProps['labelRender']; interface VariableSelectProps extends SelectProps { options: Suggestion[]; value?: string; onChange?: (value: string) => void; allowClear?: boolean; filterBooleanType?: boolean; } const VariableSelect: FC = ({ placeholder, options, value, allowClear = true, onChange, size, filterBooleanType = false, ...resetPorps }) => { const handleChange = (value: string) => { onChange?.(value); } const labelRender: LabelRender = (props) => { const { value } = props const filterOption = filteredOptions.find(vo => `{{${vo.value}}}` === value) if (filterOption) { return ( {filterOption.nodeData?.icon && filterOption.nodeData?.name && ( <> {filterOption.nodeData.name} / )} {filterOption.label} ) } return null } const filteredOptions = filterBooleanType ? options.filter(option => option.dataType !== 'boolean') : options; const groupedSuggestions = filteredOptions.reduce((groups: Record, suggestion) => { const { nodeData } = suggestion const nodeId = nodeData.id as string; if (!groups[nodeId]) { groups[nodeId] = []; } groups[nodeId].push(suggestion); return groups; }, {}); const groupedOptions = Object.entries(groupedSuggestions).map(([_nodeId, suggestions]) => ({ label: suggestions[0].nodeData.name, options: suggestions.map(s => ({ label: s.label, value: `{{${s.value}}}` })) })); return (