| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useNodes } from 'reactflow' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import NodeVariableItem from '../variable-assigner/components/node-variable-item' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import type { AssignerNodeType } from './types' | 
					
						
							| 
									
										
										
										
											2025-06-04 17:34:12 +08:00
										 |  |  | import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  | import { BlockEnum, type Node, type NodeProps } from '@/app/components/workflow/types' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18nPrefix = 'workflow.nodes.assigner' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const NodeComponent: FC<NodeProps<AssignerNodeType>> = ({ | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const nodes: Node[] = useNodes() | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |   if (data.version === '2') { | 
					
						
							|  |  |  |     const { items: operationItems } = data | 
					
						
							|  |  |  |     const validOperationItems = operationItems?.filter(item => | 
					
						
							|  |  |  |       item.variable_selector && item.variable_selector.length > 0, | 
					
						
							|  |  |  |     ) || [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (validOperationItems.length === 0) { | 
					
						
							|  |  |  |       return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className='relative flex flex-col items-start gap-0.5 self-stretch px-3 py-1'> | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |           <div className='flex flex-col items-start gap-1 self-stretch'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             <div className='flex items-center gap-1 self-stretch rounded-md bg-workflow-block-parma-bg px-[5px] py-1'> | 
					
						
							|  |  |  |               <div className='system-xs-medium flex-1 text-text-tertiary'>{t(`${i18nPrefix}.varNotSet`)}</div> | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='relative flex flex-col items-start gap-0.5 self-stretch px-3 py-1'> | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |         {operationItems.map((value, index) => { | 
					
						
							|  |  |  |           const variable = value.variable_selector | 
					
						
							|  |  |  |           if (!variable || variable.length === 0) | 
					
						
							|  |  |  |             return null | 
					
						
							|  |  |  |           const isSystem = isSystemVar(variable) | 
					
						
							|  |  |  |           const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) | 
					
						
							|  |  |  |           return ( | 
					
						
							|  |  |  |             <NodeVariableItem | 
					
						
							|  |  |  |               key={index} | 
					
						
							|  |  |  |               node={node as Node} | 
					
						
							| 
									
										
										
										
											2025-06-04 17:34:12 +08:00
										 |  |  |               variable={variable} | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |               writeMode={value.operation} | 
					
						
							|  |  |  |               className='bg-workflow-block-parma-bg' | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         })} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // Legacy version
 | 
					
						
							|  |  |  |   const { assigned_variable_selector: variable, write_mode: writeMode } = data as any | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!variable || variable.length === 0) | 
					
						
							|  |  |  |     return null | 
					
						
							|  |  |  |   const isSystem = isSystemVar(variable) | 
					
						
							|  |  |  |   const node = isSystem ? nodes.find(node => node.data.type === BlockEnum.Start) : nodes.find(node => node.id === variable[0]) | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |     <div className='relative flex flex-col items-start gap-0.5 self-stretch px-3 py-1'> | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  |       <NodeVariableItem | 
					
						
							|  |  |  |         node={node as Node} | 
					
						
							| 
									
										
										
										
											2025-06-04 17:34:12 +08:00
										 |  |  |         variable={variable} | 
					
						
							| 
									
										
										
										
											2024-12-03 13:56:40 +08:00
										 |  |  |         writeMode={writeMode} | 
					
						
							| 
									
										
										
										
											2024-08-13 14:44:10 +08:00
										 |  |  |         className='bg-workflow-block-parma-bg' | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default React.memo(NodeComponent) |