Merge branch 'main' into feat/workflow-add-block-shortcut
This commit is contained in:
commit
071b7d607b
@ -1027,7 +1027,7 @@ export const useNodesInteractions = () => {
|
|||||||
handleNodeSelect(node.id)
|
handleNodeSelect(node.id)
|
||||||
}, [workflowStore, handleNodeSelect])
|
}, [workflowStore, handleNodeSelect])
|
||||||
|
|
||||||
const handleNodesCopy = useCallback(() => {
|
const handleNodesCopy = useCallback((nodeId?: string) => {
|
||||||
if (getNodesReadOnly())
|
if (getNodesReadOnly())
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1038,17 +1038,27 @@ export const useNodesInteractions = () => {
|
|||||||
} = store.getState()
|
} = store.getState()
|
||||||
|
|
||||||
const nodes = getNodes()
|
const nodes = getNodes()
|
||||||
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start && !node.data.isInIteration)
|
|
||||||
|
|
||||||
if (bundledNodes.length) {
|
if (nodeId) {
|
||||||
setClipboardElements(bundledNodes)
|
// If nodeId is provided, copy that specific node
|
||||||
return
|
const nodeToCopy = nodes.find(node => node.id === nodeId && node.data.type !== BlockEnum.Start)
|
||||||
|
if (nodeToCopy)
|
||||||
|
setClipboardElements([nodeToCopy])
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// If no nodeId is provided, fall back to the current behavior
|
||||||
|
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start && !node.data.isInIteration)
|
||||||
|
|
||||||
const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)
|
if (bundledNodes.length) {
|
||||||
|
setClipboardElements(bundledNodes)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedNode)
|
const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)
|
||||||
setClipboardElements([selectedNode])
|
|
||||||
|
if (selectedNode)
|
||||||
|
setClipboardElements([selectedNode])
|
||||||
|
}
|
||||||
}, [getNodesReadOnly, store, workflowStore])
|
}, [getNodesReadOnly, store, workflowStore])
|
||||||
|
|
||||||
const handleNodesPaste = useCallback(() => {
|
const handleNodesPaste = useCallback(() => {
|
||||||
@ -1128,11 +1138,11 @@ export const useNodesInteractions = () => {
|
|||||||
}
|
}
|
||||||
}, [getNodesReadOnly, workflowStore, store, reactflow, saveStateToHistory, handleSyncWorkflowDraft, handleNodeIterationChildrenCopy])
|
}, [getNodesReadOnly, workflowStore, store, reactflow, saveStateToHistory, handleSyncWorkflowDraft, handleNodeIterationChildrenCopy])
|
||||||
|
|
||||||
const handleNodesDuplicate = useCallback(() => {
|
const handleNodesDuplicate = useCallback((nodeId?: string) => {
|
||||||
if (getNodesReadOnly())
|
if (getNodesReadOnly())
|
||||||
return
|
return
|
||||||
|
|
||||||
handleNodesCopy()
|
handleNodesCopy(nodeId)
|
||||||
handleNodesPaste()
|
handleNodesPaste()
|
||||||
}, [getNodesReadOnly, handleNodesCopy, handleNodesPaste])
|
}, [getNodesReadOnly, handleNodesCopy, handleNodesPaste])
|
||||||
|
|
||||||
|
@ -37,12 +37,25 @@ export const useShortcuts = (): void => {
|
|||||||
const { handleLayout } = useWorkflowOrganize()
|
const { handleLayout } = useWorkflowOrganize()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
zoomIn,
|
|
||||||
zoomOut,
|
|
||||||
zoomTo,
|
zoomTo,
|
||||||
|
getZoom,
|
||||||
fitView,
|
fitView,
|
||||||
} = useReactFlow()
|
} = useReactFlow()
|
||||||
|
|
||||||
|
// Zoom out to a minimum of 0.5 for shortcut
|
||||||
|
const constrainedZoomOut = () => {
|
||||||
|
const currentZoom = getZoom()
|
||||||
|
const newZoom = Math.max(currentZoom - 0.1, 0.5)
|
||||||
|
zoomTo(newZoom)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zoom in to a maximum of 1 for shortcut
|
||||||
|
const constrainedZoomIn = () => {
|
||||||
|
const currentZoom = getZoom()
|
||||||
|
const newZoom = Math.min(currentZoom + 0.1, 1)
|
||||||
|
zoomTo(newZoom)
|
||||||
|
}
|
||||||
|
|
||||||
const shouldHandleShortcut = useCallback((e: KeyboardEvent) => {
|
const shouldHandleShortcut = useCallback((e: KeyboardEvent) => {
|
||||||
const { showFeaturesPanel } = workflowStore.getState()
|
const { showFeaturesPanel } = workflowStore.getState()
|
||||||
return !showFeaturesPanel && !isEventTargetInputArea(e.target as HTMLElement)
|
return !showFeaturesPanel && !isEventTargetInputArea(e.target as HTMLElement)
|
||||||
@ -170,7 +183,7 @@ export const useShortcuts = (): void => {
|
|||||||
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.dash`, (e) => {
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.dash`, (e) => {
|
||||||
if (shouldHandleShortcut(e)) {
|
if (shouldHandleShortcut(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
zoomOut()
|
constrainedZoomOut()
|
||||||
handleSyncWorkflowDraft()
|
handleSyncWorkflowDraft()
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@ -181,7 +194,7 @@ export const useShortcuts = (): void => {
|
|||||||
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.equalsign`, (e) => {
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.equalsign`, (e) => {
|
||||||
if (shouldHandleShortcut(e)) {
|
if (shouldHandleShortcut(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
zoomIn()
|
constrainedZoomIn()
|
||||||
handleSyncWorkflowDraft()
|
handleSyncWorkflowDraft()
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useClickAway } from 'ahooks'
|
import { useClickAway } from 'ahooks'
|
||||||
@ -9,13 +10,18 @@ import type { Node } from './types'
|
|||||||
import { useStore } from './store'
|
import { useStore } from './store'
|
||||||
import { usePanelInteractions } from './hooks'
|
import { usePanelInteractions } from './hooks'
|
||||||
|
|
||||||
const PanelContextmenu = () => {
|
const NodeContextmenu = () => {
|
||||||
const ref = useRef(null)
|
const ref = useRef(null)
|
||||||
const nodes = useNodes()
|
const nodes = useNodes()
|
||||||
const { handleNodeContextmenuCancel } = usePanelInteractions()
|
const { handleNodeContextmenuCancel, handlePaneContextmenuCancel } = usePanelInteractions()
|
||||||
const nodeMenu = useStore(s => s.nodeMenu)
|
const nodeMenu = useStore(s => s.nodeMenu)
|
||||||
const currentNode = nodes.find(node => node.id === nodeMenu?.nodeId) as Node
|
const currentNode = nodes.find(node => node.id === nodeMenu?.nodeId) as Node
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (nodeMenu)
|
||||||
|
handlePaneContextmenuCancel()
|
||||||
|
}, [nodeMenu, handlePaneContextmenuCancel])
|
||||||
|
|
||||||
useClickAway(() => {
|
useClickAway(() => {
|
||||||
handleNodeContextmenuCancel()
|
handleNodeContextmenuCancel()
|
||||||
}, ref)
|
}, ref)
|
||||||
@ -42,4 +48,4 @@ const PanelContextmenu = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo(PanelContextmenu)
|
export default memo(NodeContextmenu)
|
||||||
|
@ -138,7 +138,7 @@ const PanelOperatorPopup = ({
|
|||||||
className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50'
|
className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onClosePopup()
|
onClosePopup()
|
||||||
handleNodesDuplicate()
|
handleNodesDuplicate(id)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('workflow.common.duplicate')}
|
{t('workflow.common.duplicate')}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
|
useEffect,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -23,11 +24,16 @@ const PanelContextmenu = () => {
|
|||||||
const clipboardElements = useStore(s => s.clipboardElements)
|
const clipboardElements = useStore(s => s.clipboardElements)
|
||||||
const setShowImportDSLModal = useStore(s => s.setShowImportDSLModal)
|
const setShowImportDSLModal = useStore(s => s.setShowImportDSLModal)
|
||||||
const { handleNodesPaste } = useNodesInteractions()
|
const { handleNodesPaste } = useNodesInteractions()
|
||||||
const { handlePaneContextmenuCancel } = usePanelInteractions()
|
const { handlePaneContextmenuCancel, handleNodeContextmenuCancel } = usePanelInteractions()
|
||||||
const { handleStartWorkflowRun } = useWorkflowStartRun()
|
const { handleStartWorkflowRun } = useWorkflowStartRun()
|
||||||
const { handleAddNote } = useOperator()
|
const { handleAddNote } = useOperator()
|
||||||
const { exportCheck } = useDSL()
|
const { exportCheck } = useDSL()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (panelMenu)
|
||||||
|
handleNodeContextmenuCancel()
|
||||||
|
}, [panelMenu, handleNodeContextmenuCancel])
|
||||||
|
|
||||||
useClickAway(() => {
|
useClickAway(() => {
|
||||||
handlePaneContextmenuCancel()
|
handlePaneContextmenuCancel()
|
||||||
}, ref)
|
}, ref)
|
||||||
|
Loading…
Reference in New Issue
Block a user