fix(webui): offer restart in installed channel rows (NAN-334) (#6392)

* fix(webui): offer restart in installed channel rows (NAN-334)

* fix(webui): align channel restart icon and hover hint

* fix(webui): explain channel installs blocked by restart
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 17:03:02 +08:00
1 parent 08ca3b4525
commit 169062be11
17 files changed
+178 -52

No files matched your search

@@ -1,9 +1,10 @@
import { useEffect, useRef, useState } from "react";
import { Download, Loader2 } from "lucide-react";
import { Download, Loader2, RotateCcw } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ChannelFeatureAction } from "@/channel-plugins/types";
import { ToggleButton } from "@/components/ui/toggle-button";
import { HoverHint } from "@/components/ui/hover-hint";
import {
ChannelLogo,
ChannelStatusBadge,
@@ -20,15 +21,19 @@ export function ChannelCatalogRow({
showBrandLogos,
onSelect,
actionKey,
actionsDisabled = false,
restartRequired = false,
onAction,
onRestart,
isRestarting = false,
}: {
feature: NanobotFeatureInfo;
showBrandLogos: boolean;
onSelect: (connect?: boolean) => void;
actionKey: string | null;
actionsDisabled?: boolean;
restartRequired?: boolean;
onAction: ChannelFeatureAction;
onRestart?: () => void;
isRestarting?: boolean;
}) {
const { t } = useTranslation();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
@@ -39,6 +44,8 @@ export function ChannelCatalogRow({
const ownActionBusy = pendingChecked !== null || actionKey === `install:${feature.name}`;
const checked = alwaysEnabled || (pendingChecked ?? channelToggleChecked(feature));
const anyActionBusy = Boolean(actionKey);
const actionsDisabled = restartRequired || isRestarting;
const showInstallRestartHint = feature.install_supported && actionsDisabled;
const installButtonRef = useRef<HTMLButtonElement | null>(null);
const [installHint, setInstallHint] = useState(false);
@@ -96,22 +103,43 @@ export function ChannelCatalogRow({
) : null}
<div className="flex w-16 shrink-0 items-center justify-center">
{!feature.installed ? (
<Button ref={installButtonRef} type="button" variant="outline" size="icon"
className={cn(
"h-[22px] w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0",
installHint && "border-[#2997FF]/60 bg-[#2997FF]/10 text-[#087FE7] ring-2 ring-[#2997FF]/25 ring-offset-2",
)}
disabled={actionsDisabled || anyActionBusy || !feature.install_supported}
aria-label={t("settings.channels.installChannel", { name: displayName })}
onClick={() => {
setInstallHint(false);
onAction("enable", feature.name, { installOnly: true, confirmed: true });
}}>
{ownActionBusy
? <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>
</Button>
<HoverHint enabled={showInstallRestartHint}
content={t(isRestarting ? "app.system.restarting" : "settings.channels.restartBeforeInstall")}>
<span role={showInstallRestartHint ? "group" : undefined}
tabIndex={showInstallRestartHint ? 0 : undefined}
aria-label={showInstallRestartHint ? t("settings.channels.installChannel", { name: displayName }) : undefined}
className="inline-flex rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2">
<Button ref={installButtonRef} type="button" variant="outline" size="icon"
className={cn(
"h-[22px] w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0",
installHint && "border-[#2997FF]/60 bg-[#2997FF]/10 text-[#087FE7] ring-2 ring-[#2997FF]/25 ring-offset-2",
)}
disabled={actionsDisabled || anyActionBusy || !feature.install_supported}
aria-label={t("settings.channels.installChannel", { name: displayName })}
onClick={() => {
setInstallHint(false);
onAction("enable", feature.name, { installOnly: true, confirmed: true });
}}>
{ownActionBusy
? <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>
</Button>
</span>
</HoverHint>
) : feature.restart_pending ? (
<HoverHint content={t("settings.channels.restartRequired")}>
<Button type="button" variant="outline" size="icon"
className="h-[22px] w-[38px] min-w-0 shrink-0 rounded-full border-border/70 bg-background p-0"
aria-label={t("app.system.restart")}
aria-busy={isRestarting}
disabled={isRestarting || anyActionBusy || !onRestart}
onClick={onRestart}>
{isRestarting
? <Loader2 className="h-3.5 w-3.5 animate-spin" aria-hidden />
: <RotateCcw className="h-3.5 w-3.5" aria-hidden />}
</Button>
</HoverHint>
) : (
<ToggleButton checked={checked}
label={checked ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
@@ -55,6 +55,7 @@ export function ChannelsSettings({
const hasEnabledConfigurableChannels = channels.some((feature) =>
feature.enabled && !feature.capabilities?.includes("always_enabled"));
const restartRequired = requiresRestartPending || Boolean(nanobotFeatures?.requires_restart);
const hasPendingChannelRestart = channels.some((feature) => feature.restart_pending);
useLayoutEffect(() => {
if (!nanobotFeatures || filterInitializedRef.current) return;
filterInitializedRef.current = true;
@@ -120,7 +121,7 @@ export function ChannelsSettings({
]} />
</div>
{error && !selectedChannel ? <DismissibleStatusMessage message={error} isError onDismiss={onDismissStatus} /> : null}
{restartRequired ? (
{restartRequired && !hasPendingChannelRestart ? (
<RestartRequiredNotice message={t("settings.channels.restartRequired")}
onRestart={onRestart} isRestarting={isRestarting} />
) : null}
@@ -143,7 +144,8 @@ export function ChannelsSettings({
<div className="grid grid-cols-1 gap-x-4 gap-y-1 min-[640px]:grid-cols-2">
{group.channels.map((feature) => (
<ChannelCatalogRow key={feature.name} feature={feature} showBrandLogos={showBrandLogos}
actionKey={actionKey} actionsDisabled={restartRequired || Boolean(isRestarting)} onAction={onAction}
actionKey={actionKey} restartRequired={restartRequired} onAction={onAction}
onRestart={onRestart} isRestarting={isRestarting}
onSelect={(connect = false) => {
triggerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
beforeCloseRef.current = null;
+1
View File
@@ -1467,6 +1467,7 @@
"loading": "Loading channels…",
"empty": "No channels match this filter.",
"restartRequired": "Restart nanobot to apply updated channel support.",
"restartBeforeInstall": "Restart nanobot before installing another channel.",
"requires": "Requires: {{requirements}}",
"setUp": "Set up",
"setupGuide": "Setup guide",
+1
View File
@@ -1263,6 +1263,7 @@
"loading": "Cargando canales...",
"empty": "Ningún canal coincide con este filtro.",
"restartRequired": "Reinicia nanobot para aplicar el soporte de canales actualizado.",
"restartBeforeInstall": "Reinicia nanobot antes de instalar otro canal.",
"requires": "Requiere: {{requirements}}",
"setUp": "Configurar",
"setupGuide": "Guía de configuración",
+1
View File
@@ -1262,6 +1262,7 @@
"loading": "Chargement des canaux...",
"empty": "Aucun canal ne correspond à ce filtre.",
"restartRequired": "Redémarrez nanobot pour appliquer le support de canal mis à jour.",
"restartBeforeInstall": "Redémarrez nanobot avant d’installer un autre canal.",
"requires": "Requiert : {{requirements}}",
"setUp": "Configurer",
"setupGuide": "Guide de configuration",
+1
View File
@@ -1262,6 +1262,7 @@
"loading": "Memuat kanal...",
"empty": "Tidak ada kanal yang cocok dengan filter ini.",
"restartRequired": "Mulai ulang nanobot untuk menerapkan dukungan kanal yang diperbarui.",
"restartBeforeInstall": "Mulai ulang nanobot sebelum memasang kanal lain.",
"requires": "Memerlukan: {{requirements}}",
"setUp": "Siapkan",
"setupGuide": "Panduan penyiapan",
+1
View File
@@ -1262,6 +1262,7 @@
"loading": "チャンネルを読み込み中...",
"empty": "一致するチャンネルはありません。",
"restartRequired": "更新したチャンネルサポートを反映するには nanobot を再起動してください。",
"restartBeforeInstall": "別のチャンネルをインストールするには、nanobot を再起動してください。",
"requires": "必要: {{requirements}}",
"setUp": "設定",
"setupGuide": "設定ガイド",
+1
View File
@@ -1262,6 +1262,7 @@
"loading": "채널을 불러오는 중...",
"empty": "일치하는 채널이 없습니다.",
"restartRequired": "업데이트된 채널 지원을 적용하려면 nanobot을 다시 시작하세요.",
"restartBeforeInstall": "다른 채널을 설치하려면 nanobot을 다시 시작하세요.",
"requires": "필요: {{requirements}}",
"setUp": "설정",
"setupGuide": "설정 가이드",
+1
View File
@@ -1276,6 +1276,7 @@
"loading": "Carregando canais...",
"empty": "Nenhum canal corresponde a este filtro.",
"restartRequired": "Reinicie o nanobot para aplicar o suporte de canais atualizado.",
"restartBeforeInstall": "Reinicie o nanobot antes de instalar outro canal.",
"requires": "Requer: {{requirements}}",
"setUp": "Configurar",
"setupGuide": "Guia de configuração",
+1
View File
@@ -1262,6 +1262,7 @@
"loading": "Đang tải kênh...",
"empty": "Không có kênh nào phù hợp.",
"restartRequired": "Khởi động lại nanobot để áp dụng hỗ trợ kênh đã cập nhật.",
"restartBeforeInstall": "Khởi động lại nanobot trước khi cài đặt kênh khác.",
"requires": "Yêu cầu: {{requirements}}",
"setUp": "Thiết lập",
"setupGuide": "Hướng dẫn thiết lập",
+1
View File
@@ -1467,6 +1467,7 @@
"loading": "正在加载聊天平台...",
"empty": "没有匹配的聊天平台。",
"restartRequired": "重启 nanobot 以应用更新后的聊天平台支持。",
"restartBeforeInstall": "重启 nanobot 后可继续安装。",
"requires": "需要:{{requirements}}",
"setUp": "设置",
"setupGuide": "配置指南",
+1
View File
@@ -1261,6 +1261,7 @@
"loading": "正在載入通訊管道…",
"empty": "沒有符合條件的通訊管道。",
"restartRequired": "重新啟動 nanobot 以套用更新後的通訊管道支援。",
"restartBeforeInstall": "重新啟動 nanobot 後即可繼續安裝。",
"requires": "需要:{{requirements}}",
"setUp": "設定",
"setupGuide": "設定指南",
+1
View File
@@ -1115,6 +1115,7 @@ export interface NanobotFeatureInfo {
status: "enabled" | "missing_dependency" | "not_enabled" | string;
install_supported: boolean;
requires_restart: boolean;
restart_pending?: boolean;
}
export interface ChannelSetupContractField {
+51 -6
View File
@@ -456,7 +456,8 @@ describe("Settings channels", () => {
expect(screen.getByRole("button", { name: "All" })).toHaveAttribute("aria-pressed", "true");
});
it("requires a restart before enabling newly installed channel support", async () => {
it("replaces the installed channel switch with an in-row restart action", async () => {
const restart = vi.fn();
const whatsappFeature = {
name: "whatsapp",
display_name: "WhatsApp",
@@ -490,7 +491,7 @@ describe("Settings channels", () => {
finishInstall = resolve;
}));
const installedPayload = {
features: [{ ...whatsappFeature, installed: true }, weixinFeature],
features: [{ ...whatsappFeature, installed: true, restart_pending: true }, weixinFeature],
enabled_count: 0,
requires_restart: true,
last_action: {
@@ -500,7 +501,7 @@ describe("Settings channels", () => {
},
};
renderSettingsView({ initialSection: "channels" });
renderSettingsView({ initialSection: "channels", onRestart: restart });
requestMutationMock.mockResolvedValueOnce({ status: "pending", session_id: "test-link" });
expect(screen.queryByRole("switch", { name: "WhatsApp channel" })).not.toBeInTheDocument();
@@ -520,13 +521,56 @@ describe("Settings channels", () => {
);
finishInstall(installedPayload);
expect(requestMutationMock).not.toHaveBeenCalledWith("settings.channel.connect.start", expect.anything(), expect.anything());
expect(await screen.findByText("Restart nanobot to apply updated channel support.")).toBeInTheDocument();
const installedGroup = await screen.findByRole("region", { name: "Requires dependencies" });
expect(within(installedGroup).getByRole("switch", { name: "WhatsApp channel" })).toBeDisabled();
const restartButton = await within(installationGroup).findByRole("button", { name: "Restart nanobot" });
const blockedInstallHint = within(installationGroup).getByRole("group", { name: "Install WeChat" });
expect(secondInstall).toBeDisabled();
await act(async () => { blockedInstallHint.focus(); });
expect(await screen.findByRole("tooltip")).toHaveTextContent("Restart nanobot before installing another channel.");
await userEvent.setup().keyboard("{Enter}");
fireEvent.click(secondInstall);
expect(requestMutationMock).toHaveBeenCalledTimes(1);
expect(restartButton).toBeEnabled();
await act(async () => { restartButton.focus(); });
expect(await screen.findByRole("tooltip")).toHaveTextContent("Restart nanobot to apply updated channel support.");
expect(screen.queryByRole("switch", { name: "WhatsApp channel" })).not.toBeInTheDocument();
expect(restart).not.toHaveBeenCalled();
fireEvent.click(restartButton);
expect(restart).toHaveBeenCalledTimes(1);
expect(requestMutationMock.mock.calls.map(([action]) => action)).toEqual([
"settings.feature.enable",
]);
});
it("keeps a refreshed pending restart on its channel and restores switches after restart", async () => {
let restartPending = true;
const installed = { ...uninstalledConnectFeature("whatsapp"), installed: true };
const other = { ...catalogFeature("Existing", false), requires_restart: true };
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings") {
return jsonResponse({ ...settingsPayload(), requires_restart: restartPending });
}
if (url === "/api/settings/nanobot-features") {
return jsonResponse({
features: [{ ...installed, restart_pending: restartPending }, other, uninstalledConnectFeature("weixin")],
enabled_count: 0,
requires_restart: restartPending,
});
}
return jsonResponse({});
}));
renderSettingsView({ initialSection: "channels" });
const installationGroup = await screen.findByRole("region", { name: "Requires dependencies" });
expect(await within(installationGroup).findByRole("button", { name: "Restart nanobot" })).toBeEnabled();
expect(screen.getByRole("switch", { name: "Existing channel" })).toBeDisabled();
restartPending = false;
await act(async () => { fireEvent(window, new Event("focus")); });
expect(await screen.findByRole("switch", { name: "WhatsApp channel" })).toBeEnabled();
expect(screen.getByRole("switch", { name: "WhatsApp channel" })).toHaveAttribute("aria-checked", "false");
expect(screen.getByRole("switch", { name: "Existing channel" })).toBeEnabled();
expect(screen.getByRole("button", { name: "Install WeChat" })).toBeEnabled();
});
it.each([
@@ -699,6 +743,7 @@ describe("Settings channels", () => {
fireEvent.click(await screen.findByRole("button", { name: "Install WhatsApp" }));
expect(await screen.findByRole("alert")).toHaveTextContent("Package install failed");
expect(screen.getByRole("button", { name: "Install WhatsApp" })).toBeEnabled();
expect(consoleError).toHaveBeenCalledWith(
"nanobot feature action failed",
expect.objectContaining({