You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { useCallback, useEffect } from 'react'
  2. import { useDatasourceOptions } from '../hooks'
  3. import OptionCard from './option-card'
  4. import { File, Watercrawl } from '@/app/components/base/icons/src/public/knowledge'
  5. import { Notion } from '@/app/components/base/icons/src/public/common'
  6. import { Jina } from '@/app/components/base/icons/src/public/llm'
  7. import { DataSourceType } from '@/models/datasets'
  8. import { DataSourceProvider } from '@/models/common'
  9. import type { Datasource } from '@/app/components/rag-pipeline/components/panel/test-run/types'
  10. import type { Node } from '@/app/components/workflow/types'
  11. import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
  12. type DataSourceOptionsProps = {
  13. pipelineNodes: Node<DataSourceNodeType>[]
  14. datasourceNodeId: string
  15. onSelect: (option: Datasource) => void
  16. }
  17. const DATA_SOURCE_ICONS = {
  18. [DataSourceType.FILE]: File as React.FC<React.SVGProps<SVGSVGElement>>,
  19. [DataSourceType.NOTION]: Notion as React.FC<React.SVGProps<SVGSVGElement>>,
  20. [DataSourceProvider.fireCrawl]: '🔥',
  21. [DataSourceProvider.jinaReader]: Jina as React.FC<React.SVGProps<SVGSVGElement>>,
  22. [DataSourceProvider.waterCrawl]: Watercrawl as React.FC<React.SVGProps<SVGSVGElement>>,
  23. }
  24. const DataSourceOptions = ({
  25. pipelineNodes,
  26. datasourceNodeId,
  27. onSelect,
  28. }: DataSourceOptionsProps) => {
  29. const { datasources, options } = useDatasourceOptions(pipelineNodes)
  30. const handelSelect = useCallback((value: string) => {
  31. const selectedOption = datasources.find(option => option.nodeId === value)
  32. if (!selectedOption)
  33. return
  34. onSelect(selectedOption)
  35. }, [datasources, onSelect])
  36. useEffect(() => {
  37. if (options.length > 0)
  38. handelSelect(options[0].value)
  39. // eslint-disable-next-line react-hooks/exhaustive-deps
  40. }, [])
  41. return (
  42. <div className='grid w-full grid-cols-4 gap-1'>
  43. {options.map(option => (
  44. <OptionCard
  45. key={option.value}
  46. label={option.label}
  47. selected={datasourceNodeId === option.value}
  48. Icon={DATA_SOURCE_ICONS[option.type as keyof typeof DATA_SOURCE_ICONS]}
  49. onClick={handelSelect.bind(null, option.value)}
  50. />
  51. ))}
  52. </div>
  53. )
  54. }
  55. export default DataSourceOptions