mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 02:42:59 +00:00 
			
		
		
		
	 dabfd74622
			
		
	
	
		dabfd74622
		
			
		
	
	
	
	
		
			
			Co-authored-by: StyleZhang <jasonapring2015@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: -LAN- <laipz8200@outlook.com>
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { FC } from 'react'
 | |
| import {
 | |
|   memo,
 | |
|   useEffect,
 | |
| } from 'react'
 | |
| import {
 | |
|   Background,
 | |
|   useNodesInitialized,
 | |
|   useViewport,
 | |
| } from 'reactflow'
 | |
| import { IterationStartNodeDumb } from '../iteration-start'
 | |
| import { useNodeIterationInteractions } from './use-interactions'
 | |
| import type { IterationNodeType } from './types'
 | |
| import AddBlock from './add-block'
 | |
| import cn from '@/utils/classnames'
 | |
| import type { NodeProps } from '@/app/components/workflow/types'
 | |
| 
 | |
| const Node: FC<NodeProps<IterationNodeType>> = ({
 | |
|   id,
 | |
|   data,
 | |
| }) => {
 | |
|   const { zoom } = useViewport()
 | |
|   const nodesInitialized = useNodesInitialized()
 | |
|   const { handleNodeIterationRerender } = useNodeIterationInteractions()
 | |
| 
 | |
|   useEffect(() => {
 | |
|     if (nodesInitialized)
 | |
|       handleNodeIterationRerender(id)
 | |
|   }, [nodesInitialized, id, handleNodeIterationRerender])
 | |
| 
 | |
|   return (
 | |
|     <div className={cn(
 | |
|       'relative min-w-[240px] min-h-[90px] w-full h-full rounded-2xl bg-[#F0F2F7]/90',
 | |
|     )}>
 | |
|       <Background
 | |
|         id={`iteration-background-${id}`}
 | |
|         className='rounded-2xl !z-0'
 | |
|         gap={[14 / zoom, 14 / zoom]}
 | |
|         size={2 / zoom}
 | |
|         color='#E4E5E7'
 | |
|       />
 | |
|       {
 | |
|         data._isCandidate && (
 | |
|           <IterationStartNodeDumb />
 | |
|         )
 | |
|       }
 | |
|       {
 | |
|         data._children!.length === 1 && (
 | |
|           <AddBlock
 | |
|             iterationNodeId={id}
 | |
|             iterationNodeData={data}
 | |
|           />
 | |
|         )
 | |
|       }
 | |
|     </div>
 | |
|   )
 | |
| }
 | |
| 
 | |
| export default memo(Node)
 |