import { memo } from 'react' import { useTranslation } from 'react-i18next' import { RiLoader2Line, RiPlayLargeLine, } from '@remixicon/react' import { useStore } from '../store' import { useNodesReadOnly, useWorkflowRun, useWorkflowStartRun, } from '../hooks' import { WorkflowRunningStatus } from '../types' import type { ViewHistoryProps } from './view-history' import ViewHistory from './view-history' import Checklist from './checklist' import cn from '@/utils/classnames' import { StopCircle, } from '@/app/components/base/icons/src/vender/line/mediaAndDevices' import { useEventEmitterContextContext } from '@/context/event-emitter' import { EVENT_WORKFLOW_STOP } from '@/app/components/workflow/variable-inspect/types' type RunModeProps = { text?: string isRunning?: boolean onStopRun?: () => void } const RunMode = memo(({ text, isRunning: running, onStopRun, }: RunModeProps) => { const { t } = useTranslation() const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun() const { handleStopRun } = useWorkflowRun() const workflowRunningData = useStore(s => s.workflowRunningData) const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running const mergedRunning = isRunning || running const handleStop = () => { handleStopRun(workflowRunningData?.task_id || '') } const { eventEmitter } = useEventEmitterContextContext() eventEmitter?.useSubscription((v: any) => { if (v.type === EVENT_WORKFLOW_STOP) handleStop() }) return ( <>
{ handleWorkflowStartRunInWorkflow() }} > { mergedRunning ? ( <> {t('workflow.common.running')} ) : ( <> {text ?? t('workflow.common.run')} ) }
{ mergedRunning && (
onStopRun ? onStopRun() : handleStopRun(workflowRunningData?.task_id || '')} >
) } ) }) const PreviewMode = memo(() => { const { t } = useTranslation() const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun() return (
handleWorkflowStartRunInChatflow()} > {t('workflow.common.debugAndPreview')}
) }) export type RunAndHistoryProps = { showRunButton?: boolean runButtonText?: string isRunning?: boolean onStopRun?: () => void showPreviewButton?: boolean viewHistoryProps?: ViewHistoryProps } const RunAndHistory = ({ showRunButton, runButtonText, isRunning, onStopRun, showPreviewButton, viewHistoryProps, }: RunAndHistoryProps) => { const { nodesReadOnly } = useNodesReadOnly() return (
{ showRunButton && } { showPreviewButton && }
) } export default memo(RunAndHistory)