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 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {
  2. memo,
  3. useCallback,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import type { NodeProps } from 'reactflow'
  7. import { RiAddLine } from '@remixicon/react'
  8. import cn from '@/utils/classnames'
  9. import Button from '@/app/components/base/button'
  10. import BlockSelector from '@/app/components/workflow/block-selector'
  11. import { useReplaceDataSourceNode } from './hooks'
  12. const DataSourceEmptyNode = ({ id }: NodeProps) => {
  13. const { t } = useTranslation()
  14. const { handleReplaceNode } = useReplaceDataSourceNode(id)
  15. const renderTrigger = useCallback(() => {
  16. return (
  17. <Button
  18. variant='primary'
  19. className='w-full'
  20. >
  21. <RiAddLine className='mr-1 h-4 w-4' />
  22. {t('workflow.nodes.dataSource.add')}
  23. </Button>
  24. )
  25. }, [])
  26. return (
  27. <div
  28. className={cn(
  29. 'relative flex rounded-2xl border',
  30. 'border-transparent',
  31. )}
  32. >
  33. <div className='absolute inset-[-2px] top-[-22px] z-[-1] rounded-[18px] bg-node-data-source-bg p-0.5 backdrop-blur-[6px]'>
  34. <div className='system-2xs-semibold-uppercase flex h-5 items-center px-2.5 text-text-tertiary'>
  35. {t('workflow.blocks.datasource')}
  36. </div>
  37. </div>
  38. <div
  39. className={cn(
  40. 'group relative shadow-xs',
  41. 'rounded-[15px] border border-transparent',
  42. 'w-[240px] bg-workflow-block-bg',
  43. )}
  44. >
  45. <div className={cn(
  46. 'flex items-center rounded-t-2xl p-3',
  47. )}>
  48. <BlockSelector
  49. asChild
  50. onSelect={handleReplaceNode}
  51. trigger={renderTrigger}
  52. noBlocks
  53. noTools
  54. popupClassName='w-[320px]'
  55. placement='bottom-start'
  56. offset={{
  57. mainAxis: 4,
  58. crossAxis: 0,
  59. }}
  60. />
  61. </div>
  62. </div>
  63. </div>
  64. )
  65. }
  66. export default memo(DataSourceEmptyNode)