| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   memo, | 
					
						
							|  |  |  |   useEffect, | 
					
						
							|  |  |  | } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   Background, | 
					
						
							|  |  |  |   useNodesInitialized, | 
					
						
							|  |  |  |   useViewport, | 
					
						
							|  |  |  | } from 'reactflow' | 
					
						
							| 
									
										
										
										
											2024-11-05 10:32:49 +08:00
										 |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  | import { IterationStartNodeDumb } from '../iteration-start' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import { useNodeIterationInteractions } from './use-interactions' | 
					
						
							|  |  |  | import type { IterationNodeType } from './types' | 
					
						
							|  |  |  | import AddBlock from './add-block' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import type { NodeProps } from '@/app/components/workflow/types' | 
					
						
							| 
									
										
										
										
											2024-11-05 10:32:49 +08:00
										 |  |  | import Toast from '@/app/components/base/toast' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18nPrefix = 'workflow.nodes.iteration' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const Node: FC<NodeProps<IterationNodeType>> = ({ | 
					
						
							|  |  |  |   id, | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { zoom } = useViewport() | 
					
						
							|  |  |  |   const nodesInitialized = useNodesInitialized() | 
					
						
							|  |  |  |   const { handleNodeIterationRerender } = useNodeIterationInteractions() | 
					
						
							| 
									
										
										
										
											2024-11-05 10:32:49 +08:00
										 |  |  |   const { t } = useTranslation() | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (nodesInitialized) | 
					
						
							|  |  |  |       handleNodeIterationRerender(id) | 
					
						
							| 
									
										
										
										
											2024-11-05 10:32:49 +08:00
										 |  |  |     if (data.is_parallel && data._isShowTips) { | 
					
						
							|  |  |  |       Toast.notify({ | 
					
						
							|  |  |  |         type: 'warning', | 
					
						
							|  |  |  |         message: t(`${i18nPrefix}.answerNodeWarningDesc`), | 
					
						
							|  |  |  |         duration: 5000, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       data._isShowTips = false | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, [nodesInitialized, id, handleNodeIterationRerender, data, t]) | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={cn( | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  |       'relative min-w-[240px] min-h-[90px] w-full h-full rounded-2xl bg-[#F0F2F7]/90', | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     )}> | 
					
						
							|  |  |  |       <Background | 
					
						
							|  |  |  |         id={`iteration-background-${id}`} | 
					
						
							|  |  |  |         className='rounded-2xl !z-0' | 
					
						
							|  |  |  |         gap={[14 / zoom, 14 / zoom]} | 
					
						
							|  |  |  |         size={2 / zoom} | 
					
						
							|  |  |  |         color='#E4E5E7' | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         data._isCandidate && ( | 
					
						
							|  |  |  |           <IterationStartNodeDumb /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         data._children!.length === 1 && ( | 
					
						
							|  |  |  |           <AddBlock | 
					
						
							|  |  |  |             iterationNodeId={id} | 
					
						
							|  |  |  |             iterationNodeData={data} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default memo(Node) |