mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
refactor collaboration
This commit is contained in:
@ -130,7 +130,9 @@ export const useNodesSyncDraft = () => {
|
||||
if (error && error.json && !error.bodyUsed) {
|
||||
error.json().then((err: any) => {
|
||||
if (err.code === 'draft_workflow_not_sync' && !notRefreshWhenSyncError)
|
||||
handleRefreshWorkflowDraft()
|
||||
// TODO: hjlarry test collaboration
|
||||
// handleRefreshWorkflowDraft()
|
||||
console.error('draft_workflow_not_sync', err)
|
||||
})
|
||||
}
|
||||
callback?.onError && callback.onError()
|
||||
|
||||
@ -17,7 +17,6 @@ import {
|
||||
} from '@/service/workflow'
|
||||
import type { FetchWorkflowDraftResponse } from '@/types/workflow'
|
||||
import { useWorkflowConfig } from '@/service/use-workflow'
|
||||
import { useCollaborationStore } from '@/app/components/workflow/store/collaboration-store'
|
||||
|
||||
export const useWorkflowInit = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
@ -40,28 +39,9 @@ export const useWorkflowInit = () => {
|
||||
}, [workflowStore])
|
||||
useWorkflowConfig(appDetail.id, handleUpdateWorkflowConfig)
|
||||
|
||||
const initializeCollaboration = async (appId: string) => {
|
||||
const { initCollaboration } = useCollaborationStore.getState()
|
||||
initCollaboration(appId)
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
const checkInitialized = () => {
|
||||
const { nodesMap, edgesMap } = useCollaborationStore.getState()
|
||||
if (nodesMap && edgesMap)
|
||||
resolve()
|
||||
else
|
||||
setTimeout(checkInitialized, 50)
|
||||
}
|
||||
checkInitialized()
|
||||
})
|
||||
}
|
||||
|
||||
const handleGetInitialWorkflowData = useCallback(async () => {
|
||||
try {
|
||||
const [res] = await Promise.all([
|
||||
fetchWorkflowDraft(`/apps/${appDetail.id}/workflows/draft`),
|
||||
initializeCollaboration(appDetail.id),
|
||||
])
|
||||
const res = await fetchWorkflowDraft(`/apps/${appDetail.id}/workflows/draft`)
|
||||
setData(res)
|
||||
workflowStore.setState({
|
||||
envSecrets: (res.environment_variables || []).filter(env => env.value_type === 'secret').reduce((acc, env) => {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { useCallback } from 'react'
|
||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||
import { fetchWorkflowDraft } from '@/service/workflow'
|
||||
import type { WorkflowDataUpdater } from '@/app/components/workflow/types'
|
||||
import { useWorkflowUpdate } from '@/app/components/workflow/hooks'
|
||||
|
||||
export const useWorkflowRefreshDraft = () => {
|
||||
@ -19,7 +18,8 @@ export const useWorkflowRefreshDraft = () => {
|
||||
} = workflowStore.getState()
|
||||
setIsSyncingWorkflowDraft(true)
|
||||
fetchWorkflowDraft(`/apps/${appId}/workflows/draft`).then((response) => {
|
||||
handleUpdateWorkflowCanvas(response.graph as WorkflowDataUpdater)
|
||||
// TODO: hjlarry test collaboration
|
||||
// handleUpdateWorkflowCanvas(response.graph as WorkflowDataUpdater)
|
||||
setSyncWorkflowDraftHash(response.hash)
|
||||
setEnvSecrets((response.environment_variables || []).filter(env => env.value_type === 'secret').reduce((acc, env) => {
|
||||
acc[env.id] = env.value
|
||||
|
||||
Reference in New Issue
Block a user