mirror of https://github.com/langgenius/dify.git
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 { useTranslation } from 'react-i18next'
|
||||
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 Toast from '@/app/components/base/toast'
|
||||
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 { t } = useTranslation()
|
||||
|
|
@ -19,29 +19,15 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||
const { inputs, setInputs } = useNodeCrud<WebhookTriggerNodeType>(id, payload)
|
||||
const appId = useAppStore.getState().appDetail?.id
|
||||
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) => {
|
||||
setInputs(produce(inputs, (draft) => {
|
||||
ensureWebhookRawVariable(draft)
|
||||
draft.method = method
|
||||
}))
|
||||
}, [inputs, setInputs])
|
||||
|
||||
const handleContentTypeChange = useCallback((contentType: string) => {
|
||||
setInputs(produce(inputs, (draft) => {
|
||||
ensureWebhookRawVariable(draft)
|
||||
const previousContentType = draft.content_type
|
||||
draft.content_type = contentType
|
||||
|
||||
|
|
@ -165,8 +151,6 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||
else
|
||||
draft.variables.push(newVar)
|
||||
})
|
||||
|
||||
ensureWebhookRawVariable(draft)
|
||||
return true
|
||||
}, [t, id, isVarUsedInNodes, removeUsedVarInNodes])
|
||||
|
||||
|
|
@ -231,7 +215,6 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => {
|
|||
const response = await fetchWebhookUrl({ appId, nodeId: id })
|
||||
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
ensureWebhookRawVariable(draft)
|
||||
draft.webhook_url = response.webhook_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.
|
||||
console.error('Failed to generate webhook URL:', error)
|
||||
const newInputs = produce(inputs, (draft) => {
|
||||
ensureWebhookRawVariable(draft)
|
||||
draft.webhook_url = ''
|
||||
})
|
||||
setInputs(newInputs)
|
||||
|
|
|
|||
|
|
@ -10,16 +10,3 @@ export const createWebhookRawVariable = (): Variable => ({
|
|||
value_selector: [],
|
||||
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