From 261e56e61d6641c6e888403b38eb79573d8b0e2f Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Tue, 5 Mar 2024 15:57:10 +0800 Subject: [PATCH] single run --- web/app/components/workflow/hooks.ts | 3 +-- .../nodes/_base/components/node-control.tsx | 15 ++++++++++++++- web/app/components/workflow/nodes/_base/node.tsx | 2 +- web/app/components/workflow/nodes/_base/panel.tsx | 6 ++---- web/app/components/workflow/nodes/index.tsx | 8 ++++++-- web/app/components/workflow/types.ts | 5 ++--- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/web/app/components/workflow/hooks.ts b/web/app/components/workflow/hooks.ts index b731487453..c2dc37dd14 100644 --- a/web/app/components/workflow/hooks.ts +++ b/web/app/components/workflow/hooks.ts @@ -18,7 +18,6 @@ import { import type { BlockEnum, Node, - SelectedNode, } from './types' import { NODES_INITIAL_DATA } from './constants' import { getLayoutByDagre } from './utils' @@ -258,7 +257,7 @@ export const useWorkflow = () => { setEdges(newEdges) }, [store]) - const handleNodeDataUpdate = useCallback(({ id, data }: SelectedNode) => { + const handleNodeDataUpdate = useCallback(({ id, data }: { id: string; data: Record }) => { const { getNodes, setNodes, 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 6f4dcd42b3..65da955ab7 100644 --- a/web/app/components/workflow/nodes/_base/components/node-control.tsx +++ b/web/app/components/workflow/nodes/_base/components/node-control.tsx @@ -1,5 +1,6 @@ import type { FC } from 'react' import { memo } from 'react' +import { useWorkflow } from '../../../hooks' import { DotsHorizontal, Loading02, @@ -11,10 +12,14 @@ import { type NodeControlProps = { isRunning?: boolean + nodeId: string } const NodeControl: FC = ({ isRunning, + nodeId, }) => { + const { handleNodeDataUpdate } = useWorkflow() + return (
{ @@ -25,7 +30,15 @@ const NodeControl: FC = ({
) } -
+
{ + handleNodeDataUpdate({ + id: nodeId, + data: { _isSingleRun: !isRunning }, + }) + }} + > { isRunning ? diff --git a/web/app/components/workflow/nodes/_base/node.tsx b/web/app/components/workflow/nodes/_base/node.tsx index 27f4f78d20..f0ceaf919a 100644 --- a/web/app/components/workflow/nodes/_base/node.tsx +++ b/web/app/components/workflow/nodes/_base/node.tsx @@ -6,7 +6,7 @@ import { cloneElement, memo, } from 'react' -import type { NodeProps } from 'reactflow' +import type { NodeProps } from '../../types' import BlockIcon from '../../block-icon' type BaseNodeProps = { diff --git a/web/app/components/workflow/nodes/_base/panel.tsx b/web/app/components/workflow/nodes/_base/panel.tsx index 1fb250ab3a..9a5e165995 100644 --- a/web/app/components/workflow/nodes/_base/panel.tsx +++ b/web/app/components/workflow/nodes/_base/panel.tsx @@ -6,7 +6,6 @@ import { cloneElement, memo, useCallback, - useState, } from 'react' import { type Node } from '../../types' import { BlockEnum } from '../../types' @@ -39,7 +38,6 @@ const BasePanel: FC = ({ handleNodeSelect, handleNodeDataUpdate, } = useWorkflow() - const [controlSingleRun, setControlSingleRun] = useState(0) const handleTitleChange = useCallback((title: string) => { handleNodeDataUpdate({ id, data: { ...data, title } }) }, [handleNodeDataUpdate, id, data]) @@ -68,7 +66,7 @@ const BasePanel: FC = ({ >
!controlSingleRun && setControlSingleRun(Date.now())} + onClick={() => handleNodeDataUpdate({ id, data: { _isSingleRun: true } })} >
@@ -93,7 +91,7 @@ const BasePanel: FC = ({
- {cloneElement(children, { id, data, controlSingleRun, setControlSingleRun })} + {cloneElement(children, { id, data })}
{ data.type !== BlockEnum.End && ( diff --git a/web/app/components/workflow/nodes/index.tsx b/web/app/components/workflow/nodes/index.tsx index dcec137ee2..162dac863a 100644 --- a/web/app/components/workflow/nodes/index.tsx +++ b/web/app/components/workflow/nodes/index.tsx @@ -16,6 +16,7 @@ import { 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] @@ -43,10 +44,13 @@ const CustomNode = memo((props: NodeProps) => { ) } { - nodeData.hovering + nodeData._selected && canRunBySingle(nodeData.type) && ( - + ) } diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 9b0dcbcefd..fcbaf782de 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -27,6 +27,7 @@ export type CommonNodeType = { _selected?: boolean _hovering?: boolean _targetBranches?: Branch[] + _isSingleRun?: boolean title: string desc: string type: BlockEnum @@ -39,12 +40,10 @@ export type CommonEdgeType = { export type Node = ReactFlowNode export type SelectedNode = Pick -export type NodeProps = { id: string; data: CommonNodeType } +export type NodeProps = { id: string; data: CommonNodeType } export type NodePanelProps = { id: string data: CommonNodeType - controlSingleRun: boolean - setControlSingleRun: (value: boolean) => void } export type Edge = ReactFlowEdge