| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  | import Field from '../_base/components/field' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import RemoveEffectVarConfirm from '../_base/components/remove-effect-var-confirm' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import useConfig from './use-config' | 
					
						
							|  |  |  | import type { VariableAssignerNodeType } from './types' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import VarGroupItem from './components/var-group-item' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import { type NodePanelProps } from '@/app/components/workflow/types' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import Split from '@/app/components/workflow/nodes/_base/components/split' | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  | import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' | 
					
						
							|  |  |  | import Switch from '@/app/components/base/switch' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import AddButton from '@/app/components/workflow/nodes/_base/components/add-button' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const i18nPrefix = 'workflow.nodes.variableAssigner' | 
					
						
							|  |  |  | const Panel: FC<NodePanelProps<VariableAssignerNodeType>> = ({ | 
					
						
							|  |  |  |   id, | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     readOnly, | 
					
						
							|  |  |  |     inputs, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     handleListOrTypeChange, | 
					
						
							|  |  |  |     isEnableGroup, | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  |     handleGroupEnabledChange, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |     handleAddGroup, | 
					
						
							|  |  |  |     handleListOrTypeChangeInGroup, | 
					
						
							|  |  |  |     handleGroupRemoved, | 
					
						
							|  |  |  |     handleVarGroupNameChange, | 
					
						
							|  |  |  |     isShowRemoveVarConfirm, | 
					
						
							|  |  |  |     hideRemoveVarConfirm, | 
					
						
							|  |  |  |     onRemoveVarConfirm, | 
					
						
							|  |  |  |     getAvailableVars, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     filterVar, | 
					
						
							|  |  |  |   } = useConfig(id, data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className='mt-2'> | 
					
						
							|  |  |  |       <div className='px-4 pb-4 space-y-4'> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         {!isEnableGroup | 
					
						
							|  |  |  |           ? ( | 
					
						
							|  |  |  |             <VarGroupItem | 
					
						
							|  |  |  |               readOnly={readOnly} | 
					
						
							|  |  |  |               nodeId={id} | 
					
						
							|  |  |  |               payload={{ | 
					
						
							|  |  |  |                 output_type: inputs.output_type, | 
					
						
							|  |  |  |                 variables: inputs.variables, | 
					
						
							|  |  |  |               }} | 
					
						
							|  |  |  |               onChange={handleListOrTypeChange} | 
					
						
							|  |  |  |               groupEnabled={false} | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |               availableVars={getAvailableVars(id, 'target', filterVar(inputs.output_type), true)} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             /> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           : (<div> | 
					
						
							|  |  |  |             <div className='space-y-2'> | 
					
						
							|  |  |  |               {inputs.advanced_settings?.groups.map((item, index) => ( | 
					
						
							|  |  |  |                 <div key={item.groupId}> | 
					
						
							|  |  |  |                   <VarGroupItem | 
					
						
							|  |  |  |                     readOnly={readOnly} | 
					
						
							|  |  |  |                     nodeId={id} | 
					
						
							|  |  |  |                     payload={item} | 
					
						
							|  |  |  |                     onChange={handleListOrTypeChangeInGroup(item.groupId)} | 
					
						
							|  |  |  |                     groupEnabled | 
					
						
							|  |  |  |                     canRemove={!readOnly && inputs.advanced_settings?.groups.length > 1} | 
					
						
							|  |  |  |                     onRemove={handleGroupRemoved(item.groupId)} | 
					
						
							|  |  |  |                     onGroupNameChange={handleVarGroupNameChange(item.groupId)} | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |                     availableVars={getAvailableVars(id, item.groupId, filterVar(item.output_type), true)} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |                   /> | 
					
						
							|  |  |  |                   {index !== inputs.advanced_settings?.groups.length - 1 && <Split className='my-4' />} | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               ))} | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |             <AddButton | 
					
						
							|  |  |  |               className='mt-2' | 
					
						
							|  |  |  |               text={t(`${i18nPrefix}.addGroup`)} | 
					
						
							|  |  |  |               onClick={handleAddGroup} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </div>)} | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  |       <Split /> | 
					
						
							|  |  |  |       <div className={cn('px-4 pt-4', isEnableGroup ? 'pb-4' : 'pb-2')}> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         <Field | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |           title={t(`${i18nPrefix}.aggregationGroup`)} | 
					
						
							|  |  |  |           tooltip={t(`${i18nPrefix}.aggregationGroupTip`)!} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           operations={ | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |             <Switch | 
					
						
							|  |  |  |               defaultValue={isEnableGroup} | 
					
						
							|  |  |  |               onChange={handleGroupEnabledChange} | 
					
						
							|  |  |  |               size='md' | 
					
						
							|  |  |  |               disabled={readOnly} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             /> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |       {isEnableGroup && ( | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         <> | 
					
						
							|  |  |  |           <Split /> | 
					
						
							|  |  |  |           <div className='px-4 pt-4 pb-2'> | 
					
						
							|  |  |  |             <OutputVars> | 
					
						
							|  |  |  |               <> | 
					
						
							|  |  |  |                 {inputs.advanced_settings?.groups.map((item, index) => ( | 
					
						
							|  |  |  |                   <VarItem | 
					
						
							|  |  |  |                     key={index} | 
					
						
							|  |  |  |                     name={`${item.group_name}.output`} | 
					
						
							|  |  |  |                     type={item.output_type} | 
					
						
							|  |  |  |                     description={t(`${i18nPrefix}.outputVars.varDescribe`, { | 
					
						
							|  |  |  |                       groupName: item.group_name, | 
					
						
							|  |  |  |                     })} | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 ))} | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             </OutputVars> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </> | 
					
						
							| 
									
										
										
										
											2024-05-30 18:54:58 +08:00
										 |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |       <RemoveEffectVarConfirm | 
					
						
							|  |  |  |         isShow={isShowRemoveVarConfirm} | 
					
						
							|  |  |  |         onCancel={hideRemoveVarConfirm} | 
					
						
							|  |  |  |         onConfirm={onRemoveVarConfirm} | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default React.memo(Panel) |