fix(webui): let users turn off failed channels (#6748)
This commit is contained in:
1 parent
0dc8679edc
commit
b65c3ac7fa
6 files changed
+39
-31
No files matched your search
@@ -9,7 +9,6 @@ import {
|
|||||||
ChannelLogo,
|
ChannelLogo,
|
||||||
ChannelStatusBadge,
|
ChannelStatusBadge,
|
||||||
channelStatusLabel,
|
channelStatusLabel,
|
||||||
channelToggleChecked,
|
|
||||||
localizedChannelDisplayName,
|
localizedChannelDisplayName,
|
||||||
} from "@/components/settings/channels/ChannelIdentity";
|
} from "@/components/settings/channels/ChannelIdentity";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -43,8 +42,8 @@ export function ChannelCatalogRow({
|
|||||||
const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false;
|
const alwaysEnabled = feature.capabilities?.includes("always_enabled") ?? false;
|
||||||
const pendingChecked = actionKey === `enable:${feature.name}` ? true
|
const pendingChecked = actionKey === `enable:${feature.name}` ? true
|
||||||
: actionKey === `disable:${feature.name}` ? false : null;
|
: actionKey === `disable:${feature.name}` ? false : null;
|
||||||
const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`;
|
const installing = actionKey === `install:${feature.name}`;
|
||||||
const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature));
|
const checked = alwaysEnabled || (pendingChecked ?? feature.enabled);
|
||||||
const anyActionBusy = Boolean(actionKey);
|
const anyActionBusy = Boolean(actionKey);
|
||||||
const actionsDisabled = restartRequired || isRestarting;
|
const actionsDisabled = restartRequired || isRestarting;
|
||||||
const showInstallRestartHint = feature.install_supported && actionsDisabled;
|
const showInstallRestartHint = feature.install_supported && actionsDisabled;
|
||||||
@@ -108,7 +107,7 @@ export function ChannelCatalogRow({
|
|||||||
{channelIdentity}
|
{channelIdentity}
|
||||||
</button>
|
</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 ? (
|
{!feature.installed ? (
|
||||||
<HoverHint enabled={showInstallRestartHint}
|
<HoverHint enabled={showInstallRestartHint}
|
||||||
content={t(isRestarting ? "app.system.restarting" : "settings.channels.restartBeforeInstall")}>
|
content={t(isRestarting ? "app.system.restarting" : "settings.channels.restartBeforeInstall")}>
|
||||||
@@ -127,7 +126,7 @@ export function ChannelCatalogRow({
|
|||||||
setInstallHint(false);
|
setInstallHint(false);
|
||||||
onAction("enable", feature.name, { installOnly: true, confirmed: true });
|
onAction("enable", feature.name, { installOnly: true, confirmed: true });
|
||||||
}}>
|
}}>
|
||||||
{ownActionBusy
|
{installing
|
||||||
? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||||
: <Download className="h-3.5 w-3.5" aria-hidden />}
|
: <Download className="h-3.5 w-3.5" aria-hidden />}
|
||||||
<span className="sr-only">{tx("settings.channels.install", "Install")}</span>
|
<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 />}
|
: <RotateCcw className="h-3.5 w-3.5" aria-hidden />}
|
||||||
</Button>
|
</Button>
|
||||||
</HoverHint>
|
</HoverHint>
|
||||||
) : (
|
) : null}
|
||||||
|
{!feature.restart_pending && (feature.installed || feature.enabled) ? (
|
||||||
<ToggleButton ref={toggleRef} checked={checked}
|
<ToggleButton ref={toggleRef} checked={checked}
|
||||||
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
|
||||||
disabled={alwaysEnabled || actionsDisabled || anyActionBusy}
|
disabled={alwaysEnabled || actionsDisabled || anyActionBusy}
|
||||||
@@ -156,7 +156,7 @@ export function ChannelCatalogRow({
|
|||||||
if (enabled && feature.configured === false) onSelect(toggleRef.current, true);
|
if (enabled && feature.configured === false) onSelect(toggleRef.current, true);
|
||||||
else onAction(enabled ? "enable" : "disable", feature.name);
|
else onAction(enabled ? "enable" : "disable", feature.name);
|
||||||
}} />
|
}} />
|
||||||
)}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -207,10 +207,6 @@ export function channelIsRunning(feature: NanobotFeatureInfo): boolean {
|
|||||||
return feature.runtime_status === "running";
|
return feature.runtime_status === "running";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function channelToggleChecked(feature: NanobotFeatureInfo): boolean {
|
|
||||||
return feature.runtime_status === "running" || feature.runtime_status === "starting";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function channelStatusLabel(
|
export function channelStatusLabel(
|
||||||
feature: NanobotFeatureInfo,
|
feature: NanobotFeatureInfo,
|
||||||
tx: (key: string, fallback: string) => string,
|
tx: (key: string, fallback: string) => string,
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export function ChannelInstancesPanelView({
|
|||||||
{instances.map((instance) => {
|
{instances.map((instance) => {
|
||||||
const expanded = selected?.id === instance.id && editor?.expanded === true;
|
const expanded = selected?.id === instance.id && editor?.expanded === true;
|
||||||
const toggling = pendingToggle?.id === instance.id;
|
const toggling = pendingToggle?.id === instance.id;
|
||||||
const checked = toggling ? pendingToggle.checked : instanceToggleChecked(instance);
|
const checked = toggling ? pendingToggle.checked : instance.enabled;
|
||||||
const instanceSummary = customization.renderInstanceSummary
|
const instanceSummary = customization.renderInstanceSummary
|
||||||
? customization.renderInstanceSummary(instance)
|
? customization.renderInstanceSummary(instance)
|
||||||
: instance.id;
|
: instance.id;
|
||||||
@@ -199,7 +199,7 @@ export function ChannelInstancesPanelView({
|
|||||||
disabled={
|
disabled={
|
||||||
Boolean(pendingToggle)
|
Boolean(pendingToggle)
|
||||||
|| savingFields
|
|| savingFields
|
||||||
|| !instance.configured
|
|| (!instance.enabled && !instance.configured)
|
||||||
}
|
}
|
||||||
ariaLabel={customization.toggleAriaLabel?.(instance)
|
ariaLabel={customization.toggleAriaLabel?.(instance)
|
||||||
?? t("settings.channels.toggleInstance", {
|
?? t("settings.channels.toggleInstance", {
|
||||||
@@ -289,10 +289,6 @@ function channelInstanceDisplayName(instance: NanobotChannelInstanceInfo): strin
|
|||||||
return instance.id;
|
return instance.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function instanceToggleChecked(instance: NanobotChannelInstanceInfo): boolean {
|
|
||||||
return instance.runtime_status === "running" || instance.runtime_status === "starting";
|
|
||||||
}
|
|
||||||
|
|
||||||
function ChannelInstanceStatusBadge({
|
function ChannelInstanceStatusBadge({
|
||||||
instance,
|
instance,
|
||||||
configuredLabel,
|
configuredLabel,
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import {
|
|||||||
ChannelRuntimeError,
|
ChannelRuntimeError,
|
||||||
CHANNEL_SETUP_PANEL_CLASS_NAME,
|
CHANNEL_SETUP_PANEL_CLASS_NAME,
|
||||||
channelSetup,
|
channelSetup,
|
||||||
channelToggleChecked,
|
|
||||||
localizedChannelDisplayName,
|
localizedChannelDisplayName,
|
||||||
} from "@/components/settings/channels/ChannelIdentity";
|
} from "@/components/settings/channels/ChannelIdentity";
|
||||||
import { ChannelSetupSurfaceView } from "@/components/settings/channels/ChannelSetupSurfaceView";
|
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) => {
|
const toggleEnabled = async (next: boolean) => {
|
||||||
if (actionPending) return;
|
if (actionPending) return;
|
||||||
if (next) {
|
if (next) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
channelIsRunning,
|
channelIsRunning,
|
||||||
channelSetup,
|
channelSetup,
|
||||||
channelStatusLabel,
|
channelStatusLabel,
|
||||||
channelToggleChecked,
|
|
||||||
} from "@/components/settings/channels/ChannelIdentity";
|
} from "@/components/settings/channels/ChannelIdentity";
|
||||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||||
|
|
||||||
@@ -176,10 +175,8 @@ describe("channel runtime state", () => {
|
|||||||
const unknown = feature({ enabled: true });
|
const unknown = feature({ enabled: true });
|
||||||
|
|
||||||
expect(channelIsRunning(running)).toBe(true);
|
expect(channelIsRunning(running)).toBe(true);
|
||||||
expect(channelToggleChecked(running)).toBe(true);
|
|
||||||
expect(channelStatusLabel(running, tx)).toBe("On");
|
expect(channelStatusLabel(running, tx)).toBe("On");
|
||||||
expect(channelIsRunning(unknown)).toBe(false);
|
expect(channelIsRunning(unknown)).toBe(false);
|
||||||
expect(channelToggleChecked(unknown)).toBe(false);
|
|
||||||
expect(channelStatusLabel(unknown, tx)).toBe("Not running");
|
expect(channelStatusLabel(unknown, tx)).toBe("Not running");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -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 () => {
|
it("keeps WeChat login recovery visible across transient channel refreshes", async () => {
|
||||||
const expiredFeature: NanobotFeatureInfo = {
|
const expiredFeature: NanobotFeatureInfo = {
|
||||||
name: "weixin",
|
name: "weixin",
|
||||||
@@ -808,7 +834,7 @@ describe("Settings channels", () => {
|
|||||||
renderSettingsView({ initialSection: "channels" });
|
renderSettingsView({ initialSection: "channels" });
|
||||||
|
|
||||||
expect((await screen.findAllByText("Failed")).length).toBeGreaterThan(0);
|
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" }));
|
fireEvent.click(screen.getByRole("button", { name: "Install Matrix" }));
|
||||||
|
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
@@ -858,10 +884,7 @@ describe("Settings channels", () => {
|
|||||||
fireEvent.click(await screen.findByRole("button", { name: "View Matrix settings" }));
|
fireEvent.click(await screen.findByRole("button", { name: "View Matrix settings" }));
|
||||||
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
|
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
|
||||||
expect(screen.getByText(runtimeError)).toBeInTheDocument();
|
expect(screen.getByText(runtimeError)).toBeInTheDocument();
|
||||||
expect(screen.getByLabelText("Matrix channel")).toHaveAttribute(
|
expect(screen.getByRole("switch", { name: "Enable channel" })).toBeChecked();
|
||||||
"aria-checked",
|
|
||||||
"false",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("starts Feishu connect in WebUI instead of showing a CLI command", async () => {
|
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]);
|
fireEvent.click((await screen.findAllByRole("button", { name: /^View .+ settings$/ }))[0]);
|
||||||
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
|
expect(screen.getAllByText("Failed").length).toBeGreaterThan(0);
|
||||||
expect(screen.getByText(runtimeError)).toBeInTheDocument();
|
expect(screen.getByText(runtimeError)).toBeInTheDocument();
|
||||||
expect(screen.getByRole("switch", { name: "test assistant" })).toHaveAttribute(
|
expect(screen.getByRole("switch", { name: "test assistant" })).toBeChecked();
|
||||||
"aria-checked",
|
|
||||||
"false",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves advanced field edits when collapsed and reopened with the keyboard", async () => {
|
it("preserves advanced field edits when collapsed and reopened with the keyboard", async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user