| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiQuestionLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { CodeLanguage } from '../code/types' | 
					
						
							|  |  |  | import useConfig from './use-config' | 
					
						
							|  |  |  | import type { TemplateTransformNodeType } from './types' | 
					
						
							|  |  |  | import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list' | 
					
						
							|  |  |  | import AddButton from '@/app/components/base/button/add-button' | 
					
						
							|  |  |  | import Field from '@/app/components/workflow/nodes/_base/components/field' | 
					
						
							|  |  |  | import Split from '@/app/components/workflow/nodes/_base/components/split' | 
					
						
							| 
									
										
										
										
											2024-04-28 17:51:58 +08:00
										 |  |  | import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' | 
					
						
							|  |  |  | import type { NodePanelProps } from '@/app/components/workflow/types' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18nPrefix = 'workflow.nodes.templateTransform' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Panel: FC<NodePanelProps<TemplateTransformNodeType>> = ({ | 
					
						
							|  |  |  |   id, | 
					
						
							|  |  |  |   data, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     readOnly, | 
					
						
							|  |  |  |     inputs, | 
					
						
							| 
									
										
										
										
											2024-05-10 18:14:05 +08:00
										 |  |  |     availableVars, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     handleVarListChange, | 
					
						
							| 
									
										
										
										
											2024-04-29 11:34:30 +08:00
										 |  |  |     handleVarNameChange, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     handleAddVariable, | 
					
						
							| 
									
										
										
										
											2024-04-28 17:51:58 +08:00
										 |  |  |     handleAddEmptyVariable, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     handleCodeChange, | 
					
						
							|  |  |  |     filterVar, | 
					
						
							|  |  |  |   } = useConfig(id, data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className='mt-2'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='space-y-4 px-4 pb-4'> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         <Field | 
					
						
							|  |  |  |           title={t(`${i18nPrefix}.inputVars`)} | 
					
						
							|  |  |  |           operations={ | 
					
						
							| 
									
										
										
										
											2024-04-28 17:51:58 +08:00
										 |  |  |             !readOnly ? <AddButton onClick={handleAddEmptyVariable} /> : undefined | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <VarList | 
					
						
							|  |  |  |             nodeId={id} | 
					
						
							|  |  |  |             readonly={readOnly} | 
					
						
							|  |  |  |             list={inputs.variables} | 
					
						
							|  |  |  |             onChange={handleVarListChange} | 
					
						
							| 
									
										
										
										
											2024-04-29 11:34:30 +08:00
										 |  |  |             onVarNameChange={handleVarNameChange} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             filterVar={filterVar} | 
					
						
							| 
									
										
										
										
											2024-11-22 16:30:22 +08:00
										 |  |  |             isSupportFileVar={false} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         </Field> | 
					
						
							|  |  |  |         <Split /> | 
					
						
							|  |  |  |         <CodeEditor | 
					
						
							| 
									
										
										
										
											2024-05-10 18:14:05 +08:00
										 |  |  |           availableVars={availableVars} | 
					
						
							| 
									
										
										
										
											2024-04-28 17:51:58 +08:00
										 |  |  |           varList={inputs.variables} | 
					
						
							|  |  |  |           onAddVar={handleAddVariable} | 
					
						
							| 
									
										
										
										
											2024-04-23 17:46:59 +08:00
										 |  |  |           isInNode | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           readOnly={readOnly} | 
					
						
							|  |  |  |           language={CodeLanguage.python3} | 
					
						
							|  |  |  |           title={ | 
					
						
							|  |  |  |             <div className='uppercase'>{t(`${i18nPrefix}.code`)}</div> | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           headerRight={ | 
					
						
							|  |  |  |             <div className='flex items-center'> | 
					
						
							|  |  |  |               <a | 
					
						
							| 
									
										
										
										
											2025-04-10 17:15:48 +08:00
										 |  |  |                 className='flex h-[18px] items-center space-x-0.5 text-xs font-normal text-text-tertiary' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |                 href="https://jinja.palletsprojects.com/en/3.1.x/templates/" | 
					
						
							|  |  |  |                 target='_blank'> | 
					
						
							|  |  |  |                 <span>{t(`${i18nPrefix}.codeSupportTip`)}</span> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <RiQuestionLine className='h-3 w-3' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |               </a> | 
					
						
							| 
									
										
										
										
											2025-04-10 17:15:48 +08:00
										 |  |  |               <div className='mx-1.5 h-3 w-px bg-divider-regular'></div> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             </div> | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           value={inputs.template} | 
					
						
							|  |  |  |           onChange={handleCodeChange} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <Split /> | 
					
						
							| 
									
										
										
										
											2024-12-11 14:21:38 +08:00
										 |  |  |       <div> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         <OutputVars> | 
					
						
							|  |  |  |           <> | 
					
						
							|  |  |  |             <VarItem | 
					
						
							|  |  |  |               name='output' | 
					
						
							|  |  |  |               type='string' | 
					
						
							|  |  |  |               description={t(`${i18nPrefix}.outputVars.output`)} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </> | 
					
						
							|  |  |  |         </OutputVars> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default React.memo(Panel) |