Commit 261e56e6 authored by StyleZhang's avatar StyleZhang

single run

parent ede0bb53
...@@ -18,7 +18,6 @@ import { ...@@ -18,7 +18,6 @@ import {
import type { import type {
BlockEnum, BlockEnum,
Node, Node,
SelectedNode,
} from './types' } from './types'
import { NODES_INITIAL_DATA } from './constants' import { NODES_INITIAL_DATA } from './constants'
import { getLayoutByDagre } from './utils' import { getLayoutByDagre } from './utils'
...@@ -258,7 +257,7 @@ export const useWorkflow = () => { ...@@ -258,7 +257,7 @@ export const useWorkflow = () => {
setEdges(newEdges) setEdges(newEdges)
}, [store]) }, [store])
const handleNodeDataUpdate = useCallback(({ id, data }: SelectedNode) => { const handleNodeDataUpdate = useCallback(({ id, data }: { id: string; data: Record<string, any> }) => {
const { const {
getNodes, getNodes,
setNodes, setNodes,
......
import type { FC } from 'react' import type { FC } from 'react'
import { memo } from 'react' import { memo } from 'react'
import { useWorkflow } from '../../../hooks'
import { import {
DotsHorizontal, DotsHorizontal,
Loading02, Loading02,
...@@ -11,10 +12,14 @@ import { ...@@ -11,10 +12,14 @@ import {
type NodeControlProps = { type NodeControlProps = {
isRunning?: boolean isRunning?: boolean
nodeId: string
} }
const NodeControl: FC<NodeControlProps> = ({ const NodeControl: FC<NodeControlProps> = ({
isRunning, isRunning,
nodeId,
}) => { }) => {
const { handleNodeDataUpdate } = useWorkflow()
return ( return (
<div className='absolute right-0 -top-7 flex items-center px-0.5 h-6 bg-white rounded-lg border-[0.5px] border-gray-100 shadow-xs text-gray-500'> <div className='absolute right-0 -top-7 flex items-center px-0.5 h-6 bg-white rounded-lg border-[0.5px] border-gray-100 shadow-xs text-gray-500'>
{ {
...@@ -25,7 +30,15 @@ const NodeControl: FC<NodeControlProps> = ({ ...@@ -25,7 +30,15 @@ const NodeControl: FC<NodeControlProps> = ({
</div> </div>
) )
} }
<div className='flex items-center justify-center w-5 h-5 cursor-pointer'> <div
className='flex items-center justify-center w-5 h-5 cursor-pointer'
onClick={() => {
handleNodeDataUpdate({
id: nodeId,
data: { _isSingleRun: !isRunning },
})
}}
>
{ {
isRunning isRunning
? <Stop className='w-3 h-3' /> ? <Stop className='w-3 h-3' />
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
cloneElement, cloneElement,
memo, memo,
} from 'react' } from 'react'
import type { NodeProps } from 'reactflow' import type { NodeProps } from '../../types'
import BlockIcon from '../../block-icon' import BlockIcon from '../../block-icon'
type BaseNodeProps = { type BaseNodeProps = {
......
...@@ -6,7 +6,6 @@ import { ...@@ -6,7 +6,6 @@ import {
cloneElement, cloneElement,
memo, memo,
useCallback, useCallback,
useState,
} from 'react' } from 'react'
import { type Node } from '../../types' import { type Node } from '../../types'
import { BlockEnum } from '../../types' import { BlockEnum } from '../../types'
...@@ -39,7 +38,6 @@ const BasePanel: FC<BasePanelProps> = ({ ...@@ -39,7 +38,6 @@ const BasePanel: FC<BasePanelProps> = ({
handleNodeSelect, handleNodeSelect,
handleNodeDataUpdate, handleNodeDataUpdate,
} = useWorkflow() } = useWorkflow()
const [controlSingleRun, setControlSingleRun] = useState(0)
const handleTitleChange = useCallback((title: string) => { const handleTitleChange = useCallback((title: string) => {
handleNodeDataUpdate({ id, data: { ...data, title } }) handleNodeDataUpdate({ id, data: { ...data, title } })
}, [handleNodeDataUpdate, id, data]) }, [handleNodeDataUpdate, id, data])
...@@ -68,7 +66,7 @@ const BasePanel: FC<BasePanelProps> = ({ ...@@ -68,7 +66,7 @@ const BasePanel: FC<BasePanelProps> = ({
> >
<div <div
className='flex items-center justify-center mr-1 w-6 h-6 rounded-md hover:bg-black/5 cursor-pointer' className='flex items-center justify-center mr-1 w-6 h-6 rounded-md hover:bg-black/5 cursor-pointer'
onClick={() => !controlSingleRun && setControlSingleRun(Date.now())} onClick={() => handleNodeDataUpdate({ id, data: { _isSingleRun: true } })}
> >
<Play className='w-4 h-4 text-gray-500' /> <Play className='w-4 h-4 text-gray-500' />
</div> </div>
...@@ -93,7 +91,7 @@ const BasePanel: FC<BasePanelProps> = ({ ...@@ -93,7 +91,7 @@ const BasePanel: FC<BasePanelProps> = ({
</div> </div>
</div> </div>
<div className='py-2'> <div className='py-2'>
{cloneElement(children, { id, data, controlSingleRun, setControlSingleRun })} {cloneElement(children, { id, data })}
</div> </div>
{ {
data.type !== BlockEnum.End && ( data.type !== BlockEnum.End && (
......
...@@ -16,6 +16,7 @@ import { ...@@ -16,6 +16,7 @@ import {
import NodeControl from './_base/components/node-control' import NodeControl from './_base/components/node-control'
const CustomNode = memo((props: NodeProps) => { const CustomNode = memo((props: NodeProps) => {
const nodeId = props.id
const nodeData = props.data const nodeData = props.data
const NodeComponent = NodeComponentMap[nodeData.type] const NodeComponent = NodeComponentMap[nodeData.type]
...@@ -43,10 +44,13 @@ const CustomNode = memo((props: NodeProps) => { ...@@ -43,10 +44,13 @@ const CustomNode = memo((props: NodeProps) => {
) )
} }
{ {
nodeData.hovering nodeData._selected
&& canRunBySingle(nodeData.type) && canRunBySingle(nodeData.type)
&& ( && (
<NodeControl /> <NodeControl
nodeId={nodeId}
isRunning={nodeData._isSingleRun}
/>
) )
} }
</> </>
......
...@@ -27,6 +27,7 @@ export type CommonNodeType<T = {}> = { ...@@ -27,6 +27,7 @@ export type CommonNodeType<T = {}> = {
_selected?: boolean _selected?: boolean
_hovering?: boolean _hovering?: boolean
_targetBranches?: Branch[] _targetBranches?: Branch[]
_isSingleRun?: boolean
title: string title: string
desc: string desc: string
type: BlockEnum type: BlockEnum
...@@ -39,12 +40,10 @@ export type CommonEdgeType = { ...@@ -39,12 +40,10 @@ export type CommonEdgeType = {
export type Node = ReactFlowNode<CommonNodeType> export type Node = ReactFlowNode<CommonNodeType>
export type SelectedNode = Pick<Node, 'id' | 'data'> export type SelectedNode = Pick<Node, 'id' | 'data'>
export type NodeProps<T> = { id: string; data: CommonNodeType<T> } export type NodeProps<T = unknown> = { id: string; data: CommonNodeType<T> }
export type NodePanelProps<T> = { export type NodePanelProps<T> = {
id: string id: string
data: CommonNodeType<T> data: CommonNodeType<T>
controlSingleRun: boolean
setControlSingleRun: (value: boolean) => void
} }
export type Edge = ReactFlowEdge<CommonEdgeType> export type Edge = ReactFlowEdge<CommonEdgeType>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment