node.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useEffect,
  5. } from 'react'
  6. import {
  7. Background,
  8. useNodesInitialized,
  9. useViewport,
  10. } from 'reactflow'
  11. import { IterationStartNodeDumb } from '../iteration-start'
  12. import { useNodeIterationInteractions } from './use-interactions'
  13. import type { IterationNodeType } from './types'
  14. import AddBlock from './add-block'
  15. import cn from '@/utils/classnames'
  16. import type { NodeProps } from '@/app/components/workflow/types'
  17. const Node: FC<NodeProps<IterationNodeType>> = ({
  18. id,
  19. data,
  20. }) => {
  21. const { zoom } = useViewport()
  22. const nodesInitialized = useNodesInitialized()
  23. const { handleNodeIterationRerender } = useNodeIterationInteractions()
  24. useEffect(() => {
  25. if (nodesInitialized)
  26. handleNodeIterationRerender(id)
  27. }, [nodesInitialized, id, handleNodeIterationRerender])
  28. return (
  29. <div className={cn(
  30. 'relative min-w-[240px] min-h-[90px] w-full h-full rounded-2xl bg-[#F0F2F7]/90',
  31. )}>
  32. <Background
  33. id={`iteration-background-${id}`}
  34. className='rounded-2xl !z-0'
  35. gap={[14 / zoom, 14 / zoom]}
  36. size={2 / zoom}
  37. color='#E4E5E7'
  38. />
  39. {
  40. data._isCandidate && (
  41. <IterationStartNodeDumb />
  42. )
  43. }
  44. {
  45. data._children!.length === 1 && (
  46. <AddBlock
  47. iterationNodeId={id}
  48. iterationNodeData={data}
  49. />
  50. )
  51. }
  52. </div>
  53. )
  54. }
  55. export default memo(Node)