Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.tsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { useCallback, useEffect } from 'react'
  2. import { useDatasourceOptions } from '../hooks'
  3. import OptionCard from './option-card'
  4. import type { Datasource } from '@/app/components/rag-pipeline/components/panel/test-run/types'
  5. import type { Node } from '@/app/components/workflow/types'
  6. import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
  7. type DataSourceOptionsProps = {
  8. pipelineNodes: Node<DataSourceNodeType>[]
  9. datasourceNodeId: string
  10. onSelect: (option: Datasource) => void
  11. }
  12. const DataSourceOptions = ({
  13. pipelineNodes,
  14. datasourceNodeId,
  15. onSelect,
  16. }: DataSourceOptionsProps) => {
  17. const { datasources, options } = useDatasourceOptions(pipelineNodes)
  18. const handelSelect = useCallback((value: string) => {
  19. const selectedOption = datasources.find(option => option.nodeId === value)
  20. if (!selectedOption)
  21. return
  22. onSelect(selectedOption)
  23. }, [datasources, onSelect])
  24. useEffect(() => {
  25. if (options.length > 0 && !datasourceNodeId)
  26. handelSelect(options[0].value)
  27. // eslint-disable-next-line react-hooks/exhaustive-deps
  28. }, [])
  29. return (
  30. <div className='grid w-full grid-cols-4 gap-1'>
  31. {options.map(option => (
  32. <OptionCard
  33. key={option.value}
  34. label={option.label}
  35. selected={datasourceNodeId === option.value}
  36. nodeData={option.data}
  37. onClick={handelSelect.bind(null, option.value)}
  38. />
  39. ))}
  40. </div>
  41. )
  42. }
  43. export default DataSourceOptions