From b65c3ac7faf4d813d1501e657dfad9c39d0adf94 Mon Sep 17 00:00:00 2001
From: chengyongru <61816729+chengyongru@users.noreply.github.com>
Date: Sun, 22 Nov 2026 14:00:14 +0800
Subject: [PATCH] fix(webui): let users turn off failed channels (#6748)
---
.../settings/channels/ChannelCatalogRow.tsx | 14 +++----
.../settings/channels/ChannelIdentity.tsx | 4 --
.../channels/ChannelInstancesPanelView.tsx | 8 +---
.../settings/channels/ChannelSetupPanel.tsx | 3 +-
webui/src/tests/channel-identity.test.ts | 3 --
webui/src/tests/settings-channels.test.tsx | 38 ++++++++++++++-----
6 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/webui/src/components/settings/channels/ChannelCatalogRow.tsx b/webui/src/components/settings/channels/ChannelCatalogRow.tsx
index 1a1bf8837..8d4a4c4bb 100644
--- a/webui/src/components/settings/channels/ChannelCatalogRow.tsx
+++ b/webui/src/components/settings/channels/ChannelCatalogRow.tsx
@@ -9,7 +9,6 @@ import {
ChannelLogo,
ChannelStatusBadge,
channelStatusLabel,
- channelToggleChecked,
localizedChannelDisplayName,
} from "@/components/settings/channels/ChannelIdentity";
import { Button } from "@/components/ui/button";
@@ -43,8 +42,8 @@ export function ChannelCatalogRow({
const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false;
const pendingChecked = actionKey === `enable:${feature.name}` ? true
: actionKey === `disable:${feature.name}` ? false : null;
- const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`;
- const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature));
+ const installing = actionKey === `install:${feature.name}`;
+ const checked = alwaysEnabled || (pendingChecked ?? feature.enabled);
const anyActionBusy = Boolean(actionKey);
const actionsDisabled = restartRequired || isRestarting;
const showInstallRestartHint = feature.install_supported && actionsDisabled;
@@ -108,7 +107,7 @@ export function ChannelCatalogRow({
{channelIdentity}
)}
-
+
{!feature.installed ? (
@@ -127,7 +126,7 @@ export function ChannelCatalogRow({
setInstallHint(false);
onAction("enable", feature.name, { installOnly: true, confirmed: true });
}}>
- {ownActionBusy
+ {installing
?
: }
{tx("settings.channels.install", "Install")}
@@ -147,7 +146,8 @@ export function ChannelCatalogRow({
: }
- ) : (
+ ) : null}
+ {!feature.restart_pending && (feature.installed || feature.enabled) ? (
- )}
+ ) : null}
);
diff --git a/webui/src/components/settings/channels/ChannelIdentity.tsx b/webui/src/components/settings/channels/ChannelIdentity.tsx
index 1a89675fd..9e65ec453 100644
--- a/webui/src/components/settings/channels/ChannelIdentity.tsx
+++ b/webui/src/components/settings/channels/ChannelIdentity.tsx
@@ -207,10 +207,6 @@ export function channelIsRunning(feature: NanobotFeatureInfo): boolean {
return feature.runtime_status === "running";
}
-export function channelToggleChecked(feature: NanobotFeatureInfo): boolean {
- return feature.runtime_status === "running" || feature.runtime_status === "starting";
-}
-
export function channelStatusLabel(
feature: NanobotFeatureInfo,
tx: (key: string, fallback: string) => string,
diff --git a/webui/src/components/settings/channels/ChannelInstancesPanelView.tsx b/webui/src/components/settings/channels/ChannelInstancesPanelView.tsx
index 44ff20360..475f2ae07 100644
--- a/webui/src/components/settings/channels/ChannelInstancesPanelView.tsx
+++ b/webui/src/components/settings/channels/ChannelInstancesPanelView.tsx
@@ -136,7 +136,7 @@ export function ChannelInstancesPanelView({
{instances.map((instance) => {
const expanded = selected?.id === instance.id && editor?.expanded === true;
const toggling = pendingToggle?.id === instance.id;
- const checked = toggling ? pendingToggle.checked : instanceToggleChecked(instance);
+ const checked = toggling ? pendingToggle.checked : instance.enabled;
const instanceSummary = customization.renderInstanceSummary
? customization.renderInstanceSummary(instance)
: instance.id;
@@ -199,7 +199,7 @@ export function ChannelInstancesPanelView({
disabled={
Boolean(pendingToggle)
|| savingFields
- || !instance.configured
+ || (!instance.enabled && !instance.configured)
}
ariaLabel={customization.toggleAriaLabel?.(instance)
?? t("settings.channels.toggleInstance", {
@@ -289,10 +289,6 @@ function channelInstanceDisplayName(instance: NanobotChannelInstanceInfo): strin
return instance.id;
}
-function instanceToggleChecked(instance: NanobotChannelInstanceInfo): boolean {
- return instance.runtime_status === "running" || instance.runtime_status === "starting";
-}
-
function ChannelInstanceStatusBadge({
instance,
configuredLabel,
diff --git a/webui/src/components/settings/channels/ChannelSetupPanel.tsx b/webui/src/components/settings/channels/ChannelSetupPanel.tsx
index 79c8d85c6..5d2377de6 100644
--- a/webui/src/components/settings/channels/ChannelSetupPanel.tsx
+++ b/webui/src/components/settings/channels/ChannelSetupPanel.tsx
@@ -38,7 +38,6 @@ import {
ChannelRuntimeError,
CHANNEL_SETUP_PANEL_CLASS_NAME,
channelSetup,
- channelToggleChecked,
localizedChannelDisplayName,
} from "@/components/settings/channels/ChannelIdentity";
import { ChannelSetupSurfaceView } from "@/components/settings/channels/ChannelSetupSurfaceView";
@@ -434,7 +433,7 @@ function ChannelSetupSurface({
}
};
- const enabled = pendingEnabled ?? channelToggleChecked(feature);
+ const enabled = pendingEnabled ?? feature.enabled;
const toggleEnabled = async (next: boolean) => {
if (actionPending) return;
if (next) {
diff --git a/webui/src/tests/channel-identity.test.ts b/webui/src/tests/channel-identity.test.ts
index e17c7d5d9..1e215b2e8 100644
--- a/webui/src/tests/channel-identity.test.ts
+++ b/webui/src/tests/channel-identity.test.ts
@@ -4,7 +4,6 @@ import {
channelIsRunning,
channelSetup,
channelStatusLabel,
- channelToggleChecked,
} from "@/components/settings/channels/ChannelIdentity";
import type { NanobotFeatureInfo } from "@/lib/types";
@@ -176,10 +175,8 @@ describe("channel runtime state", () => {
const unknown = feature({ enabled: true });
expect(channelIsRunning(running)).toBe(true);
- expect(channelToggleChecked(running)).toBe(true);
expect(channelStatusLabel(running, tx)).toBe("On");
expect(channelIsRunning(unknown)).toBe(false);
- expect(channelToggleChecked(unknown)).toBe(false);
expect(channelStatusLabel(unknown, tx)).toBe("Not running");
});
});
diff --git a/webui/src/tests/settings-channels.test.tsx b/webui/src/tests/settings-channels.test.tsx
index d274d54ac..c5a4a3b38 100644
--- a/webui/src/tests/settings-channels.test.tsx
+++ b/webui/src/tests/settings-channels.test.tsx
@@ -645,6 +645,32 @@ describe("Settings channels", () => {
},
);
+ it.each([true, false])("turns off failed WeChat from the channel list (support installed: %s)", async (installed) => {
+ const feature: NanobotFeatureInfo = {
+ ...uninstalledConnectFeature("weixin"), installed, configured: true, enabled: true,
+ runtime_status: "failed", status: "failed",
+ };
+ vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
+ if (String(input) === "/api/settings") return jsonResponse(settingsPayload());
+ if (String(input) === "/api/settings/nanobot-features") return jsonResponse({ features: [feature], enabled_count: 0 });
+ return jsonResponse({});
+ }));
+ requestMutationMock.mockResolvedValueOnce({
+ features: [{ ...feature, enabled: false, runtime_status: "stopped", status: "stopped" }], enabled_count: 0,
+ });
+
+ renderSettingsView({ initialSection: "channels" });
+ expect(await screen.findByText("Failed")).toBeVisible();
+ const toggle = screen.getByRole("switch", { name: "WeChat channel" });
+ expect(toggle).toBeChecked();
+ await userEvent.click(toggle);
+ expect(requestMutationMock).toHaveBeenCalledTimes(1);
+ expect(requestMutationMock).toHaveBeenCalledWith(
+ "settings.feature.disable", { name: "weixin" }, expect.any(Number),
+ );
+ await waitFor(() => expect(screen.queryByRole("button", { name: "View WeChat settings" })).not.toBeInTheDocument());
+ });
+
it("keeps WeChat login recovery visible across transient channel refreshes", async () => {
const expiredFeature: NanobotFeatureInfo = {
name: "weixin",
@@ -808,7 +834,7 @@ describe("Settings channels", () => {
renderSettingsView({ initialSection: "channels" });
expect((await screen.findAllByText("Failed")).length).toBeGreaterThan(0);
- expect(screen.queryByRole("switch", { name: "Matrix channel" })).not.toBeInTheDocument();
+ expect(screen.getByRole("switch", { name: "Matrix channel" })).toBeChecked();
fireEvent.click(screen.getByRole("button", { name: "Install Matrix" }));
await waitFor(() =>
@@ -858,10 +884,7 @@ describe("Settings channels", () => {
fireEvent.click(await screen.findByRole("button", { name: "View Matrix settings" }));
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
expect(screen.getByText(runtimeError)).toBeInTheDocument();
- expect(screen.getByLabelText("Matrix channel")).toHaveAttribute(
- "aria-checked",
- "false",
- );
+ expect(screen.getByRole("switch", { name: "Enable channel" })).toBeChecked();
});
it("starts Feishu connect in WebUI instead of showing a CLI command", async () => {
@@ -1429,10 +1452,7 @@ describe("Settings channels", () => {
fireEvent.click((await screen.findAllByRole("button", { name: /^View .+ settings$/ }))[0]);
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
expect(screen.getByText(runtimeError)).toBeInTheDocument();
- expect(screen.getByRole("switch", { name: "test assistant" })).toHaveAttribute(
- "aria-checked",
- "false",
- );
+ expect(screen.getByRole("switch", { name: "test assistant" })).toBeChecked();
});
it("preserves advanced field edits when collapsed and reopened with the keyboard", async () => {