mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
backup draft
This commit is contained in:
@ -22,6 +22,23 @@ export const useWorkflowRun = () => {
|
||||
const reactflow = useReactFlow()
|
||||
const workflowContainerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const handleBackupDraft = useCallback(() => {
|
||||
const {
|
||||
getNodes,
|
||||
getEdges,
|
||||
getViewport,
|
||||
} = reactflow
|
||||
const {
|
||||
setBackupDraft,
|
||||
} = useStore.getState()
|
||||
|
||||
setBackupDraft({
|
||||
nodes: getNodes(),
|
||||
edges: getEdges(),
|
||||
viewport: getViewport(),
|
||||
})
|
||||
}, [reactflow])
|
||||
|
||||
const handleLoadBackupDraft = useCallback(() => {
|
||||
const {
|
||||
setNodes,
|
||||
@ -55,9 +72,10 @@ export const useWorkflowRun = () => {
|
||||
handleLoadBackupDraft()
|
||||
}
|
||||
else {
|
||||
handleBackupDraft()
|
||||
const newNodes = produce(getNodes(), (draft) => {
|
||||
draft.forEach((node) => {
|
||||
node.data._runningStatus = shouldClear ? undefined : NodeRunningStatus.Waiting
|
||||
node.data._runningStatus = NodeRunningStatus.Waiting
|
||||
})
|
||||
})
|
||||
setNodes(newNodes)
|
||||
@ -68,7 +86,7 @@ export const useWorkflowRun = () => {
|
||||
})
|
||||
setEdges(newEdges)
|
||||
}
|
||||
}, [store, handleLoadBackupDraft])
|
||||
}, [store, handleLoadBackupDraft, handleBackupDraft])
|
||||
|
||||
const handleRun = useCallback((params: any, callback?: IOtherOptions) => {
|
||||
const {
|
||||
@ -77,8 +95,6 @@ export const useWorkflowRun = () => {
|
||||
edges,
|
||||
setEdges,
|
||||
} = store.getState()
|
||||
const { getViewport } = reactflow
|
||||
const { setBackupDraft } = useStore.getState()
|
||||
const appDetail = useAppStore.getState().appDetail
|
||||
const workflowContainer = document.getElementById('workflow-container')
|
||||
|
||||
@ -87,12 +103,6 @@ export const useWorkflowRun = () => {
|
||||
clientHeight,
|
||||
} = workflowContainer!
|
||||
|
||||
setBackupDraft({
|
||||
nodes: getNodes(),
|
||||
edges,
|
||||
viewport: getViewport(),
|
||||
})
|
||||
|
||||
let url = ''
|
||||
if (appDetail?.mode === 'advanced-chat')
|
||||
url = `/apps/${appDetail.id}/advanced-chat/workflows/draft/run`
|
||||
@ -164,6 +174,7 @@ export const useWorkflowRun = () => {
|
||||
}, [store, reactflow])
|
||||
|
||||
return {
|
||||
handleBackupDraft,
|
||||
handleRunSetting,
|
||||
handleRun,
|
||||
workflowContainerRef,
|
||||
|
||||
Reference in New Issue
Block a user