From 36c3774fac8088669683b76a0519d6b0c2ccb155 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Tue, 2 Apr 2024 16:57:11 +0800 Subject: [PATCH] modify test run panel --- .../workflow/header/run-and-history.tsx | 6 +- .../workflow/header/view-history.tsx | 1 + .../workflow/hooks/use-workflow-run.ts | 12 +++ web/app/components/workflow/panel/index.tsx | 11 +-- .../workflow/panel/inputs-panel.tsx | 81 +++++++++---------- .../workflow/panel/workflow-preview.tsx | 67 ++++++++++++--- .../components/workflow/run/output-panel.tsx | 18 ++++- web/i18n/en-US/run-log.ts | 1 + web/i18n/zh-Hans/run-log.ts | 1 + 9 files changed, 127 insertions(+), 71 deletions(-) diff --git a/web/app/components/workflow/header/run-and-history.tsx b/web/app/components/workflow/header/run-and-history.tsx index 43143013ee..25a037976a 100644 --- a/web/app/components/workflow/header/run-and-history.tsx +++ b/web/app/components/workflow/header/run-and-history.tsx @@ -44,7 +44,6 @@ const RunMode = memo(() => { const handleClick = useCallback(async () => { const { - setShowInputsPanel, workflowRunningData, } = workflowStore.getState() @@ -63,7 +62,10 @@ const RunMode = memo(() => { handleRun({ inputs: {}, files: [] }) } else { - setShowInputsPanel(true) + workflowStore.setState({ + historyWorkflowData: undefined, + showInputsPanel: true, + }) handleSyncWorkflowDraft(true) } }, [ diff --git a/web/app/components/workflow/header/view-history.tsx b/web/app/components/workflow/header/view-history.tsx index a28626f1cb..32b004fbc1 100644 --- a/web/app/components/workflow/header/view-history.tsx +++ b/web/app/components/workflow/header/view-history.tsx @@ -129,6 +129,7 @@ const ViewHistory = () => { onClick={() => { workflowStore.setState({ historyWorkflowData: item, + showInputsPanel: false, }) handleBackupDraft() setOpen(false) diff --git a/web/app/components/workflow/hooks/use-workflow-run.ts b/web/app/components/workflow/hooks/use-workflow-run.ts index 76a9a43421..d74c4a7d7c 100644 --- a/web/app/components/workflow/hooks/use-workflow-run.ts +++ b/web/app/components/workflow/hooks/use-workflow-run.ts @@ -86,6 +86,7 @@ export const useWorkflowRun = () => { workflowStore.setState({ workflowRunningData: undefined, historyWorkflowData: undefined, + showInputsPanel: false, }) } else { @@ -155,6 +156,17 @@ export const useWorkflowRun = () => { let prevNodeId = '' + const { + workflowRunningData, + setWorkflowRunningData, + } = workflowStore.getState() + setWorkflowRunningData(produce(workflowRunningData!, (draft) => { + draft.result = { + ...draft?.result, + status: WorkflowRunningStatus.Running, + } + })) + ssePost( url, { diff --git a/web/app/components/workflow/panel/index.tsx b/web/app/components/workflow/panel/index.tsx index b5d35d94eb..a564c504d4 100644 --- a/web/app/components/workflow/panel/index.tsx +++ b/web/app/components/workflow/panel/index.tsx @@ -10,7 +10,6 @@ import { useStore } from '../store' import { useIsChatMode } from '../hooks' import DebugAndPreview from './debug-and-preview' import Record from './record' -import InputsPanel from './inputs-panel' import WorkflowPreview from './workflow-preview' import ChatRecord from './chat-record' import { useStore as useAppStore } from '@/app/components/app/store' @@ -30,11 +29,12 @@ const Panel: FC = () => { showWorkflowPreview, } = useMemo(() => { return { - showNodePanel: !!selectedNode && !workflowRunningData && !historyWorkflowData, + showNodePanel: !!selectedNode && !workflowRunningData && !historyWorkflowData && !showInputsPanel, showDebugAndPreviewPanel: isChatMode && workflowRunningData && !historyWorkflowData, - showWorkflowPreview: !isChatMode && workflowRunningData && !historyWorkflowData, + showWorkflowPreview: !isChatMode && !historyWorkflowData && (workflowRunningData || showInputsPanel), } }, [ + showInputsPanel, selectedNode, isChatMode, workflowRunningData, @@ -71,11 +71,6 @@ const Panel: FC = () => { ) } - { - showInputsPanel && ( - - ) - } { showWorkflowPreview && ( diff --git a/web/app/components/workflow/panel/inputs-panel.tsx b/web/app/components/workflow/panel/inputs-panel.tsx index 69a6c5a04b..c52c406ae6 100644 --- a/web/app/components/workflow/panel/inputs-panel.tsx +++ b/web/app/components/workflow/panel/inputs-panel.tsx @@ -1,6 +1,5 @@ import { memo, - useCallback, useMemo, } from 'react' import { useTranslation } from 'react-i18next' @@ -9,6 +8,7 @@ import FormItem from '../nodes/_base/components/before-run-form/form-item' import { BlockEnum, InputVarType, + WorkflowRunningStatus, } from '../types' import { useStore, @@ -19,13 +19,18 @@ import type { StartNodeType } from '../nodes/start/types' import Button from '@/app/components/base/button' import { useFeatures } from '@/app/components/base/features/hooks' -const InputsPanel = () => { +type Props = { + onRun: () => void +} + +const InputsPanel = ({ onRun }: Props) => { const { t } = useTranslation() const workflowStore = useWorkflowStore() const fileSettings = useFeatures(s => s.features.file) const nodes = useNodes() const inputs = useStore(s => s.inputs) const files = useStore(s => s.files) + const workflowRunningData = useStore(s => s.workflowRunningData) const { handleRun, handleRunSetting, @@ -64,56 +69,42 @@ const InputsPanel = () => { } } - const handleCancel = useCallback(() => { - workflowStore.setState({ showInputsPanel: false }) - }, [workflowStore]) - const doRun = () => { - handleCancel() + onRun() handleRunSetting() handleRun({ inputs, files }) } return ( -
-
-
- {t('workflow.singleRun.testRun')} -
-
- { - variables.map(variable => ( -
- handleValueChange(variable.variable, v)} - /> -
- )) - } -
-
- - -
+ <> +
+ { + variables.map(variable => ( +
+ handleValueChange(variable.variable, v)} + /> +
+ )) + }
-
+
+ +
+ ) } diff --git a/web/app/components/workflow/panel/workflow-preview.tsx b/web/app/components/workflow/panel/workflow-preview.tsx index 661b106704..a772b1e303 100644 --- a/web/app/components/workflow/panel/workflow-preview.tsx +++ b/web/app/components/workflow/panel/workflow-preview.tsx @@ -7,13 +7,20 @@ import { useTranslation } from 'react-i18next' import OutputPanel from '../run/output-panel' import ResultPanel from '../run/result-panel' import TracingPanel from '../run/tracing-panel' -import { useStore } from '../store' +import { useStore, useWorkflowStore } from '../store' +import { + WorkflowRunningStatus, +} from '../types' +import InputsPanel from './inputs-panel' import Loading from '@/app/components/base/loading' +import { XClose } from '@/app/components/base/icons/src/vender/line/general' const WorkflowPreview = () => { const { t } = useTranslation() - const [currentTab, setCurrentTab] = useState('TRACING') + const workflowStore = useWorkflowStore() + const showInputsPanel = useStore(s => s.showInputsPanel) const workflowRunningData = useStore(s => s.workflowRunningData) + const [currentTab, setCurrentTab] = useState(showInputsPanel ? 'INPUT' : 'TRACING') const switchTab = async (tab: string) => { setCurrentTab(tab) @@ -24,44 +31,80 @@ const WorkflowPreview = () => { flex flex-col w-[420px] h-full rounded-2xl border-[0.5px] border-gray-200 shadow-xl bg-white `}>
- Test Run#{workflowRunningData?.result.sequence_number} + {`Test Run${!workflowRunningData?.result.sequence_number ? '' : `#${workflowRunningData?.result.sequence_number}`}`} + {showInputsPanel && workflowRunningData?.result?.status !== WorkflowRunningStatus.Running && ( +
{ + workflowStore.setState({ + showInputsPanel: false, + workflowRunningData: undefined, + }) + }}> + +
+ )}
+ {showInputsPanel && ( +
switchTab('INPUT')} + >{t('runLog.input')}
+ )}
switchTab('RESULT')} + onClick={() => { + if (!workflowRunningData) + return + switchTab('RESULT') + }} >{t('runLog.result')}
switchTab('DETAIL')} + onClick={() => { + if (!workflowRunningData) + return + switchTab('DETAIL') + }} >{t('runLog.detail')}
switchTab('TRACING')} + onClick={() => { + if (!workflowRunningData) + return + switchTab('TRACING') + }} >{t('runLog.tracing')}
-
+
+ {currentTab === 'INPUT' && ( + switchTab('RESULT')} /> + )} {currentTab === 'RESULT' && ( )} - {currentTab === 'RESULT' && !workflowRunningData?.result && ( -
- -
- )} {currentTab === 'DETAIL' && ( = ({ + isRunning, outputs, error, }) => { return (
- {error && ( -
-
{error}
+ {isRunning && ( +
+
)} - {!outputs && ( + {!isRunning && error && ( +
+
+
{error}
+
+
+ )} + {!isRunning && !outputs && (
diff --git a/web/i18n/en-US/run-log.ts b/web/i18n/en-US/run-log.ts index 4091bd4a39..d868d7deda 100644 --- a/web/i18n/en-US/run-log.ts +++ b/web/i18n/en-US/run-log.ts @@ -1,4 +1,5 @@ const translation = { + input: 'INPUT', result: 'RESULT', detail: 'DETAIL', tracing: 'TRACING', diff --git a/web/i18n/zh-Hans/run-log.ts b/web/i18n/zh-Hans/run-log.ts index d5a3202657..c3d3aec9fe 100644 --- a/web/i18n/zh-Hans/run-log.ts +++ b/web/i18n/zh-Hans/run-log.ts @@ -1,4 +1,5 @@ const translation = { + input: '输入', result: '结果', detail: '详情', tracing: '追踪',