| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  | import { IModalProps } from '@/interfaces/common'; | 
					
						
							| 
									
										
										
										
											2024-06-06 11:01:14 +08:00
										 |  |  | import { Drawer, Form } from 'antd'; | 
					
						
							|  |  |  | import { useEffect } from 'react'; | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  | import { Node } from 'reactflow'; | 
					
						
							|  |  |  | import AnswerForm from '../answer-form'; | 
					
						
							|  |  |  | import BeginForm from '../begin-form'; | 
					
						
							| 
									
										
										
										
											2024-06-25 12:09:07 +08:00
										 |  |  | import CategorizeForm from '../categorize-form'; | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  | import { Operator } from '../constant'; | 
					
						
							|  |  |  | import GenerateForm from '../generate-form'; | 
					
						
							|  |  |  | import { useHandleFormValuesChange } from '../hooks'; | 
					
						
							| 
									
										
										
										
											2024-06-28 16:25:20 +08:00
										 |  |  | import MessageForm from '../message-form'; | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  | import RetrievalForm from '../retrieval-form'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface IProps { | 
					
						
							|  |  |  |   node?: Node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const FormMap = { | 
					
						
							|  |  |  |   [Operator.Begin]: BeginForm, | 
					
						
							|  |  |  |   [Operator.Retrieval]: RetrievalForm, | 
					
						
							|  |  |  |   [Operator.Generate]: GenerateForm, | 
					
						
							|  |  |  |   [Operator.Answer]: AnswerForm, | 
					
						
							| 
									
										
										
										
											2024-06-25 12:09:07 +08:00
										 |  |  |   [Operator.Categorize]: CategorizeForm, | 
					
						
							| 
									
										
										
										
											2024-06-28 16:25:20 +08:00
										 |  |  |   [Operator.Message]: MessageForm, | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const FlowDrawer = ({ | 
					
						
							|  |  |  |   visible, | 
					
						
							|  |  |  |   hideModal, | 
					
						
							|  |  |  |   node, | 
					
						
							|  |  |  | }: IModalProps<any> & IProps) => { | 
					
						
							|  |  |  |   const operatorName: Operator = node?.data.label; | 
					
						
							|  |  |  |   const OperatorForm = FormMap[operatorName]; | 
					
						
							| 
									
										
										
										
											2024-06-06 11:01:14 +08:00
										 |  |  |   const [form] = Form.useForm(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  |   const { handleValuesChange } = useHandleFormValuesChange(node?.id); | 
					
						
							| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-06 11:01:14 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (visible) { | 
					
						
							|  |  |  |       form.setFieldsValue(node?.data?.form); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, [visible, form, node?.data?.form]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <Drawer | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  |       title={node?.data.label} | 
					
						
							| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  |       placement="right" | 
					
						
							|  |  |  |       onClose={hideModal} | 
					
						
							|  |  |  |       open={visible} | 
					
						
							|  |  |  |       getContainer={false} | 
					
						
							|  |  |  |       mask={false} | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  |       width={470} | 
					
						
							| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  |       {visible && ( | 
					
						
							| 
									
										
										
										
											2024-06-06 11:01:14 +08:00
										 |  |  |         <OperatorForm | 
					
						
							|  |  |  |           onValuesChange={handleValuesChange} | 
					
						
							|  |  |  |           form={form} | 
					
						
							| 
									
										
										
										
											2024-06-25 19:28:24 +08:00
										 |  |  |           node={node} | 
					
						
							| 
									
										
										
										
											2024-06-06 11:01:14 +08:00
										 |  |  |         ></OperatorForm> | 
					
						
							| 
									
										
										
										
											2024-06-05 10:46:06 +08:00
										 |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-05-23 18:53:04 +08:00
										 |  |  |     </Drawer> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default FlowDrawer; |