mirror of https://github.com/langgenius/dify.git
fix add candidate webhook node raise error
This commit is contained in:
parent
b04f92715c
commit
559cf6583f
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
memo,
|
||||
useCallback,
|
||||
} from 'react'
|
||||
import produce from 'immer'
|
||||
import {
|
||||
|
|
@ -12,13 +13,15 @@ import {
|
|||
useStore,
|
||||
useWorkflowStore,
|
||||
} from './store'
|
||||
import { WorkflowHistoryEvent, useNodesInteractions, useWorkflowHistory } from './hooks'
|
||||
import { WorkflowHistoryEvent, useNodesInteractions, useNodesSyncDraft, useWorkflowHistory } from './hooks'
|
||||
import { CUSTOM_NODE } from './constants'
|
||||
import { getIterationStartNode, getLoopStartNode } from './utils'
|
||||
import CustomNode from './nodes'
|
||||
import CustomNoteNode from './note-node'
|
||||
import { CUSTOM_NOTE_NODE } from './note-node/constants'
|
||||
import { BlockEnum } from './types'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { fetchWebhookUrl } from '@/service/apps'
|
||||
|
||||
const CandidateNode = () => {
|
||||
const store = useStoreApi()
|
||||
|
|
@ -29,6 +32,35 @@ const CandidateNode = () => {
|
|||
const { zoom } = useViewport()
|
||||
const { handleNodeSelect } = useNodesInteractions()
|
||||
const { saveStateToHistory } = useWorkflowHistory()
|
||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||
|
||||
const autoGenerateWebhookUrl = useCallback((nodeId: string) => {
|
||||
const appId = useAppStore.getState().appDetail?.id
|
||||
if (!appId)
|
||||
return
|
||||
|
||||
fetchWebhookUrl({ appId, nodeId }).then((response) => {
|
||||
const { getNodes, setNodes } = store.getState()
|
||||
let hasUpdated = false
|
||||
const updatedNodes = produce(getNodes(), (draft) => {
|
||||
const targetNode = draft.find(n => n.id === nodeId)
|
||||
if (!targetNode || targetNode.data.type !== BlockEnum.TriggerWebhook)
|
||||
return
|
||||
|
||||
targetNode.data = {
|
||||
...targetNode.data,
|
||||
webhook_url: response.webhook_url,
|
||||
webhook_debug_url: response.webhook_debug_url,
|
||||
}
|
||||
hasUpdated = true
|
||||
})
|
||||
if (hasUpdated)
|
||||
setNodes(updatedNodes)
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
console.error('Failed to auto-generate webhook URL from candidate placement:', error)
|
||||
})
|
||||
}, [store])
|
||||
|
||||
useEventListener('click', (e) => {
|
||||
const { candidateNode, mousePosition } = workflowStore.getState()
|
||||
|
|
@ -70,6 +102,12 @@ const CandidateNode = () => {
|
|||
|
||||
if (candidateNode.type === CUSTOM_NOTE_NODE)
|
||||
handleNodeSelect(candidateNode.id)
|
||||
|
||||
if (candidateNode.data.type === BlockEnum.TriggerWebhook) {
|
||||
handleSyncWorkflowDraft(true, true, {
|
||||
onSuccess: () => autoGenerateWebhookUrl(candidateNode.id),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue