mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
fix add candidate webhook node raise error
This commit is contained in:
parent
b04f92715c
commit
559cf6583f
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
|
useCallback,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import {
|
import {
|
||||||
@ -12,13 +13,15 @@ import {
|
|||||||
useStore,
|
useStore,
|
||||||
useWorkflowStore,
|
useWorkflowStore,
|
||||||
} from './store'
|
} from './store'
|
||||||
import { WorkflowHistoryEvent, useNodesInteractions, useWorkflowHistory } from './hooks'
|
import { WorkflowHistoryEvent, useNodesInteractions, useNodesSyncDraft, useWorkflowHistory } from './hooks'
|
||||||
import { CUSTOM_NODE } from './constants'
|
import { CUSTOM_NODE } from './constants'
|
||||||
import { getIterationStartNode, getLoopStartNode } from './utils'
|
import { getIterationStartNode, getLoopStartNode } from './utils'
|
||||||
import CustomNode from './nodes'
|
import CustomNode from './nodes'
|
||||||
import CustomNoteNode from './note-node'
|
import CustomNoteNode from './note-node'
|
||||||
import { CUSTOM_NOTE_NODE } from './note-node/constants'
|
import { CUSTOM_NOTE_NODE } from './note-node/constants'
|
||||||
import { BlockEnum } from './types'
|
import { BlockEnum } from './types'
|
||||||
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||||
|
import { fetchWebhookUrl } from '@/service/apps'
|
||||||
|
|
||||||
const CandidateNode = () => {
|
const CandidateNode = () => {
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
@ -29,6 +32,35 @@ const CandidateNode = () => {
|
|||||||
const { zoom } = useViewport()
|
const { zoom } = useViewport()
|
||||||
const { handleNodeSelect } = useNodesInteractions()
|
const { handleNodeSelect } = useNodesInteractions()
|
||||||
const { saveStateToHistory } = useWorkflowHistory()
|
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) => {
|
useEventListener('click', (e) => {
|
||||||
const { candidateNode, mousePosition } = workflowStore.getState()
|
const { candidateNode, mousePosition } = workflowStore.getState()
|
||||||
@ -70,6 +102,12 @@ const CandidateNode = () => {
|
|||||||
|
|
||||||
if (candidateNode.type === CUSTOM_NOTE_NODE)
|
if (candidateNode.type === CUSTOM_NOTE_NODE)
|
||||||
handleNodeSelect(candidateNode.id)
|
handleNodeSelect(candidateNode.id)
|
||||||
|
|
||||||
|
if (candidateNode.data.type === BlockEnum.TriggerWebhook) {
|
||||||
|
handleSyncWorkflowDraft(true, true, {
|
||||||
|
onSuccess: () => autoGenerateWebhookUrl(candidateNode.id),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user