mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Add feature to be able to chain prompt values
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { createContext, useState } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { getUniqueNodeId } from 'utils/genericHelper'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
const initialValue = {
|
||||
reactFlowInstance: null,
|
||||
setReactFlowInstance: () => {},
|
||||
duplicateNode: () => {},
|
||||
deleteNode: () => {},
|
||||
deleteEdge: () => {}
|
||||
}
|
||||
@@ -22,13 +25,53 @@ export const ReactFlowContext = ({ children }) => {
|
||||
reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((edge) => edge.id !== id))
|
||||
}
|
||||
|
||||
const duplicateNode = (id) => {
|
||||
const nodes = reactFlowInstance.getNodes()
|
||||
const originalNode = nodes.find((n) => n.id === id)
|
||||
if (originalNode) {
|
||||
const newNodeId = getUniqueNodeId(originalNode.data, nodes)
|
||||
const clonedNode = cloneDeep(originalNode)
|
||||
|
||||
const duplicatedNode = {
|
||||
...clonedNode,
|
||||
id: newNodeId,
|
||||
position: {
|
||||
x: clonedNode.position.x + 400,
|
||||
y: clonedNode.position.y
|
||||
},
|
||||
positionAbsolute: {
|
||||
x: clonedNode.positionAbsolute.x + 400,
|
||||
y: clonedNode.positionAbsolute.y
|
||||
},
|
||||
data: {
|
||||
...clonedNode.data,
|
||||
id: newNodeId
|
||||
},
|
||||
selected: false
|
||||
}
|
||||
|
||||
const dataKeys = ['inputParams', 'inputAnchors', 'outputAnchors']
|
||||
|
||||
for (const key of dataKeys) {
|
||||
for (const item of duplicatedNode.data[key]) {
|
||||
if (item.id) {
|
||||
item.id = item.id.replace(id, newNodeId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reactFlowInstance.setNodes([...nodes, duplicatedNode])
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<flowContext.Provider
|
||||
value={{
|
||||
reactFlowInstance,
|
||||
setReactFlowInstance,
|
||||
deleteNode,
|
||||
deleteEdge
|
||||
deleteEdge,
|
||||
duplicateNode
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user