import { Bell,Edit2,Loader2,Send,Trash2 } from 'lucide-react'; import React from 'react'; import type { NotificationChannel } from '../api'; import { notificationChannelTypes,notificationEventSummary } from '../state'; // NotificationChannelListProps 描述通知渠道列表的操作边界。 export interface NotificationChannelListProps { // channels 是当前可展示的通知渠道。 channels: NotificationChannel[]; // testingId 是当前正在测试发送的渠道 ID。 testingId: string; // onEdit 打开指定渠道的编辑弹窗。 onEdit: (channel: NotificationChannel) => void; // onDelete 删除指定渠道。 onDelete: (channel: NotificationChannel) => void | Promise; // onToggleEnabled 切换指定渠道的启用状态。 onToggleEnabled: (channel: NotificationChannel) => void | Promise; // onTest 发送指定渠道的测试通知。 onTest: (channel: NotificationChannel) => void | Promise; } // NotificationChannelList 渲染渠道摘要、启用状态和操作按钮。 export const NotificationChannelList: React.FC = ({ channels, testingId, onEdit, onDelete, onToggleEnabled, onTest }) => { // findChannel 从按钮数据属性中查找对应渠道。 const findChannel = (event: React.MouseEvent): NotificationChannel | null => channels.find( // channel 是当前待匹配的渠道数据。 channel => channel.id === event.currentTarget.dataset.channelId, ) || null; // handleToggleClick 处理渠道启用状态按钮点击。 const handleToggleClick = (event: React.MouseEvent) => { // channel 是按钮对应的渠道数据。 const channel = findChannel(event); if (channel) void onToggleEnabled(channel); }; // handleTestClick 处理渠道测试按钮点击。 const handleTestClick = (event: React.MouseEvent) => { // channel 是按钮对应的渠道数据。 const channel = findChannel(event); if (channel) void onTest(channel); }; // handleEditClick 处理渠道编辑按钮点击。 const handleEditClick = (event: React.MouseEvent) => { // channel 是按钮对应的渠道数据。 const channel = findChannel(event); if (channel) onEdit(channel); }; // handleDeleteClick 处理渠道删除按钮点击。 const handleDeleteClick = (event: React.MouseEvent) => { // channel 是按钮对应的渠道数据。 const channel = findChannel(event); if (channel) void onDelete(channel); }; // renderChannel 渲染单个通知渠道卡片。 const renderChannel = (channel: NotificationChannel) => { // meta 是当前渠道类型的静态展示配置。 const meta = notificationChannelTypes[channel.type] || notificationChannelTypes.webhook; // Icon 是当前渠道类型对应的图标组件。 const Icon = meta.icon; return (
{channel.name} {meta.label} {!channel.enabled && 已停用}
{meta.fields.map( // field 是当前渠道摘要需要读取的配置字段。 field => channel.config?.[field.key], ).filter(Boolean).map( // value 是渠道配置中非空的摘要值。 (value, index) => {String(value).length > 40 ? `${String(value).slice(0, 40)}…` : String(value)}, )}
订阅:{notificationEventSummary(channel.event_types)}
); }; if (channels.length === 0) { return

还没有配置任何通知渠道

点击右上角「新建渠道」开始配置

; } return
{channels.map(renderChannel)}
; };