Commit b718e66b authored by StyleZhang's avatar StyleZhang

fix: drag stop & click

parent a55a7603
import { useCallback } from 'react' import { useCallback, useRef } from 'react'
import produce from 'immer' import produce from 'immer'
import type { import type {
NodeDragHandler, NodeDragHandler,
...@@ -29,17 +29,17 @@ export const useNodesInteractions = () => { ...@@ -29,17 +29,17 @@ export const useNodesInteractions = () => {
const store = useStoreApi() const store = useStoreApi()
const nodesInitialData = useNodesInitialData() const nodesInitialData = useNodesInitialData()
const { handleSyncWorkflowDraft } = useNodesSyncDraft() const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const dragNodeStartPosition = useRef({ x: 0, y: 0 } as { x: number; y: number })
const handleNodeDragStart = useCallback<NodeDragHandler>(() => { const handleNodeDragStart = useCallback<NodeDragHandler>((_, node) => {
const { const {
runningStatus, runningStatus,
setIsDragging,
} = useStore.getState() } = useStore.getState()
if (runningStatus) if (runningStatus)
return return
setIsDragging(true) dragNodeStartPosition.current = { x: node.position.x, y: node.position.y }
}, []) }, [])
const handleNodeDrag = useCallback<NodeDragHandler>((e, node: Node) => { const handleNodeDrag = useCallback<NodeDragHandler>((e, node: Node) => {
...@@ -147,10 +147,9 @@ export const useNodesInteractions = () => { ...@@ -147,10 +147,9 @@ export const useNodesInteractions = () => {
setNodes(newNodes) setNodes(newNodes)
}, [store]) }, [store])
const handleNodeDragStop = useCallback<NodeDragHandler>(() => { const handleNodeDragStop = useCallback<NodeDragHandler>((_, node) => {
const { const {
runningStatus, runningStatus,
setIsDragging,
setHelpLineHorizontal, setHelpLineHorizontal,
setHelpLineVertical, setHelpLineVertical,
} = useStore.getState() } = useStore.getState()
...@@ -158,10 +157,12 @@ export const useNodesInteractions = () => { ...@@ -158,10 +157,12 @@ export const useNodesInteractions = () => {
if (runningStatus) if (runningStatus)
return return
setIsDragging(false) const { x, y } = dragNodeStartPosition.current
setHelpLineHorizontal() if (!(x === node.position.x && y === node.position.y)) {
setHelpLineVertical() setHelpLineHorizontal()
handleSyncWorkflowDraft() setHelpLineVertical()
handleSyncWorkflowDraft()
}
}, [handleSyncWorkflowDraft]) }, [handleSyncWorkflowDraft])
const handleNodeEnter = useCallback<NodeMouseHandler>((_, node) => { const handleNodeEnter = useCallback<NodeMouseHandler>((_, node) => {
...@@ -236,10 +237,9 @@ export const useNodesInteractions = () => { ...@@ -236,10 +237,9 @@ export const useNodesInteractions = () => {
const handleNodeClick = useCallback<NodeMouseHandler>((_, node) => { const handleNodeClick = useCallback<NodeMouseHandler>((_, node) => {
const { const {
runningStatus, runningStatus,
isDragging,
} = useStore.getState() } = useStore.getState()
if (runningStatus || isDragging) if (runningStatus)
return return
handleNodeSelect(node.id) handleNodeSelect(node.id)
......
...@@ -18,7 +18,6 @@ type State = { ...@@ -18,7 +18,6 @@ type State = {
workflowRunId: string workflowRunId: string
showRunHistory: boolean showRunHistory: boolean
showFeaturesPanel: boolean showFeaturesPanel: boolean
isDragging: boolean
helpLineHorizontal?: HelpLineHorizontalPosition helpLineHorizontal?: HelpLineHorizontalPosition
helpLineVertical?: HelpLineVerticalPosition helpLineVertical?: HelpLineVerticalPosition
toolsets: CollectionWithExpanded[] toolsets: CollectionWithExpanded[]
...@@ -37,7 +36,6 @@ type Action = { ...@@ -37,7 +36,6 @@ type Action = {
setWorkflowRunId: (workflowRunId: string) => void setWorkflowRunId: (workflowRunId: string) => void
setShowRunHistory: (showRunHistory: boolean) => void setShowRunHistory: (showRunHistory: boolean) => void
setShowFeaturesPanel: (showFeaturesPanel: boolean) => void setShowFeaturesPanel: (showFeaturesPanel: boolean) => void
setIsDragging: (isDragging: boolean) => void
setHelpLineHorizontal: (helpLineHorizontal?: HelpLineHorizontalPosition) => void setHelpLineHorizontal: (helpLineHorizontal?: HelpLineHorizontalPosition) => void
setHelpLineVertical: (helpLineVertical?: HelpLineVerticalPosition) => void setHelpLineVertical: (helpLineVertical?: HelpLineVerticalPosition) => void
setToolsets: (toolsets: CollectionWithExpanded[]) => void setToolsets: (toolsets: CollectionWithExpanded[]) => void
...@@ -62,8 +60,6 @@ export const useStore = create<State & Action>(set => ({ ...@@ -62,8 +60,6 @@ export const useStore = create<State & Action>(set => ({
setShowRunHistory: showRunHistory => set(() => ({ showRunHistory })), setShowRunHistory: showRunHistory => set(() => ({ showRunHistory })),
showFeaturesPanel: false, showFeaturesPanel: false,
setShowFeaturesPanel: showFeaturesPanel => set(() => ({ showFeaturesPanel })), setShowFeaturesPanel: showFeaturesPanel => set(() => ({ showFeaturesPanel })),
isDragging: false,
setIsDragging: isDragging => set(() => ({ isDragging })),
helpLineHorizontal: undefined, helpLineHorizontal: undefined,
setHelpLineHorizontal: helpLineHorizontal => set(() => ({ helpLineHorizontal })), setHelpLineHorizontal: helpLineHorizontal => set(() => ({ helpLineHorizontal })),
helpLineVertical: undefined, helpLineVertical: undefined,
......
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