| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							| 
									
										
										
										
											2025-06-24 09:10:30 +08:00
										 |  |  | import React from 'react' | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  | import { RiAddLine } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import Split from '../_base/components/split' | 
					
						
							|  |  |  | import InputNumberWithSlider from '../_base/components/input-number-with-slider' | 
					
						
							|  |  |  | import type { LoopNodeType } from './types' | 
					
						
							|  |  |  | import useConfig from './use-config' | 
					
						
							|  |  |  | import ConditionWrap from './components/condition-wrap' | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  | import LoopVariable from './components/loop-variables' | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import type { NodePanelProps } from '@/app/components/workflow/types' | 
					
						
							|  |  |  | import Field from '@/app/components/workflow/nodes/_base/components/field' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { LOOP_NODE_MAX_COUNT } from '@/config' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18nPrefix = 'workflow.nodes.loop' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Panel: FC<NodePanelProps<LoopNodeType>> = ({ | 
					
						
							|  |  |  |   id, | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     readOnly, | 
					
						
							|  |  |  |     inputs, | 
					
						
							|  |  |  |     childrenNodeVars, | 
					
						
							|  |  |  |     loopChildrenNodes, | 
					
						
							|  |  |  |     handleAddCondition, | 
					
						
							|  |  |  |     handleUpdateCondition, | 
					
						
							|  |  |  |     handleRemoveCondition, | 
					
						
							|  |  |  |     handleToggleConditionLogicalOperator, | 
					
						
							|  |  |  |     handleAddSubVariableCondition, | 
					
						
							|  |  |  |     handleRemoveSubVariableCondition, | 
					
						
							|  |  |  |     handleUpdateSubVariableCondition, | 
					
						
							|  |  |  |     handleToggleSubVariableConditionLogicalOperator, | 
					
						
							|  |  |  |     handleUpdateLoopCount, | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  |     handleAddLoopVariable, | 
					
						
							|  |  |  |     handleRemoveLoopVariable, | 
					
						
							|  |  |  |     handleUpdateLoopVariable, | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   } = useConfig(id, data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className='mt-2'> | 
					
						
							|  |  |  |       <div> | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  |         <Field | 
					
						
							|  |  |  |           title={<div className='pl-3'>{t('workflow.nodes.loop.loopVariables')}</div>} | 
					
						
							|  |  |  |           operations={ | 
					
						
							|  |  |  |             <div | 
					
						
							|  |  |  |               className='mr-4 flex h-5 w-5 cursor-pointer items-center justify-center' | 
					
						
							|  |  |  |               onClick={handleAddLoopVariable} | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               <RiAddLine className='h-4 w-4 text-text-tertiary' /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <div className='px-4'> | 
					
						
							|  |  |  |             <LoopVariable | 
					
						
							|  |  |  |               variables={inputs.loop_variables} | 
					
						
							|  |  |  |               nodeId={id} | 
					
						
							|  |  |  |               handleRemoveLoopVariable={handleRemoveLoopVariable} | 
					
						
							|  |  |  |               handleUpdateLoopVariable={handleUpdateLoopVariable} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </Field> | 
					
						
							|  |  |  |         <Split className='my-2' /> | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |         <Field | 
					
						
							|  |  |  |           title={<div className='pl-3'>{t(`${i18nPrefix}.breakCondition`)}</div>} | 
					
						
							| 
									
										
										
										
											2025-03-12 10:10:51 +08:00
										 |  |  |           tooltip={t(`${i18nPrefix}.breakConditionTip`)} | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |         > | 
					
						
							|  |  |  |           <ConditionWrap | 
					
						
							|  |  |  |             nodeId={id} | 
					
						
							|  |  |  |             readOnly={readOnly} | 
					
						
							|  |  |  |             handleAddCondition={handleAddCondition} | 
					
						
							|  |  |  |             handleRemoveCondition={handleRemoveCondition} | 
					
						
							|  |  |  |             handleUpdateCondition={handleUpdateCondition} | 
					
						
							|  |  |  |             handleToggleConditionLogicalOperator={handleToggleConditionLogicalOperator} | 
					
						
							|  |  |  |             handleAddSubVariableCondition={handleAddSubVariableCondition} | 
					
						
							|  |  |  |             handleRemoveSubVariableCondition={handleRemoveSubVariableCondition} | 
					
						
							|  |  |  |             handleUpdateSubVariableCondition={handleUpdateSubVariableCondition} | 
					
						
							|  |  |  |             handleToggleSubVariableConditionLogicalOperator={handleToggleSubVariableConditionLogicalOperator} | 
					
						
							|  |  |  |             availableNodes={loopChildrenNodes} | 
					
						
							|  |  |  |             availableVars={childrenNodeVars} | 
					
						
							|  |  |  |             conditions={inputs.break_conditions || []} | 
					
						
							|  |  |  |             logicalOperator={inputs.logical_operator!} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </Field> | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  |         <Split className='mt-2' /> | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |         <div className='mt-2'> | 
					
						
							|  |  |  |           <Field | 
					
						
							|  |  |  |             title={<div className='pl-3'>{t(`${i18nPrefix}.loopMaxCount`)}</div>} | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <div className='px-3 py-2'> | 
					
						
							|  |  |  |               <InputNumberWithSlider | 
					
						
							|  |  |  |                 min={1} | 
					
						
							|  |  |  |                 max={LOOP_NODE_MAX_COUNT} | 
					
						
							|  |  |  |                 value={inputs.loop_count} | 
					
						
							|  |  |  |                 onChange={(val) => { | 
					
						
							|  |  |  |                   const roundedVal = Math.round(val) | 
					
						
							|  |  |  |                   handleUpdateLoopCount(Number.isNaN(roundedVal) ? 1 : roundedVal) | 
					
						
							|  |  |  |                 }} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </Field> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       {/* Error handling for the Loop node is currently not considered. */} | 
					
						
							|  |  |  |       {/* <div className='px-4 py-2'> | 
					
						
							|  |  |  |         <Field title={t(`${i18nPrefix}.errorResponseMethod`)} > | 
					
						
							|  |  |  |           <Select items={responseMethod} defaultValue={inputs.error_handle_mode} onSelect={changeErrorResponseMode} allowSearch={false}> | 
					
						
							|  |  |  |           </Select> | 
					
						
							|  |  |  |         </Field> | 
					
						
							|  |  |  |       </div> */} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default React.memo(Panel) |