From 817e16493f282892b5c5d582aa140f73b5b32955 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Fri, 22 Mar 2024 14:57:31 +0800 Subject: [PATCH] checklist --- .../workflow/panel/workflow-info.tsx | 80 ++++++++++++++++--- 1 file changed, 68 insertions(+), 12 deletions(-) diff --git a/web/app/components/workflow/panel/workflow-info.tsx b/web/app/components/workflow/panel/workflow-info.tsx index efb6588097..a4e720a631 100644 --- a/web/app/components/workflow/panel/workflow-info.tsx +++ b/web/app/components/workflow/panel/workflow-info.tsx @@ -1,5 +1,7 @@ -import type { FC } from 'react' -import { memo } from 'react' +import { + memo, + useMemo, +} from 'react' import { useTranslation } from 'react-i18next' import { getIncomers, @@ -8,17 +10,23 @@ import { useNodes, } from 'reactflow' import BlockIcon from '../block-icon' +import { useNodesExtraData } from '../hooks' import type { CommonNodeType } from '../types' +import { BlockEnum } from '../types' +import { useStore } from '../store' import { AlertTriangle } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' import { FileCheck02 } from '@/app/components/base/icons/src/vender/line/files' import { useStore as useAppStore } from '@/app/components/app/store' import AppIcon from '@/app/components/base/app-icon' -const WorkflowInfo: FC = () => { +const WorkflowInfo = () => { const { t } = useTranslation() const appDetail = useAppStore(state => state.appDetail) const nodes = useNodes() const edges = useEdges() + const nodesExtraData = useNodesExtraData() + const buildInTools = useStore(s => s.buildInTools) + const customTools = useStore(s => s.customTools) const needConnectNodes = nodes.filter((node) => { const incomers = getIncomers(node, nodes, edges) const outgoers = getOutgoers(node, nodes, edges) @@ -26,6 +34,39 @@ const WorkflowInfo: FC = () => { return !incomers.length && !outgoers.length }) + const needWarningNodes = useMemo(() => { + const list = [] + + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i] + const incomers = getIncomers(node, nodes, edges) + const outgoers = getOutgoers(node, nodes, edges) + const { errorMessage } = nodesExtraData[node.data.type].checkValid(node.data, t) + let toolIcon + + if (node.data.type === BlockEnum.Tool) { + if (node.data.provider_type === 'builtin') + toolIcon = buildInTools.find(tool => tool.id === node.data.provider_id)?.icon + + if (node.data.provider_type === 'custom') + toolIcon = customTools.find(tool => tool.id === node.data.provider_id)?.icon + } + + if (errorMessage || ((!incomers.length && !outgoers.length))) { + list.push({ + id: node.id, + type: node.data.type, + title: node.data.title, + toolIcon, + unConnected: !incomers.length && !outgoers.length, + errorMessage, + }) + } + } + + return list + }, [t, nodes, edges, nodesExtraData, buildInTools, customTools]) + if (!appDetail) return null @@ -57,24 +98,39 @@ const WorkflowInfo: FC = () => {
{ - needConnectNodes.map(node => ( + needWarningNodes.map(node => (
- {node.data.title} -
-
-
- - {t('workflow.common.needConnecttip')} -
+ {node.title}
+ { + node.unConnected && ( +
+
+ + {t('workflow.common.needConnecttip')} +
+
+ ) + } + { + node.errorMessage && ( +
+
+ + {node.errorMessage} +
+
+ ) + }
)) }