From 16abcf082c8ba0b75ef0480f37b7713c8578f1dc Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Thu, 7 Mar 2024 17:09:04 +0800 Subject: [PATCH] node control --- web/app/components/workflow/hooks.ts | 1 + web/app/components/workflow/index.tsx | 8 +- .../nodes/_base/components/node-control.tsx | 2 +- .../components/workflow/nodes/_base/node.tsx | 110 +++++++++++------- web/app/components/workflow/nodes/index.tsx | 21 +--- web/app/components/workflow/types.ts | 1 - 6 files changed, 72 insertions(+), 71 deletions(-) diff --git a/web/app/components/workflow/hooks.ts b/web/app/components/workflow/hooks.ts index acc1bbba3a..508e043dfe 100644 --- a/web/app/components/workflow/hooks.ts +++ b/web/app/components/workflow/hooks.ts @@ -368,6 +368,7 @@ export const useWorkflow = () => { x: currentNode.position.x, y: currentNode.position.y, }, + targetPosition: Position.Left, } const newNodes = produce(nodes, (draft) => { const index = draft.findIndex(node => node.id === currentNodeId) diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx index 25628c93f2..24dd42172e 100644 --- a/web/app/components/workflow/index.tsx +++ b/web/app/components/workflow/index.tsx @@ -9,8 +9,6 @@ import { useKeyPress } from 'ahooks' import ReactFlow, { Background, ReactFlowProvider, - useEdgesState, - useNodesState, useOnViewportChange, } from 'reactflow' import type { Viewport } from 'reactflow' @@ -56,13 +54,11 @@ type WorkflowProps = { viewport?: Viewport } const Workflow: FC = memo(({ - nodes: initialNodes, - edges: initialEdges, + nodes, + edges, viewport, }) => { const showFeaturesPanel = useStore(state => state.showFeaturesPanel) - const [nodes] = useNodesState(initialNodes) - const [edges] = useEdgesState(initialEdges) const { handleSyncWorkflowDraft, diff --git a/web/app/components/workflow/nodes/_base/components/node-control.tsx b/web/app/components/workflow/nodes/_base/components/node-control.tsx index 3e482388b2..2cbbc76231 100644 --- a/web/app/components/workflow/nodes/_base/components/node-control.tsx +++ b/web/app/components/workflow/nodes/_base/components/node-control.tsx @@ -21,7 +21,7 @@ const NodeControl: FC = ({ const { handleNodeDataUpdate } = useWorkflow() return ( -
+
{ isRunning && (
diff --git a/web/app/components/workflow/nodes/_base/node.tsx b/web/app/components/workflow/nodes/_base/node.tsx index a1767a7f57..2f1391c8d8 100644 --- a/web/app/components/workflow/nodes/_base/node.tsx +++ b/web/app/components/workflow/nodes/_base/node.tsx @@ -8,10 +8,12 @@ import { } from 'react' import type { NodeProps } from '../../types' import { BlockEnum } from '../../types' +import { canRunBySingle } from '../../utils' import { NodeSourceHandle, NodeTargetHandle, } from './components/node-handle' +import NodeControl from './components/node-control' import BlockIcon from '@/app/components/workflow/block-icon' type BaseNodeProps = { @@ -26,55 +28,73 @@ const BaseNode: FC = ({ return (
- { - data.type !== BlockEnum.VariableAssigner && ( - + { + data.type !== BlockEnum.VariableAssigner && ( + + ) + } + { + data.type !== BlockEnum.IfElse && data.type !== BlockEnum.QuestionClassifier && ( + + ) + } + { + canRunBySingle(data.type) + && ( +
+ +
+ ) + } +
+ - ) - } - { - data.type !== BlockEnum.IfElse && data.type !== BlockEnum.QuestionClassifier && ( - - ) - } -
- -
- {data.title} -
-
-
- {cloneElement(children, { id, data })} -
- { - data.desc && ( -
- {data.desc} +
+ {data.title}
- ) - } +
+
+ {cloneElement(children, { id, data })} +
+ { + data.desc && ( +
+ {data.desc} +
+ ) + } +
) } diff --git a/web/app/components/workflow/nodes/index.tsx b/web/app/components/workflow/nodes/index.tsx index e4ee0ffbd6..c123750fb0 100644 --- a/web/app/components/workflow/nodes/index.tsx +++ b/web/app/components/workflow/nodes/index.tsx @@ -1,36 +1,21 @@ import { memo } from 'react' import type { NodeProps } from 'reactflow' import type { Node } from '../types' -import { canRunBySingle } from '../utils' import { NodeComponentMap, PanelComponentMap, } from './constants' import BaseNode from './_base/node' import BasePanel from './_base/panel' -import NodeControl from './_base/components/node-control' const CustomNode = memo((props: NodeProps) => { - const nodeId = props.id const nodeData = props.data const NodeComponent = NodeComponentMap[nodeData.type] return ( - <> - - - - { - nodeData._selected - && canRunBySingle(nodeData.type) - && ( - - ) - } - + + + ) }) CustomNode.displayName = 'CustomNode' diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index ea853070dd..c6d0613d85 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -27,7 +27,6 @@ export type Branch = { export type CommonNodeType = { _selected?: boolean - _hovering?: boolean _targetBranches?: Branch[] _isSingleRun?: boolean _icon?: Collection['icon']