From 6f865b96a2b7e56b0c31047f39cd74ffe3cdd62e Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Thu, 26 Dec 2024 14:40:42 +0800 Subject: [PATCH] refact workflow run log --- .../workflow/nodes/iteration/panel.tsx | 2 - .../workflow/panel/workflow-preview.tsx | 282 +++++++----------- web/app/components/workflow/run/index.tsx | 43 +-- .../iteration-log/iteration-result-panel.tsx | 96 ++---- web/app/components/workflow/run/meta.tsx | 2 +- .../components/workflow/run/output-panel.tsx | 4 +- .../workflow/run/special-result-panel.tsx | 1 - .../components/workflow/run/tracing-panel.tsx | 48 ++- 8 files changed, 177 insertions(+), 301 deletions(-) diff --git a/web/app/components/workflow/nodes/iteration/panel.tsx b/web/app/components/workflow/nodes/iteration/panel.tsx index 2ad2cac2d9..83402e9cad 100644 --- a/web/app/components/workflow/nodes/iteration/panel.tsx +++ b/web/app/components/workflow/nodes/iteration/panel.tsx @@ -53,7 +53,6 @@ const Panel: FC> = ({ isShowIterationDetail, backToSingleRun, showIterationDetail, - hideIterationDetail, runningStatus, handleRun, handleStop, @@ -181,7 +180,6 @@ const Panel: FC> = ({ {isShowIterationDetail && ( )} diff --git a/web/app/components/workflow/panel/workflow-preview.tsx b/web/app/components/workflow/panel/workflow-preview.tsx index 2e7f859b93..b4e4d4c5d1 100644 --- a/web/app/components/workflow/panel/workflow-preview.tsx +++ b/web/app/components/workflow/panel/workflow-preview.tsx @@ -1,8 +1,6 @@ import { memo, - useCallback, useEffect, - // useRef, useState, } from 'react' import { @@ -11,7 +9,6 @@ import { } 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' @@ -24,12 +21,9 @@ import { } from '../types' import { SimpleBtn } from '../../app/text-generate/item' import Toast from '../../base/toast' -import { IterationResultPanel } from '../run/iteration-log' -import { RetryResultPanel } from '../run/retry-log' import InputsPanel from './inputs-panel' import cn from '@/utils/classnames' import Loading from '@/app/components/base/loading' -import type { IterationDurationMap, NodeTracing } from '@/types/workflow' const WorkflowPreview = () => { const { t } = useTranslation() @@ -53,44 +47,6 @@ const WorkflowPreview = () => { switchTab('DETAIL') }, [workflowRunningData]) - const [iterationRunResult, setIterationRunResult] = useState([]) - const [retryRunResult, setRetryRunResult] = useState([]) - const [iterDurationMap, setIterDurationMap] = useState({}) - const [isShowIterationDetail, { - setTrue: doShowIterationDetail, - setFalse: doHideIterationDetail, - }] = useBoolean(false) - const [isShowRetryDetail, { - setTrue: doShowRetryDetail, - setFalse: doHideRetryDetail, - }] = useBoolean(false) - - const handleShowIterationDetail = useCallback((detail: NodeTracing[][], iterationDurationMap: IterationDurationMap) => { - setIterDurationMap(iterationDurationMap) - setIterationRunResult(detail) - doShowIterationDetail() - }, [doShowIterationDetail]) - - const handleRetryDetail = useCallback((detail: NodeTracing[]) => { - setRetryRunResult(detail) - doShowRetryDetail() - }, [doShowRetryDetail]) - - if (isShowIterationDetail) { - return ( -
- -
- ) - } - return (
{
- {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' && ( <> -
- {showInputsPanel && ( -
switchTab('INPUT')} - >{t('runLog.input')}
- )} -
switchTab('DETAIL')} + /> + {(workflowRunningData?.result.status === WorkflowRunningStatus.Succeeded && workflowRunningData?.resultText && typeof workflowRunningData?.resultText === 'string') && ( + { - 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' && !isShowRetryDetail && ( - - )} - {currentTab === 'TRACING' && !workflowRunningData?.tracing?.length && ( -
- -
- )} - { - currentTab === 'TRACING' && isShowRetryDetail && ( - - ) - } -
+ 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 && ( +
+ +
+ )} +
) diff --git a/web/app/components/workflow/run/index.tsx b/web/app/components/workflow/run/index.tsx index b4de75fa64..557fb8b06e 100644 --- a/web/app/components/workflow/run/index.tsx +++ b/web/app/components/workflow/run/index.tsx @@ -6,8 +6,6 @@ import { useTranslation } from 'react-i18next' import OutputPanel from './output-panel' import ResultPanel from './result-panel' import TracingPanel from './tracing-panel' -import SpecialResultPanel from './special-result-panel' -import { useLogs } from './hooks' import cn from '@/utils/classnames' import { ToastContext } from '@/app/components/base/toast' import Loading from '@/app/components/base/loading' @@ -105,24 +103,6 @@ const RunPanel: FC = ({ hideResult, activeTab = 'RESULT', runID, getRe adjustResultHeight() }, [loading]) - const { - showSpecialResultPanel, - - showRetryDetail, - setShowRetryDetailFalse, - retryResultList, - handleShowRetryResultList, - - showIteratingDetail, - setShowIteratingDetailFalse, - iterationResultList, - iterationResultDurationMap, - handleShowIterationResultList, - - showAgentDetail, - setShowAgentDetailFalse, - } = useLogs() - return (
{/* tab */} @@ -152,7 +132,7 @@ const RunPanel: FC = ({ hideResult, activeTab = 'RESULT', runID, getRe >{t('runLog.tracing')}
{/* panel detail */} -
+
{loading && (
@@ -179,31 +159,12 @@ const RunPanel: FC = ({ hideResult, activeTab = 'RESULT', runID, getRe exceptionCounts={runDetail.exceptions_count} /> )} - {!loading && currentTab === 'TRACING' && !showSpecialResultPanel && ( + {!loading && currentTab === 'TRACING' && ( )} - { - !loading && currentTab === 'TRACING' && showSpecialResultPanel && ( - - ) - }
) diff --git a/web/app/components/workflow/run/iteration-log/iteration-result-panel.tsx b/web/app/components/workflow/run/iteration-log/iteration-result-panel.tsx index 07e0db969f..19f79feb13 100644 --- a/web/app/components/workflow/run/iteration-log/iteration-result-panel.tsx +++ b/web/app/components/workflow/run/iteration-log/iteration-result-panel.tsx @@ -3,15 +3,13 @@ import type { FC } from 'react' import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { + RiArrowLeftLine, RiArrowRightSLine, - RiCloseLine, RiErrorWarningLine, RiLoader2Line, } from '@remixicon/react' -import { ArrowNarrowLeft } from '@/app/components/base/icons/src/vender/line/arrows' import { NodeRunningStatus } from '@/app/components/workflow/types' import TracingPanel from '@/app/components/workflow/run/tracing-panel' -import { RetryResultPanel } from '@/app/components/workflow/run/retry-log' import { Iteration } from '@/app/components/base/icons/src/vender/workflow' import cn from '@/utils/classnames' import type { IterationDurationMap, NodeTracing } from '@/types/workflow' @@ -19,17 +17,13 @@ const i18nPrefix = 'workflow.singleRun' type Props = { list: NodeTracing[][] - onHide: () => void onBack: () => void - noWrap?: boolean iterDurationMap?: IterationDurationMap } const IterationResultPanel: FC = ({ list, - onHide, onBack, - noWrap, iterDurationMap, }) => { const { t } = useTranslation() @@ -75,29 +69,22 @@ const IterationResultPanel: FC = ({ ) } - const [retryRunResult, setRetryRunResult] = useState | undefined>() - const handleRetryDetail = (v: number, detail?: NodeTracing[]) => { - setRetryRunResult({ ...retryRunResult, [v]: detail }) - } - const main = ( - <> -
-
-
- {t(`${i18nPrefix}.testRunIteration`)} -
-
- -
-
-
- -
{t(`${i18nPrefix}.back`)}
-
+ return ( +
+
{ + e.stopPropagation() + e.nativeEvent.stopImmediatePropagation() + onBack() + }} + > + +
{t(`${i18nPrefix}.back`)}
{/* List */} -
+
{list.map((iteration, index) => (
= ({ {expandedIterations[index] &&
} - { - !retryRunResult?.[index] && ( -
- handleRetryDetail(index, v)} - /> -
- ) - } - { - retryRunResult?.[index] && ( - handleRetryDetail(index, undefined)} - /> - ) - } +
+ +
))}
- - ) - const handleNotBubble = useCallback((e: React.MouseEvent) => { - // if not do this, it will trigger the message log modal disappear(useClickAway) - e.stopPropagation() - e.nativeEvent.stopImmediatePropagation() - }, []) - - if (noWrap) - return main - - return ( -
-
- {main} -
-
+
) } export default React.memo(IterationResultPanel) diff --git a/web/app/components/workflow/run/meta.tsx b/web/app/components/workflow/run/meta.tsx index 9326125101..d99261bb9d 100644 --- a/web/app/components/workflow/run/meta.tsx +++ b/web/app/components/workflow/run/meta.tsx @@ -3,7 +3,7 @@ import type { FC } from 'react' import { useTranslation } from 'react-i18next' import useTimestamp from '@/hooks/use-timestamp' -interface Props { +type Props = { status: string executor?: string startTime?: number diff --git a/web/app/components/workflow/run/output-panel.tsx b/web/app/components/workflow/run/output-panel.tsx index 6a5443e51b..6a2a359483 100644 --- a/web/app/components/workflow/run/output-panel.tsx +++ b/web/app/components/workflow/run/output-panel.tsx @@ -9,7 +9,7 @@ import { FileList } from '@/app/components/base/file-uploader' import StatusContainer from '@/app/components/workflow/run/status-container' import { getProcessedFilesFromResponse } from '@/app/components/base/file-uploader/utils' -interface OutputPanelProps { +type OutputPanelProps = { isRunning?: boolean outputs?: any error?: string @@ -47,7 +47,7 @@ const OutputPanel: FC = ({ return getProcessedFilesFromResponse(fileList) }, [outputs]) return ( -
+
{isRunning && (
diff --git a/web/app/components/workflow/run/special-result-panel.tsx b/web/app/components/workflow/run/special-result-panel.tsx index 0995ecf1ef..c66a9f4472 100644 --- a/web/app/components/workflow/run/special-result-panel.tsx +++ b/web/app/components/workflow/run/special-result-panel.tsx @@ -43,7 +43,6 @@ const SpecialResultPanel = ({ showIteratingDetail && ( diff --git a/web/app/components/workflow/run/tracing-panel.tsx b/web/app/components/workflow/run/tracing-panel.tsx index 8329b88cbd..fd6a9fdde5 100644 --- a/web/app/components/workflow/run/tracing-panel.tsx +++ b/web/app/components/workflow/run/tracing-panel.tsx @@ -12,16 +12,16 @@ import { RiMenu4Line, } from '@remixicon/react' import { useTranslation } from 'react-i18next' +import { useLogs } from './hooks' import NodePanel from './node' +import SpecialResultPanel from './special-result-panel' import { BlockEnum, } from '@/app/components/workflow/types' -import type { IterationDurationMap, NodeTracing } from '@/types/workflow' +import type { NodeTracing } from '@/types/workflow' type TracingPanelProps = { list: NodeTracing[] - onShowIterationDetail?: (detail: NodeTracing[][], iterDurationMap: IterationDurationMap) => void - onShowRetryDetail?: (detail: NodeTracing[]) => void className?: string hideNodeInfo?: boolean hideNodeProcessDetail?: boolean @@ -160,8 +160,6 @@ function buildLogTree(nodes: NodeTracing[], t: (key: string) => string): Tracing const TracingPanel: FC = ({ list, - onShowIterationDetail, - onShowRetryDetail, className, hideNodeInfo = false, hideNodeProcessDetail = false, @@ -203,6 +201,24 @@ const TracingPanel: FC = ({ } }, []) + const { + showSpecialResultPanel, + + showRetryDetail, + setShowRetryDetailFalse, + retryResultList, + handleShowRetryResultList, + + showIteratingDetail, + setShowIteratingDetailFalse, + iterationResultList, + iterationResultDurationMap, + handleShowIterationResultList, + + showAgentDetail, + setShowAgentDetailFalse, + } = useLogs() + const renderNode = (node: TracingNodeProps) => { if (node.isParallel) { const isCollapsed = collapsedNodes.has(node.id) @@ -252,8 +268,8 @@ const TracingPanel: FC = ({
= ({ } } + if (showSpecialResultPanel) { + return ( + + ) + } + return (
{treeNodes.map(renderNode)}