fix(webui): let users turn off failed channels (#6748)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-22 14:00:14 +08:00
1 parent 0dc8679edc
commit b65c3ac7fa
6 files changed
+39 -31

No files matched your search

@@ -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}
</button>
)}
<div className="flex w-11 shrink-0 items-center justify-center">
<div className="flex min-w-11 shrink-0 items-center justify-center gap-3">
{!feature.installed ? (
<HoverHint enabled={showInstallRestartHint}
content={t(isRestarting ? "app.system.restarting" : "settings.channels.restartBeforeInstall")}>
@@ -127,7 +126,7 @@ export function ChannelCatalogRow({
setInstallHint(false);
onAction("enable", feature.name, { installOnly: true, confirmed: true });
}}>
{ownActionBusy
{installing
? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
: <Download className="h-3.5 w-3.5" aria-hidden />}
<span className="sr-only">{tx("settings.channels.install", "Install")}</span>
@@ -147,7 +146,8 @@ export function ChannelCatalogRow({
: <RotateCcw className="h-3.5 w-3.5" aria-hidden />}
</Button>
</HoverHint>
) : (
) : null}
{!feature.restart_pending && (feature.installed || feature.enabled) ? (
<ToggleButton ref={toggleRef} checked={checked}
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
disabled={alwaysEnabled || actionsDisabled || anyActionBusy}
@@ -156,7 +156,7 @@ export function ChannelCatalogRow({
if (enabled && feature.configured === false) onSelect(toggleRef.current, true);
else onAction(enabled ? "enable" : "disable", feature.name);
}} />
)}
) : null}
</div>
</div>
);
@@ -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,
@@ -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,
@@ -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) {
-3
View File
@@ -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");
});
});
+29 -9
View File
@@ -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 () => {