mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 23:06:40 +08:00
Move Builder, app creation, and shared DSL import UI into feature modules. Keep app draft state in the app editor and serialize pipeline draft saves before test runs. Validate affected unit and browser suites, type checking, and repository static checks. Fix the pipeline viewport browser fixture to avoid real network requests.
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import type { SyncDraftCallback } from '@/app/components/workflow/hooks-store'
|
|
import { produce } from 'immer'
|
|
import { useCallback } from 'react'
|
|
import { useCollaborativeWorkflow } from './use-collaborative-workflow'
|
|
import { useScheduleDraftSave } from './use-schedule-draft-save'
|
|
import { useNodesReadOnly } from './use-workflow'
|
|
|
|
type NodeDataUpdatePayload = {
|
|
id: string
|
|
data: Record<string, unknown>
|
|
}
|
|
|
|
export const useNodeDataUpdate = () => {
|
|
const { handleSyncWorkflowDraft } = useScheduleDraftSave()
|
|
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,
|
|
}
|
|
}
|