| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { memo } from 'react' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiLoader2Line, | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |   RiPlayLargeLine, | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { useStore } from '../store' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   useIsChatMode, | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |   useNodesReadOnly, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useWorkflowRun, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useWorkflowStartRun, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } from '../hooks' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { WorkflowRunningStatus } from '../types' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import ViewHistory from './view-history' | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | import Checklist from './checklist' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   StopCircle, | 
					
						
							|  |  |  | } from '@/app/components/base/icons/src/vender/line/mediaAndDevices' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RunMode = memo(() => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun() | 
					
						
							|  |  |  |   const { handleStopRun } = useWorkflowRun() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const workflowRunningData = useStore(s => s.workflowRunningData) | 
					
						
							|  |  |  |   const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <div | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |         className={cn( | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |           'flex items-center px-2.5 h-7 rounded-md text-[13px] font-medium text-components-button-secondary-accent-text', | 
					
						
							|  |  |  |           'hover:bg-state-accent-hover cursor-pointer', | 
					
						
							|  |  |  |           isRunning && 'bg-state-accent-hover !cursor-not-allowed', | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |         )} | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |         onClick={() => { | 
					
						
							|  |  |  |           handleWorkflowStartRunInWorkflow() | 
					
						
							|  |  |  |         }} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           isRunning | 
					
						
							|  |  |  |             ? ( | 
					
						
							|  |  |  |               <> | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  |                 <RiLoader2Line className='mr-1 w-4 h-4 animate-spin' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |                 {t('workflow.common.running')} | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             : ( | 
					
						
							|  |  |  |               <> | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |                 <RiPlayLargeLine className='mr-1 w-4 h-4' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |                 {t('workflow.common.run')} | 
					
						
							|  |  |  |               </> | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         isRunning && ( | 
					
						
							|  |  |  |           <div | 
					
						
							|  |  |  |             className='flex items-center justify-center ml-0.5 w-7 h-7 cursor-pointer hover:bg-black/5 rounded-md' | 
					
						
							|  |  |  |             onClick={() => handleStopRun(workflowRunningData?.task_id || '')} | 
					
						
							|  |  |  |           > | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |             <StopCircle className='w-4 h-4 text-components-button-ghost-text' /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | RunMode.displayName = 'RunMode' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const PreviewMode = memo(() => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |       className={cn( | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |         'flex items-center px-2.5 h-7 rounded-md text-[13px] font-medium text-components-button-secondary-accent-text', | 
					
						
							|  |  |  |         'hover:bg-state-accent-hover cursor-pointer', | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       onClick={() => handleWorkflowStartRunInChatflow()} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |       <RiPlayLargeLine className='mr-1 w-4 h-4' /> | 
					
						
							| 
									
										
										
										
											2024-04-28 17:09:56 +08:00
										 |  |  |       {t('workflow.common.debugAndPreview')} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | PreviewMode.displayName = 'PreviewMode' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RunAndHistory: FC = () => { | 
					
						
							|  |  |  |   const isChatMode = useIsChatMode() | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |   const { nodesReadOnly } = useNodesReadOnly() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |     <div className='flex items-center px-0.5 h-8 rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg shadow-xs'> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         !isChatMode && <RunMode /> | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         isChatMode && <PreviewMode /> | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |       <div className='mx-0.5 w-[1px] h-3.5 bg-divider-regular'></div> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       <ViewHistory /> | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |       <Checklist disabled={nodesReadOnly} /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default memo(RunAndHistory) |