From 92ec7ae10df7c3112d0b1e804ccc679139e5fcab Mon Sep 17 00:00:00 2001 From: Nov1c444 <857526207@qq.com> Date: Fri, 1 Nov 2024 15:43:10 +0800 Subject: [PATCH] chore: change the parallel warning show logic --- .../workflow/hooks/use-nodes-interactions.ts | 6 ++-- .../workflow/nodes/iteration/default.ts | 34 ++++++++++++++----- .../workflow/nodes/iteration/node.tsx | 4 +-- .../workflow/nodes/iteration/types.ts | 3 +- web/app/components/workflow/run/node.tsx | 6 +++- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/web/app/components/workflow/hooks/use-nodes-interactions.ts b/web/app/components/workflow/hooks/use-nodes-interactions.ts index 7e53592f2c..375a269377 100644 --- a/web/app/components/workflow/hooks/use-nodes-interactions.ts +++ b/web/app/components/workflow/hooks/use-nodes-interactions.ts @@ -644,10 +644,10 @@ export const useNodesInteractions = () => { newNode.data.isInIteration = true newNode.data.iteration_id = prevNode.parentId newNode.zIndex = ITERATION_CHILDREN_Z_INDEX - if (newNode.data.type === BlockEnum.Answer) { + if (newNode.data.type === BlockEnum.Answer || newNode.data.type === BlockEnum.Tool || newNode.data.type === BlockEnum.Assigner) { const parentIterNodeIndex = nodes.findIndex(node => node.id === prevNode.parentId) - if (nodes[parentIterNodeIndex].data._isFirstTime) - nodes[parentIterNodeIndex].data._isShowTips = true + const iterNodeData: IterationNodeType = nodes[parentIterNodeIndex].data + iterNodeData._isShowTips = true } } diff --git a/web/app/components/workflow/nodes/iteration/default.ts b/web/app/components/workflow/nodes/iteration/default.ts index 82845e2049..cdef268adb 100644 --- a/web/app/components/workflow/nodes/iteration/default.ts +++ b/web/app/components/workflow/nodes/iteration/default.ts @@ -1,7 +1,10 @@ import { BlockEnum, ErrorHandleMode } from '../../types' import type { NodeDefault } from '../../types' import type { IterationNodeType } from './types' -import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants' +import { + ALL_CHAT_AVAILABLE_BLOCKS, + ALL_COMPLETION_AVAILABLE_BLOCKS, +} from '@/app/components/workflow/constants' const i18nPrefix = 'workflow' const nodeDefault: NodeDefault = { @@ -10,7 +13,6 @@ const nodeDefault: NodeDefault = { iterator_selector: [], output_selector: [], _children: [], - _isFirstTime: true, _isShowTips: false, is_parallel: false, parallel_nums: 10, @@ -19,21 +21,37 @@ const nodeDefault: NodeDefault = { getAvailablePrevNodes(isChatMode: boolean) { const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS - : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End) + : ALL_COMPLETION_AVAILABLE_BLOCKS.filter( + type => type !== BlockEnum.End, + ) return nodes }, getAvailableNextNodes(isChatMode: boolean) { - const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS + const nodes = isChatMode + ? ALL_CHAT_AVAILABLE_BLOCKS + : ALL_COMPLETION_AVAILABLE_BLOCKS return nodes }, checkValid(payload: IterationNodeType, t: any) { let errorMessages = '' - if (!errorMessages && (!payload.iterator_selector || payload.iterator_selector.length === 0)) - errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.iteration.input`) }) + if ( + !errorMessages + && (!payload.iterator_selector || payload.iterator_selector.length === 0) + ) { + errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { + field: t(`${i18nPrefix}.nodes.iteration.input`), + }) + } - if (!errorMessages && (!payload.output_selector || payload.output_selector.length === 0)) - errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { field: t(`${i18nPrefix}.nodes.iteration.output`) }) + if ( + !errorMessages + && (!payload.output_selector || payload.output_selector.length === 0) + ) { + errorMessages = t(`${i18nPrefix}.errorMsg.fieldRequired`, { + field: t(`${i18nPrefix}.nodes.iteration.output`), + }) + } return { isValid: !errorMessages, diff --git a/web/app/components/workflow/nodes/iteration/node.tsx b/web/app/components/workflow/nodes/iteration/node.tsx index 05b2fe15b3..fda033b87a 100644 --- a/web/app/components/workflow/nodes/iteration/node.tsx +++ b/web/app/components/workflow/nodes/iteration/node.tsx @@ -31,13 +31,13 @@ const Node: FC> = ({ useEffect(() => { if (nodesInitialized) handleNodeIterationRerender(id) - if (data.is_parallel && data._isShowTips && data._isFirstTime) { + if (data.is_parallel && data._isShowTips) { Toast.notify({ type: 'warning', message: t(`${i18nPrefix}.answerNodeWarningDesc`), duration: 5000, }) - data._isFirstTime = false + data._isShowTips = false } }, [nodesInitialized, id, handleNodeIterationRerender, data, t]) diff --git a/web/app/components/workflow/nodes/iteration/types.ts b/web/app/components/workflow/nodes/iteration/types.ts index a35d56c2f0..4a20dbd456 100644 --- a/web/app/components/workflow/nodes/iteration/types.ts +++ b/web/app/components/workflow/nodes/iteration/types.ts @@ -16,6 +16,5 @@ export type IterationNodeType = CommonNodeType & { is_parallel: boolean // open the parallel mode or not parallel_nums: number // the numbers of parallel error_handle_mode: ErrorHandleMode // how to handle error in the iteration - _isShowTips?: boolean // when answer node in parallel mode iteration show tips - _isFirstTime?: boolean // is the first time to add parallel iteration node + _isShowTips: boolean // when answer node in parallel mode iteration show tips } diff --git a/web/app/components/workflow/run/node.tsx b/web/app/components/workflow/run/node.tsx index 7d1a731545..f77b1aca3a 100644 --- a/web/app/components/workflow/run/node.tsx +++ b/web/app/components/workflow/run/node.tsx @@ -76,7 +76,11 @@ const NodePanel: FC = ({ if (!details || details.length === 0) return 0 - return details.flat().filter(item => item.status === 'failed').length + return details.reduce((acc, iteration) => { + if (iteration.some(item => item.status === 'failed')) + acc++ + return acc + }, 0) } useEffect(() => { setCollapseState(!nodeInfo.expand)