chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import type { SyncDraftCallback } from '@/app/components/workflow/hooks-store'
|
||||
import { produce } from 'immer'
|
||||
import { useCallback } from 'react'
|
||||
import { useCollaborativeWorkflow } from './use-collaborative-workflow'
|
||||
import { useNodesSyncDraft } from './use-nodes-sync-draft'
|
||||
import { useNodesReadOnly } from './use-workflow'
|
||||
|
||||
type NodeDataUpdatePayload = {
|
||||
id: string
|
||||
data: Record<string, unknown>
|
||||
}
|
||||
|
||||
export const useNodeDataUpdate = () => {
|
||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||
const { getNodesReadOnly } = useNodesReadOnly()
|
||||
const collaborativeWorkflow = useCollaborativeWorkflow()
|
||||
|
||||
const handleNodeDataUpdate = useCallback(
|
||||
({ id, data }: NodeDataUpdatePayload) => {
|
||||
const { nodes, setNodes } = collaborativeWorkflow.getState()
|
||||
const newNodes = produce(nodes, (draft) => {
|
||||
const currentNode = draft.find((node) => node.id === id)!
|
||||
|
||||
if (currentNode) currentNode.data = { ...currentNode.data, ...data }
|
||||
})
|
||||
setNodes(newNodes)
|
||||
},
|
||||
[collaborativeWorkflow],
|
||||
)
|
||||
|
||||
const handleNodeDataUpdateWithSyncDraft = useCallback(
|
||||
(
|
||||
payload: NodeDataUpdatePayload,
|
||||
options?: {
|
||||
sync?: boolean
|
||||
notRefreshWhenSyncError?: boolean
|
||||
callback?: SyncDraftCallback
|
||||
},
|
||||
) => {
|
||||
if (getNodesReadOnly()) return
|
||||
|
||||
handleNodeDataUpdate(payload)
|
||||
handleSyncWorkflowDraft(options?.sync, options?.notRefreshWhenSyncError, options?.callback)
|
||||
},
|
||||
[handleSyncWorkflowDraft, handleNodeDataUpdate, getNodesReadOnly],
|
||||
)
|
||||
|
||||
return {
|
||||
handleNodeDataUpdate,
|
||||
handleNodeDataUpdateWithSyncDraft,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user