import { useCallback, useEffect } from 'react' import { useDatasourceOptions } from '../hooks' import OptionCard from './option-card' import type { Datasource } from '@/app/components/rag-pipeline/components/panel/test-run/types' import type { Node } from '@/app/components/workflow/types' import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' type DataSourceOptionsProps = { pipelineNodes: Node[] datasourceNodeId: string onSelect: (option: Datasource) => void } const DataSourceOptions = ({ pipelineNodes, datasourceNodeId, onSelect, }: DataSourceOptionsProps) => { const options = useDatasourceOptions(pipelineNodes) const handelSelect = useCallback((value: string) => { const selectedOption = options.find(option => option.value === value) if (!selectedOption) return const datasource = { nodeId: selectedOption.value, nodeData: selectedOption.data, } onSelect(datasource) }, [onSelect, options]) useEffect(() => { if (options.length > 0 && !datasourceNodeId) handelSelect(options[0].value) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return (
{options.map(option => ( ))}
) } export default DataSourceOptions