import React, { useCallback } from 'react' // import { useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' import { useWorkflowRun, /* useWorkflowRunValidation, */ useWorkflowStartRun } from '@/app/components/workflow/hooks' import { useStore } from '@/app/components/workflow/store' import { WorkflowRunningStatus } from '@/app/components/workflow/types' import { useEventEmitterContextContext } from '@/context/event-emitter' import { EVENT_WORKFLOW_STOP } from '@/app/components/workflow/variable-inspect/types' import { getKeyboardKeyNameBySystem } from '@/app/components/workflow/utils' import cn from '@/utils/classnames' import { RiLoader2Line, RiPlayLargeLine } from '@remixicon/react' import { StopCircle } from '@/app/components/base/icons/src/vender/line/mediaAndDevices' // import ShortcutsName from '../shortcuts-name' // import { useDynamicTestRunOptions } from '../hooks/use-dynamic-test-run-options' // import TestRunMenu, { type TestRunMenuRef, type TriggerOption } from './test-run-menu' type RunModeProps = { text?: string } const RunMode = ({ text, }: RunModeProps) => { const { t } = useTranslation() const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun() const { handleStopRun } = useWorkflowRun() // const { validateBeforeRun } = useWorkflowRunValidation() const workflowRunningData = useStore(s => s.workflowRunningData) const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running // const dynamicOptions = useDynamicTestRunOptions() // const testRunMenuRef = useRef(null) // useEffect(() => { // // @ts-expect-error - Dynamic property for backward compatibility with keyboard shortcuts // window._toggleTestRunDropdown = () => { // testRunMenuRef.current?.toggle() // } // return () => { // // @ts-expect-error - Dynamic property cleanup // delete window._toggleTestRunDropdown // } // }, []) const handleStop = useCallback(() => { handleStopRun(workflowRunningData?.task_id || '') }, [handleStopRun, workflowRunningData?.task_id]) // const handleTriggerSelect = (option: TriggerOption) => { // // Validate checklist before running any workflow // if (!validateBeforeRun()) // return // if (option.type === 'user_input') { // handleWorkflowStartRunInWorkflow() // } // else { // // Placeholder for trigger-specific execution logic for schedule, webhook, plugin types // console.log('TODO: Handle trigger execution for type:', option.type, 'nodeId:', option.nodeId) // } // } const { eventEmitter } = useEventEmitterContextContext() eventEmitter?.useSubscription((v: any) => { if (v.type === EVENT_WORKFLOW_STOP) handleStop() }) return (
{ isRunning && ( ) }
) } export default React.memo(RunMode)