refactor(trigger-webhook): remove redundant WebhookParam type and sim… (#24390)

This commit is contained in:
cathy
2025-08-24 00:21:47 +08:00
committed by GitHub
parent 6b0d919dbd
commit 4084ade86c
3 changed files with 25 additions and 22 deletions

View File

@@ -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)
}

View File

@@ -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}

View File

@@ -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