mirror of
https://github.com/langgenius/dify.git
synced 2026-01-08 07:14:14 +00:00
refactor(trigger-webhook): remove redundant WebhookParam type and sim… (#24390)
This commit is contained in:
@@ -4,12 +4,25 @@ import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import GenericTable from './generic-table'
|
||||
import type { ColumnConfig, GenericTableRow } from './generic-table'
|
||||
import type { WebhookParam } from '../types'
|
||||
import type { ParameterType, WebhookParameter } from '../types'
|
||||
|
||||
const normalizeParamType = (type: string): ParameterType => {
|
||||
switch (type) {
|
||||
case 'string':
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
case 'array':
|
||||
case 'object':
|
||||
return type
|
||||
default:
|
||||
return 'string'
|
||||
}
|
||||
}
|
||||
|
||||
type ParameterTableProps = {
|
||||
title: string
|
||||
parameters: WebhookParam[]
|
||||
onChange: (params: WebhookParam[]) => void
|
||||
parameters: WebhookParameter[]
|
||||
onChange: (params: WebhookParameter[]) => void
|
||||
readonly?: boolean
|
||||
placeholder?: string
|
||||
showType?: boolean
|
||||
@@ -70,22 +83,19 @@ const ParameterTable: FC<ParameterTableProps> = ({
|
||||
required: false,
|
||||
}
|
||||
|
||||
// Convert WebhookParam[] to GenericTableRow[]
|
||||
const tableData: GenericTableRow[] = parameters.map(param => ({
|
||||
key: param.key,
|
||||
key: param.name,
|
||||
type: param.type,
|
||||
required: param.required,
|
||||
value: param.value,
|
||||
}))
|
||||
|
||||
const handleDataChange = (data: GenericTableRow[]) => {
|
||||
const newParams: WebhookParam[] = data
|
||||
const newParams: WebhookParameter[] = data
|
||||
.filter(row => typeof row.key === 'string' && (row.key as string).trim() !== '')
|
||||
.map(row => ({
|
||||
key: String(row.key),
|
||||
type: (row.type as string) || 'string',
|
||||
name: String(row.key),
|
||||
type: normalizeParamType((row.type as string) || 'string'),
|
||||
required: Boolean(row.required),
|
||||
value: (row.value as string) || '',
|
||||
}))
|
||||
onChange(newParams)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { FC } from 'react'
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import type { HttpMethod, WebhookParam, WebhookParameter, WebhookTriggerNodeType } from './types'
|
||||
import type { HttpMethod, WebhookTriggerNodeType } from './types'
|
||||
import useConfig from './use-config'
|
||||
import ParameterTable from './components/parameter-table'
|
||||
import HeaderTable from './components/header-table'
|
||||
@@ -114,8 +114,8 @@ const Panel: FC<NodePanelProps<WebhookTriggerNodeType>> = ({
|
||||
<ParameterTable
|
||||
readonly={readOnly}
|
||||
title="Query Parameters"
|
||||
parameters={inputs.params as unknown as WebhookParam[]}
|
||||
onChange={params => handleParamsChange(params as unknown as WebhookParameter[])}
|
||||
parameters={inputs.params}
|
||||
onChange={handleParamsChange}
|
||||
placeholder={t(`${i18nPrefix}.noQueryParameters`)}
|
||||
showType={false}
|
||||
/>
|
||||
@@ -135,8 +135,8 @@ const Panel: FC<NodePanelProps<WebhookTriggerNodeType>> = ({
|
||||
<ParameterTable
|
||||
readonly={readOnly}
|
||||
title="Request Body Parameters"
|
||||
parameters={inputs.body as unknown as WebhookParam[]}
|
||||
onChange={params => handleBodyChange(params as unknown as WebhookParameter[])}
|
||||
parameters={inputs.body}
|
||||
onChange={handleBodyChange}
|
||||
placeholder={t(`${i18nPrefix}.noBodyParameters`)}
|
||||
showType={true}
|
||||
isRequestBody={true}
|
||||
|
||||
@@ -12,13 +12,6 @@ export type WebhookParameter = {
|
||||
required: boolean
|
||||
}
|
||||
|
||||
export type WebhookParam = {
|
||||
key: string
|
||||
type: string
|
||||
value: string
|
||||
required: boolean
|
||||
}
|
||||
|
||||
export type WebhookHeader = {
|
||||
name: string
|
||||
required: boolean
|
||||
|
||||
Reference in New Issue
Block a user