From b2c1b1f7d70164befb3027cc555b3af994b2b213 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Sat, 24 Oct 2026 16:10:46 +0800 Subject: [PATCH] feat(web): support default notification channel (ONE-154) --- web/src/components/ChannelSelector.tsx | 15 ++++++++++---- web/src/locales/en.json | 6 ++++-- web/src/locales/zh.json | 6 ++++-- web/src/pages/channels/ChannelPage.tsx | 27 ++++++++++++++++++++++++-- web/src/types/index.ts | 1 + 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/web/src/components/ChannelSelector.tsx b/web/src/components/ChannelSelector.tsx index 89628b2..8a8e271 100644 --- a/web/src/components/ChannelSelector.tsx +++ b/web/src/components/ChannelSelector.tsx @@ -16,6 +16,7 @@ export function ChannelSelector({ const { t } = useTranslation(); const [open, setOpen] = useState(false); const [enabledChannels, setEnabledChannels] = useState([]); + const [defaultChannel, setDefaultChannel] = useState(""); const [loading, setLoading] = useState(true); const ref = useRef(null); @@ -24,8 +25,10 @@ export function ChannelSelector({ try { const config = await api.get("/me/notifications"); setEnabledChannels(config.enabled_channels || []); + setDefaultChannel(config.default_channel || ""); } catch { setEnabledChannels([]); + setDefaultChannel(""); } finally { setLoading(false); } @@ -48,6 +51,12 @@ export function ChannelSelector({ const availableChannels = CHANNELS.filter((ch) => enabledChannels.includes(ch.id), ); + const defaultChannelLabel = CHANNELS.find( + (channel) => channel.id === defaultChannel, + )?.label; + const emptySelectionLabel = defaultChannelLabel + ? t("channels.defaultChannelOption", { name: defaultChannelLabel }) + : t("channels.noChannelsSelected"); const toggleChannel = (channelId: string) => { const newSelected = selected.includes(channelId) @@ -84,7 +93,7 @@ export function ChannelSelector({ > {selected.length === 0 - ? t("channels.allChannels") + ? emptySelectionLabel : t("channels.selectedChannels", { count: selected.length })} {selected.length === 0 && } - - {t("channels.allChannels")} - + {emptySelectionLabel} {selected.length === 0 && ( )} diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 8f17735..d080070 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -358,7 +358,7 @@ }, "channels": { "title": "Channel Management", - "description": "Configure notification channels. Notifications will be sent to all enabled channels by default. Each notification item can individually select which channels to use.", + "description": "Configure notification channels. Notifications without a channel selection are sent only to the default channel. Each item can individually select one or more channels.", "telegram": "Telegram", "webhook": "Webhook", "wechatbot": "WeCom Bot", @@ -383,7 +383,9 @@ "apiKey": "API Key", "token": "Token", "selectChannels": "Select Notification Channels", - "allChannels": "All enabled channels", + "defaultChannel": "Default channel", + "setAsDefault": "Set as default", + "defaultChannelOption": "Default channel ({{name}})", "selectedChannels": "{{count}} channels selected", "noChannelsSelected": "None selected (use default)", "noChannelsEnabled": "No channels enabled, please configure in Channel Management first", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 733570e..beaaa3c 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -358,7 +358,7 @@ }, "channels": { "title": "通道管理", - "description": "配置通知通道,设置将发送到所有已启用的通道。每个通知项可以单独选择要使用的通道。", + "description": "配置通知渠道。未指定渠道的通知将只发送到默认渠道;每个事项可以单独多选要使用的渠道。", "telegram": "Telegram", "webhook": "Webhook", "wechatbot": "企业微信机器人", @@ -383,7 +383,9 @@ "apiKey": "API 密钥", "token": "令牌", "selectChannels": "选择通知渠道", - "allChannels": "所有已启用的渠道", + "defaultChannel": "默认渠道", + "setAsDefault": "设为默认", + "defaultChannelOption": "默认渠道({{name}})", "selectedChannels": "已选择 {{count}} 个渠道", "noChannelsSelected": "未选择(使用默认)", "noChannelsEnabled": "未启用任何通道,请先到通道管理页面配置", diff --git a/web/src/pages/channels/ChannelPage.tsx b/web/src/pages/channels/ChannelPage.tsx index 5f48f05..635fd3d 100644 --- a/web/src/pages/channels/ChannelPage.tsx +++ b/web/src/pages/channels/ChannelPage.tsx @@ -316,8 +316,18 @@ function ChannelCard({ enabled_channels: next.enabled_channels, }); onConfigChange(next); - } catch { - // no state change on error + } catch (err: any) { + setFeedback({ ok: false, msg: err.message || t("common.error") }); + } + }; + + const handleSetDefault = async () => { + setFeedback(null); + try { + await api.put("/me/notifications", { default_channel: channel.id }); + onConfigChange({ ...config, default_channel: channel.id }); + } catch (err: any) { + setFeedback({ ok: false, msg: err.message || t("common.error") }); } }; @@ -390,6 +400,19 @@ function ChannelCard({ > {isEnabled ? t("common.enabled") : t("common.disabled")} + {config.default_channel === channel.id ? ( + + {t("channels.defaultChannel")} + + ) : isEnabled ? ( + + ) : null}