mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
initial nodes
This commit is contained in:
parent
347cd6befc
commit
acae51c309
@ -19,9 +19,14 @@ export const usePipelineRefreshDraft = () => {
|
|||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
setIsSyncingWorkflowDraft(true)
|
setIsSyncingWorkflowDraft(true)
|
||||||
fetchWorkflowDraft(`/rag/pipelines/${pipelineId}/workflows/draft`).then((response) => {
|
fetchWorkflowDraft(`/rag/pipelines/${pipelineId}/workflows/draft`).then((response) => {
|
||||||
|
const {
|
||||||
|
nodes: processedNodes,
|
||||||
|
viewport,
|
||||||
|
} = processNodesWithoutDataSource(response.graph.nodes, response.graph.viewport)
|
||||||
handleUpdateWorkflowCanvas({
|
handleUpdateWorkflowCanvas({
|
||||||
...response.graph,
|
...response.graph,
|
||||||
nodes: processNodesWithoutDataSource(response.graph.nodes),
|
nodes: processedNodes,
|
||||||
|
viewport,
|
||||||
} as WorkflowDataUpdater)
|
} as WorkflowDataUpdater)
|
||||||
setSyncWorkflowDraftHash(response.hash)
|
setSyncWorkflowDraftHash(response.hash)
|
||||||
setEnvSecrets((response.environment_variables || []).filter(env => env.value_type === 'secret').reduce((acc, env) => {
|
setEnvSecrets((response.environment_variables || []).filter(env => env.value_type === 'secret').reduce((acc, env) => {
|
||||||
|
|||||||
@ -23,7 +23,7 @@ const RagPipeline = () => {
|
|||||||
} = usePipelineInit()
|
} = usePipelineInit()
|
||||||
const nodesData = useMemo(() => {
|
const nodesData = useMemo(() => {
|
||||||
if (data)
|
if (data)
|
||||||
return processNodesWithoutDataSource(initialNodes(data.graph.nodes, data.graph.edges))
|
return initialNodes(data.graph.nodes, data.graph.edges)
|
||||||
|
|
||||||
return []
|
return []
|
||||||
}, [data])
|
}, [data])
|
||||||
@ -41,15 +41,20 @@ const RagPipeline = () => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
nodes: processedNodes,
|
||||||
|
viewport,
|
||||||
|
} = processNodesWithoutDataSource(nodesData, data.graph.viewport)
|
||||||
return (
|
return (
|
||||||
<WorkflowWithDefaultContext
|
<WorkflowWithDefaultContext
|
||||||
edges={edgesData}
|
edges={edgesData}
|
||||||
nodes={nodesData}
|
nodes={processedNodes}
|
||||||
>
|
>
|
||||||
<RagPipelineMain
|
<RagPipelineMain
|
||||||
edges={edgesData}
|
edges={edgesData}
|
||||||
nodes={nodesData}
|
nodes={processedNodes}
|
||||||
viewport={data.graph.viewport}
|
viewport={viewport}
|
||||||
/>
|
/>
|
||||||
</WorkflowWithDefaultContext>
|
</WorkflowWithDefaultContext>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import type { Viewport } from 'reactflow'
|
||||||
import type { Node } from '@/app/components/workflow/types'
|
import type { Node } from '@/app/components/workflow/types'
|
||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import { generateNewNode } from '@/app/components/workflow/utils'
|
import { generateNewNode } from '@/app/components/workflow/utils'
|
||||||
@ -5,15 +6,23 @@ import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from '@/app/components/workflow/nodes/d
|
|||||||
import { CUSTOM_NOTE_NODE } from '@/app/components/workflow/note-node/constants'
|
import { CUSTOM_NOTE_NODE } from '@/app/components/workflow/note-node/constants'
|
||||||
import { NoteTheme } from '@/app/components/workflow/note-node/types'
|
import { NoteTheme } from '@/app/components/workflow/note-node/types'
|
||||||
import type { NoteNodeType } from '@/app/components/workflow/note-node/types'
|
import type { NoteNodeType } from '@/app/components/workflow/note-node/types'
|
||||||
import { CUSTOM_NODE } from '@/app/components/workflow/constants'
|
import {
|
||||||
|
CUSTOM_NODE,
|
||||||
|
NODE_WIDTH_X_OFFSET,
|
||||||
|
START_INITIAL_POSITION,
|
||||||
|
} from '@/app/components/workflow/constants'
|
||||||
|
|
||||||
export const processNodesWithoutDataSource = (nodes: Node[]) => {
|
export const processNodesWithoutDataSource = (nodes: Node[], viewport?: Viewport) => {
|
||||||
let leftNode
|
let leftNode
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
const node = nodes[i]
|
const node = nodes[i]
|
||||||
|
|
||||||
if (node.data.type === BlockEnum.DataSource)
|
if (node.data.type === BlockEnum.DataSource) {
|
||||||
return nodes
|
return {
|
||||||
|
nodes,
|
||||||
|
viewport,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (node.type === CUSTOM_NODE && !leftNode)
|
if (node.type === CUSTOM_NODE && !leftNode)
|
||||||
leftNode = node
|
leftNode = node
|
||||||
@ -23,6 +32,8 @@ export const processNodesWithoutDataSource = (nodes: Node[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (leftNode) {
|
if (leftNode) {
|
||||||
|
const startX = leftNode.position.x - NODE_WIDTH_X_OFFSET
|
||||||
|
const startY = leftNode.position.y
|
||||||
const { newNode } = generateNewNode({
|
const { newNode } = generateNewNode({
|
||||||
id: 'data-source-empty',
|
id: 'data-source-empty',
|
||||||
type: CUSTOM_DATA_SOURCE_EMPTY_NODE,
|
type: CUSTOM_DATA_SOURCE_EMPTY_NODE,
|
||||||
@ -34,8 +45,8 @@ export const processNodesWithoutDataSource = (nodes: Node[]) => {
|
|||||||
_isTempNode: true,
|
_isTempNode: true,
|
||||||
},
|
},
|
||||||
position: {
|
position: {
|
||||||
x: leftNode.position.x - 500,
|
x: startX,
|
||||||
y: leftNode.position.y,
|
y: startY,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const newNoteNode = generateNewNode({
|
const newNoteNode = generateNewNode({
|
||||||
@ -54,16 +65,26 @@ export const processNodesWithoutDataSource = (nodes: Node[]) => {
|
|||||||
_isTempNode: true,
|
_isTempNode: true,
|
||||||
} as NoteNodeType,
|
} as NoteNodeType,
|
||||||
position: {
|
position: {
|
||||||
x: leftNode.position.x - 500,
|
x: startX,
|
||||||
y: leftNode.position.y + 100,
|
y: startY + 100,
|
||||||
},
|
},
|
||||||
}).newNode
|
}).newNode
|
||||||
return [
|
return {
|
||||||
newNode,
|
nodes: [
|
||||||
newNoteNode,
|
newNode,
|
||||||
...nodes,
|
newNoteNode,
|
||||||
]
|
...nodes,
|
||||||
|
],
|
||||||
|
viewport: {
|
||||||
|
x: (START_INITIAL_POSITION.x - startX) * (viewport?.zoom || 1),
|
||||||
|
y: (START_INITIAL_POSITION.y - startY) * (viewport?.zoom || 1),
|
||||||
|
zoom: viewport?.zoom || 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes
|
return {
|
||||||
|
nodes,
|
||||||
|
viewport,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user