mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
rm unused ensureWebhookRawVariable
This commit is contained in:
parent
771cc72dcf
commit
d90ffbcf14
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect } from 'react'
|
import { useCallback } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { HttpMethod, WebhookHeader, WebhookParameter, WebhookTriggerNodeType } from './types'
|
import type { HttpMethod, WebhookHeader, WebhookParameter, WebhookTriggerNodeType } from './types'
|
||||||
@ -11,7 +11,7 @@ import type { Variable } from '@/app/components/workflow/types'
|
|||||||
import { VarType } from '@/app/components/workflow/types'
|
import { VarType } from '@/app/components/workflow/types'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import { checkKeys, hasDuplicateStr } from '@/utils/var'
|
import { checkKeys, hasDuplicateStr } from '@/utils/var'
|
||||||
import { WEBHOOK_RAW_VARIABLE_NAME, ensureWebhookRawVariable } from './utils/raw-variable'
|
import { WEBHOOK_RAW_VARIABLE_NAME } from './utils/raw-variable'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -19,29 +19,15 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||||||
const { inputs, setInputs } = useNodeCrud<WebhookTriggerNodeType>(id, payload)
|
const { inputs, setInputs } = useNodeCrud<WebhookTriggerNodeType>(id, payload)
|
||||||
const appId = useAppStore.getState().appDetail?.id
|
const appId = useAppStore.getState().appDetail?.id
|
||||||
const { isVarUsedInNodes, removeUsedVarInNodes } = useWorkflow()
|
const { isVarUsedInNodes, removeUsedVarInNodes } = useWorkflow()
|
||||||
const hasWebhookRawVariable = inputs.variables?.some(variable => variable.variable === WEBHOOK_RAW_VARIABLE_NAME) ?? false
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (readOnly)
|
|
||||||
return
|
|
||||||
|
|
||||||
if (!hasWebhookRawVariable) {
|
|
||||||
setInputs(produce(inputs, (draft) => {
|
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}, [readOnly, hasWebhookRawVariable, inputs, setInputs])
|
|
||||||
|
|
||||||
const handleMethodChange = useCallback((method: HttpMethod) => {
|
const handleMethodChange = useCallback((method: HttpMethod) => {
|
||||||
setInputs(produce(inputs, (draft) => {
|
setInputs(produce(inputs, (draft) => {
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
draft.method = method
|
draft.method = method
|
||||||
}))
|
}))
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
const handleContentTypeChange = useCallback((contentType: string) => {
|
const handleContentTypeChange = useCallback((contentType: string) => {
|
||||||
setInputs(produce(inputs, (draft) => {
|
setInputs(produce(inputs, (draft) => {
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
const previousContentType = draft.content_type
|
const previousContentType = draft.content_type
|
||||||
draft.content_type = contentType
|
draft.content_type = contentType
|
||||||
|
|
||||||
@ -165,8 +151,6 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||||||
else
|
else
|
||||||
draft.variables.push(newVar)
|
draft.variables.push(newVar)
|
||||||
})
|
})
|
||||||
|
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
return true
|
return true
|
||||||
}, [t, id, isVarUsedInNodes, removeUsedVarInNodes])
|
}, [t, id, isVarUsedInNodes, removeUsedVarInNodes])
|
||||||
|
|
||||||
@ -231,7 +215,6 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||||||
const response = await fetchWebhookUrl({ appId, nodeId: id })
|
const response = await fetchWebhookUrl({ appId, nodeId: id })
|
||||||
|
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
draft.webhook_url = response.webhook_url
|
draft.webhook_url = response.webhook_url
|
||||||
draft.webhook_debug_url = response.webhook_debug_url
|
draft.webhook_debug_url = response.webhook_debug_url
|
||||||
})
|
})
|
||||||
@ -242,7 +225,6 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||||||
// Keep the UI unblocked and allow users to proceed in local/dev environments.
|
// Keep the UI unblocked and allow users to proceed in local/dev environments.
|
||||||
console.error('Failed to generate webhook URL:', error)
|
console.error('Failed to generate webhook URL:', error)
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
ensureWebhookRawVariable(draft)
|
|
||||||
draft.webhook_url = ''
|
draft.webhook_url = ''
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
|
|||||||
@ -10,16 +10,3 @@ export const createWebhookRawVariable = (): Variable => ({
|
|||||||
value_selector: [],
|
value_selector: [],
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
type WithVariables = {
|
|
||||||
variables?: Variable[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ensureWebhookRawVariable = <T extends WithVariables>(payload: T): void => {
|
|
||||||
if (!payload.variables)
|
|
||||||
payload.variables = []
|
|
||||||
|
|
||||||
const hasRawVariable = payload.variables.some(variable => variable.variable === WEBHOOK_RAW_VARIABLE_NAME)
|
|
||||||
if (!hasRawVariable)
|
|
||||||
payload.variables.push(createWebhookRawVariable())
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user