mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 11:25:55 +08:00
fix: workflow add next node from knowledge retrieval node (#4467)
This commit is contained in:
parent
0ac5d621b6
commit
de3a7603ac
@ -466,8 +466,7 @@ export const useNodesInteractions = () => {
|
|||||||
const prevNode = nodes[prevNodeIndex]
|
const prevNode = nodes[prevNodeIndex]
|
||||||
const outgoers = getOutgoers(prevNode, nodes, edges).sort((a, b) => a.position.y - b.position.y)
|
const outgoers = getOutgoers(prevNode, nodes, edges).sort((a, b) => a.position.y - b.position.y)
|
||||||
const lastOutgoer = outgoers[outgoers.length - 1]
|
const lastOutgoer = outgoers[outgoers.length - 1]
|
||||||
if (prevNode.data.type === BlockEnum.KnowledgeRetrieval)
|
|
||||||
targetHandle = prevNodeId
|
|
||||||
newNode.data._connectedTargetHandleIds = [targetHandle]
|
newNode.data._connectedTargetHandleIds = [targetHandle]
|
||||||
newNode.data._connectedSourceHandleIds = []
|
newNode.data._connectedSourceHandleIds = []
|
||||||
newNode.position = {
|
newNode.position = {
|
||||||
@ -593,8 +592,7 @@ export const useNodesInteractions = () => {
|
|||||||
if (prevNodeId && nextNodeId) {
|
if (prevNodeId && nextNodeId) {
|
||||||
const prevNode = nodes.find(node => node.id === prevNodeId)!
|
const prevNode = nodes.find(node => node.id === prevNodeId)!
|
||||||
const nextNode = nodes.find(node => node.id === nextNodeId)!
|
const nextNode = nodes.find(node => node.id === nextNodeId)!
|
||||||
if (prevNode.data.type === BlockEnum.KnowledgeRetrieval)
|
|
||||||
targetHandle = prevNodeId
|
|
||||||
newNode.data._connectedTargetHandleIds = [targetHandle]
|
newNode.data._connectedTargetHandleIds = [targetHandle]
|
||||||
newNode.data._connectedSourceHandleIds = [sourceHandle]
|
newNode.data._connectedSourceHandleIds = [sourceHandle]
|
||||||
newNode.position = {
|
newNode.position = {
|
||||||
@ -925,10 +923,6 @@ export const useNodesInteractions = () => {
|
|||||||
edges,
|
edges,
|
||||||
} = store.getState()
|
} = store.getState()
|
||||||
|
|
||||||
const edgeSelected = edges.some(edge => edge.selected)
|
|
||||||
if (edgeSelected)
|
|
||||||
return
|
|
||||||
|
|
||||||
const nodes = getNodes()
|
const nodes = getNodes()
|
||||||
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start)
|
const bundledNodes = nodes.filter(node => node.data._isBundled && node.data.type !== BlockEnum.Start)
|
||||||
|
|
||||||
@ -937,6 +931,10 @@ export const useNodesInteractions = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const edgeSelected = edges.some(edge => edge.selected)
|
||||||
|
if (edgeSelected)
|
||||||
|
return
|
||||||
|
|
||||||
const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)
|
const selectedNode = nodes.find(node => node.data.selected && node.data.type !== BlockEnum.Start)
|
||||||
|
|
||||||
if (selectedNode)
|
if (selectedNode)
|
||||||
|
@ -101,9 +101,40 @@ export const useSelectionInteractions = () => {
|
|||||||
setNodes(newNodes)
|
setNodes(newNodes)
|
||||||
}, [store, workflowStore])
|
}, [store, workflowStore])
|
||||||
|
|
||||||
|
const handleSelectionCancel = useCallback(() => {
|
||||||
|
const {
|
||||||
|
getNodes,
|
||||||
|
setNodes,
|
||||||
|
edges,
|
||||||
|
setEdges,
|
||||||
|
} = store.getState()
|
||||||
|
|
||||||
|
store.setState({
|
||||||
|
userSelectionRect: null,
|
||||||
|
userSelectionActive: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
const nodes = getNodes()
|
||||||
|
const newNodes = produce(nodes, (draft) => {
|
||||||
|
draft.forEach((node) => {
|
||||||
|
if (node.data._isBundled)
|
||||||
|
node.data._isBundled = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
setNodes(newNodes)
|
||||||
|
const newEdges = produce(edges, (draft) => {
|
||||||
|
draft.forEach((edge) => {
|
||||||
|
if (edge.data._isBundled)
|
||||||
|
edge.data._isBundled = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
setEdges(newEdges)
|
||||||
|
}, [store])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleSelectionStart,
|
handleSelectionStart,
|
||||||
handleSelectionChange,
|
handleSelectionChange,
|
||||||
handleSelectionDrag,
|
handleSelectionDrag,
|
||||||
|
handleSelectionCancel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import { memo } from 'react'
|
import { memo, useCallback } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
|
import { useKeyPress } from 'ahooks'
|
||||||
import {
|
import {
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
|
useSelectionInteractions,
|
||||||
useWorkflow,
|
useWorkflow,
|
||||||
} from '../hooks'
|
} from '../hooks'
|
||||||
|
import { isEventTargetInputArea } from '../utils'
|
||||||
import { useStore } from '../store'
|
import { useStore } from '../store'
|
||||||
import AddBlock from './add-block'
|
import AddBlock from './add-block'
|
||||||
import TipPopup from './tip-popup'
|
import TipPopup from './tip-popup'
|
||||||
@ -27,6 +30,44 @@ const Control = () => {
|
|||||||
nodesReadOnly,
|
nodesReadOnly,
|
||||||
getNodesReadOnly,
|
getNodesReadOnly,
|
||||||
} = useNodesReadOnly()
|
} = useNodesReadOnly()
|
||||||
|
const { handleSelectionCancel } = useSelectionInteractions()
|
||||||
|
|
||||||
|
const handleModePointer = useCallback(() => {
|
||||||
|
if (getNodesReadOnly())
|
||||||
|
return
|
||||||
|
setControlMode('pointer')
|
||||||
|
}, [getNodesReadOnly, setControlMode])
|
||||||
|
const handleModeHand = useCallback(() => {
|
||||||
|
if (getNodesReadOnly())
|
||||||
|
return
|
||||||
|
setControlMode('hand')
|
||||||
|
handleSelectionCancel()
|
||||||
|
}, [getNodesReadOnly, setControlMode, handleSelectionCancel])
|
||||||
|
|
||||||
|
useKeyPress('h', (e) => {
|
||||||
|
if (getNodesReadOnly())
|
||||||
|
return
|
||||||
|
|
||||||
|
if (isEventTargetInputArea(e.target as HTMLElement))
|
||||||
|
return
|
||||||
|
|
||||||
|
e.preventDefault()
|
||||||
|
handleModeHand()
|
||||||
|
}, {
|
||||||
|
exactMatch: true,
|
||||||
|
useCapture: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
useKeyPress('v', (e) => {
|
||||||
|
if (isEventTargetInputArea(e.target as HTMLElement))
|
||||||
|
return
|
||||||
|
|
||||||
|
e.preventDefault()
|
||||||
|
handleModePointer()
|
||||||
|
}, {
|
||||||
|
exactMatch: true,
|
||||||
|
useCapture: true,
|
||||||
|
})
|
||||||
|
|
||||||
const goLayout = () => {
|
const goLayout = () => {
|
||||||
if (getNodesReadOnly())
|
if (getNodesReadOnly())
|
||||||
@ -45,7 +86,7 @@ const Control = () => {
|
|||||||
controlMode === 'pointer' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
|
controlMode === 'pointer' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
|
||||||
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
||||||
)}
|
)}
|
||||||
onClick={() => setControlMode('pointer')}
|
onClick={handleModePointer}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
controlMode === 'pointer' ? <Cursor02CSolid className='w-4 h-4' /> : <Cursor02C className='w-4 h-4' />
|
controlMode === 'pointer' ? <Cursor02CSolid className='w-4 h-4' /> : <Cursor02C className='w-4 h-4' />
|
||||||
@ -59,7 +100,7 @@ const Control = () => {
|
|||||||
controlMode === 'hand' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
|
controlMode === 'hand' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
|
||||||
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
||||||
)}
|
)}
|
||||||
onClick={() => setControlMode('hand')}
|
onClick={handleModeHand}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
controlMode === 'hand' ? <Hand02Solid className='w-4 h-4' /> : <Hand02 className='w-4 h-4' />
|
controlMode === 'hand' ? <Hand02Solid className='w-4 h-4' /> : <Hand02 className='w-4 h-4' />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user