dify/web/app/components/workflow/nodes/trigger-webhook/components/header-table.tsx
Yeuoly b76e17b25d
feat: introduce trigger functionality (#27644)
Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com>
Co-authored-by: Stream <Stream_2@qq.com>
Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: zhsama <torvalds@linux.do>
Co-authored-by: Harry <xh001x@hotmail.com>
Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com>
Co-authored-by: yessenia <yessenia.contact@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: WTW0313 <twwu@dify.ai>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-12 17:59:37 +08:00

79 lines
2.0 KiB
TypeScript

'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import GenericTable from './generic-table'
import type { ColumnConfig, GenericTableRow } from './generic-table'
import type { WebhookHeader } from '../types'
type HeaderTableProps = {
readonly?: boolean
headers?: WebhookHeader[]
onChange: (headers: WebhookHeader[]) => void
}
const HeaderTable: FC<HeaderTableProps> = ({
readonly = false,
headers = [],
onChange,
}) => {
const { t } = useTranslation()
// Define columns for header table - matching prototype design
const columns: ColumnConfig[] = [
{
key: 'name',
title: t('workflow.nodes.triggerWebhook.varName'),
type: 'input',
width: 'flex-1',
placeholder: t('workflow.nodes.triggerWebhook.varNamePlaceholder'),
},
{
key: 'required',
title: t('workflow.nodes.triggerWebhook.required'),
type: 'switch',
width: 'w-[88px]',
},
]
// No default prefilled row; table initializes with one empty row
// Empty row template for new rows
const emptyRowData: GenericTableRow = {
name: '',
required: false,
}
// Convert WebhookHeader[] to GenericTableRow[]
const tableData: GenericTableRow[] = headers.map(header => ({
name: header.name,
required: header.required,
}))
// Handle data changes
const handleDataChange = (data: GenericTableRow[]) => {
const newHeaders: WebhookHeader[] = data
.filter(row => row.name && typeof row.name === 'string' && row.name.trim() !== '')
.map(row => ({
name: (row.name as string) || '',
required: !!row.required,
}))
onChange(newHeaders)
}
return (
<GenericTable
title="Header Parameters"
columns={columns}
data={tableData}
onChange={handleDataChange}
readonly={readonly}
placeholder={t('workflow.nodes.triggerWebhook.noHeaders')}
emptyRowData={emptyRowData}
showHeader={true}
/>
)
}
export default React.memo(HeaderTable)