mirror of https://github.com/langgenius/dify.git
the initial data to collaboration store
This commit is contained in:
parent
af6df05685
commit
7233b4de55
|
|
@ -56,20 +56,6 @@ export const useWorkflowInit = () => {
|
|||
})
|
||||
}
|
||||
|
||||
const populateCollaborationWithServerData = async (serverData: any) => {
|
||||
const { nodesMap, edgesMap, loroDoc } = useCollaborationStore.getState()
|
||||
serverData.graph.nodes?.forEach((node: any) => {
|
||||
console.log('Setting node:', node.id, node)
|
||||
nodesMap.set(node.id, node)
|
||||
})
|
||||
|
||||
serverData.graph.edges?.forEach((edge: any) => {
|
||||
console.log('Setting edge:', edge.id, edge)
|
||||
edgesMap.set(edge.id, edge)
|
||||
})
|
||||
loroDoc.commit()
|
||||
}
|
||||
|
||||
const handleGetInitialWorkflowData = useCallback(async () => {
|
||||
try {
|
||||
const [res] = await Promise.all([
|
||||
|
|
@ -85,7 +71,6 @@ export const useWorkflowInit = () => {
|
|||
environmentVariables: res.environment_variables?.map(env => env.value_type === 'secret' ? { ...env, value: '[__HIDDEN__]' } : env) || [],
|
||||
conversationVariables: res.conversation_variables || [],
|
||||
})
|
||||
await populateCollaborationWithServerData(res)
|
||||
setSyncWorkflowDraftHash(res.hash)
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import {
|
|||
} from '@/app/components/workflow/context'
|
||||
import { createWorkflowSlice } from './store/workflow/workflow-slice'
|
||||
import WorkflowAppMain from './components/workflow-main'
|
||||
import { useCollaborationStore } from '@/app/components/workflow/store/collaboration-store'
|
||||
|
||||
const WorkflowAppWithAdditionalContext = () => {
|
||||
const {
|
||||
|
|
@ -32,15 +33,26 @@ const WorkflowAppWithAdditionalContext = () => {
|
|||
const { data: fileUploadConfigResponse } = useSWR({ url: '/files/upload' }, fetchFileUploadConfig)
|
||||
|
||||
const nodesData = useMemo(() => {
|
||||
if (data)
|
||||
return initialNodes(data.graph.nodes, data.graph.edges)
|
||||
if (data) {
|
||||
const processedNodes = initialNodes(data.graph.nodes, data.graph.edges)
|
||||
|
||||
const { setNodes } = useCollaborationStore.getState()
|
||||
setNodes(processedNodes)
|
||||
|
||||
return processedNodes
|
||||
}
|
||||
return []
|
||||
}, [data])
|
||||
const edgesData = useMemo(() => {
|
||||
if (data)
|
||||
return initialEdges(data.graph.edges, data.graph.nodes)
|
||||
|
||||
const edgesData = useMemo(() => {
|
||||
if (data) {
|
||||
const processedEdges = initialEdges(data.graph.edges, data.graph.nodes)
|
||||
|
||||
const { setEdges } = useCollaborationStore.getState()
|
||||
setEdges(processedEdges)
|
||||
|
||||
return processedEdges
|
||||
}
|
||||
return []
|
||||
}, [data])
|
||||
|
||||
|
|
|
|||
|
|
@ -94,15 +94,15 @@ export const useCollaborationStore = create<CollaborationStore>((set, get) => ({
|
|||
const oldNode = oldNodesMap.get(newNode.id)
|
||||
if (!oldNode) {
|
||||
// add
|
||||
nodesMap.set(newNode.id, getPersistentNodeData(newNode))
|
||||
nodesMap.set(newNode.id, newNode)
|
||||
}
|
||||
else {
|
||||
else {
|
||||
const oldPersistentData = getPersistentNodeData(oldNode)
|
||||
const newPersistentData = getPersistentNodeData(newNode)
|
||||
|
||||
if (!isEqual(oldPersistentData, newPersistentData)) {
|
||||
// update
|
||||
nodesMap.set(newNode.id, newPersistentData)
|
||||
nodesMap.set(newNode.id, newNode)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue