import { memo, useCallback, useEffect, // useRef, useState, } from 'react' import { RiClipboardLine, RiCloseLine, } from '@remixicon/react' import { useTranslation } from 'react-i18next' import copy from 'copy-to-clipboard' import { useBoolean } from 'ahooks' import ResultText from '../run/result-text' import ResultPanel from '../run/result-panel' import TracingPanel from '../run/tracing-panel' import { useWorkflowInteractions, } from '../hooks' import { useStore } from '../store' import { WorkflowRunningStatus, } from '../types' import { SimpleBtn } from '../../app/text-generate/item' import Toast from '../../base/toast' import IterationResultPanel from '../run/iteration-result-panel' import InputsPanel from './inputs-panel' import cn from '@/utils/classnames' import Loading from '@/app/components/base/loading' import type { NodeTracing } from '@/types/workflow' const WorkflowPreview = () => { const { t } = useTranslation() const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions() const workflowRunningData = useStore(s => s.workflowRunningData) const showInputsPanel = useStore(s => s.showInputsPanel) const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel) const [currentTab, setCurrentTab] = useState(showInputsPanel ? 'INPUT' : 'TRACING') const switchTab = async (tab: string) => { setCurrentTab(tab) } useEffect(() => { if (showDebugAndPreviewPanel && showInputsPanel) setCurrentTab('INPUT') }, [showDebugAndPreviewPanel, showInputsPanel]) useEffect(() => { if ((workflowRunningData?.result.status === WorkflowRunningStatus.Succeeded || workflowRunningData?.result.status === WorkflowRunningStatus.Failed) && !workflowRunningData.resultText) switchTab('DETAIL') }, [workflowRunningData]) const [iterationRunResult, setIterationRunResult] = useState([]) const [isShowIterationDetail, { setTrue: doShowIterationDetail, setFalse: doHideIterationDetail, }] = useBoolean(false) const handleShowIterationDetail = useCallback((detail: NodeTracing[][]) => { setIterationRunResult(detail) doShowIterationDetail() }, [doShowIterationDetail]) if (isShowIterationDetail) { return (
) } return (
{`Test Run${!workflowRunningData?.result.sequence_number ? '' : `#${workflowRunningData?.result.sequence_number}`}`}
handleCancelDebugAndPreviewPanel()}>
{isShowIterationDetail ? ( ) : ( <>
{showInputsPanel && (
switchTab('INPUT')} >{t('runLog.input')}
)}
{ if (!workflowRunningData) return switchTab('RESULT') }} >{t('runLog.result')}
{ if (!workflowRunningData) return switchTab('DETAIL') }} >{t('runLog.detail')}
{ if (!workflowRunningData) return switchTab('TRACING') }} >{t('runLog.tracing')}
{currentTab === 'INPUT' && showInputsPanel && ( switchTab('RESULT')} /> )} {currentTab === 'RESULT' && ( <> switchTab('DETAIL')} /> {(workflowRunningData?.result.status === WorkflowRunningStatus.Succeeded && workflowRunningData?.resultText && typeof workflowRunningData?.resultText === 'string') && ( { const content = workflowRunningData?.resultText if (typeof content === 'string') copy(content) else copy(JSON.stringify(content)) Toast.notify({ type: 'success', message: t('common.actionMsg.copySuccessfully') }) }}>
{t('common.operation.copy')}
)} )} {currentTab === 'DETAIL' && ( )} {currentTab === 'DETAIL' && !workflowRunningData?.result && (
)} {currentTab === 'TRACING' && ( )} {currentTab === 'TRACING' && !workflowRunningData?.tracing?.length && (
)}
)}
) } export default memo(WorkflowPreview)