From c6bc81b0df3b2fe3545a7c9a8d0bcb3badf75032 Mon Sep 17 00:00:00 2001 From: Bastiaan <17990055+bbassie@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:51:34 +0100 Subject: [PATCH] Confirm controller and host restarts in the web UI (#1214) Restart on the Controller and host pages sent the request on click. A host restart stops every running instance on it, and they stay down unless instance.auto_start is set, so one misclick takes servers offline. Both now open a confirm dialog first, and the host one names the running instances it will stop. Co-authored-by: Claude Opus 5.5 --- .../web_ui/src/components/ControllerPage.tsx | 23 +++++++-- .../web_ui/src/components/HostViewPage.tsx | 50 +++++++++++++++---- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/packages/web_ui/src/components/ControllerPage.tsx b/packages/web_ui/src/components/ControllerPage.tsx index a6ffabe0..cc064e23 100644 --- a/packages/web_ui/src/components/ControllerPage.tsx +++ b/packages/web_ui/src/components/ControllerPage.tsx @@ -1,5 +1,5 @@ import React, {useContext, useState} from "react"; -import { Descriptions, Flex, Popconfirm, Space, Tooltip, Typography } from "antd"; +import { Descriptions, Flex, Modal, Popconfirm, Space, Tooltip, Typography } from "antd"; import { ExclamationCircleOutlined } from "@ant-design/icons"; import * as lib from "@clusterio/lib"; @@ -28,6 +28,7 @@ type ControllerControlButtonProps = { canRestart?: boolean, restartRequired?: bo function ControllerControlButton({ canRestart, restartRequired }: ControllerControlButtonProps) { const account = useAccount(); const control = useContext(ControlContext); + const [modal, modalContext] = Modal.useModal(); const actions: VariableDropdownButtonProps["actions"] = []; if (account.hasPermission("core.controller.restart") && canRestart) { @@ -40,9 +41,18 @@ function ControllerControlButton({ canRestart, restartRequired }: ControllerCont ), onClick: () => { - control.send( - new lib.ControllerRestartRequest() - ).catch(notifyErrorHandler("Error restarting controller")); + modal.confirm({ + title: "Restart the controller?", + content: "Hosts and this page lose their connection until the controller is back.", + okText: "Restart", + okButtonProps: { danger: true }, + autoFocusButton: "cancel", + onOk: () => { + control.send( + new lib.ControllerRestartRequest() + ).catch(notifyErrorHandler("Error restarting controller")); + }, + }); }, }); } @@ -87,7 +97,10 @@ function ControllerControlButton({ canRestart, restartRequired }: ControllerCont }); } - return ; + return <> + + {modalContext} + ; } diff --git a/packages/web_ui/src/components/HostViewPage.tsx b/packages/web_ui/src/components/HostViewPage.tsx index 2328fce7..fef62835 100644 --- a/packages/web_ui/src/components/HostViewPage.tsx +++ b/packages/web_ui/src/components/HostViewPage.tsx @@ -1,5 +1,5 @@ import React, { useContext, useState } from "react"; -import { Descriptions, Typography, Button, Space, Popconfirm, Flex, Tooltip } from "antd"; +import { Descriptions, Typography, Button, Space, Popconfirm, Flex, Tooltip, Modal } from "antd"; import { ExclamationCircleOutlined } from "@ant-design/icons"; import { useNavigate, useParams } from "react-router-dom"; @@ -29,11 +29,17 @@ import VariableDropdownButton, { VariableDropdownButtonProps } from "./VariableD const { Title } = Typography; -type HostControlButtonProps = { hostId: number, canRestart?: boolean, restartRequired?: boolean }; +type HostControlButtonProps = { + hostId: number, + instances: ReadonlyMap, + canRestart?: boolean, + restartRequired?: boolean, +}; -function HostControlButton({ hostId, canRestart, restartRequired }: HostControlButtonProps) { +function HostControlButton({ hostId, instances, canRestart, restartRequired }: HostControlButtonProps) { const account = useAccount(); const control = useContext(ControlContext); + const [modal, modalContext] = Modal.useModal(); const actions: VariableDropdownButtonProps["actions"] = []; if (account.hasPermission("core.host.restart") && canRestart) { @@ -46,10 +52,28 @@ function HostControlButton({ hostId, canRestart, restartRequired }: HostControlB ), onClick: () => { - control.sendTo( - { hostId }, - new lib.HostRestartRequest() - ).catch(notifyErrorHandler("Error restarting host")); + const running = [...instances.values()] + .filter(instance => !["unknown", "unassigned", "stopped", "deleted"].includes(instance.status)) + .map(instance => instance.name); + modal.confirm({ + title: "Restart the host?", + content: running.length + ? <> + This stops {running.length} running {running.length === 1 ? "instance" : "instances"}: + {" "}{running.join(", ")}.
+ They stay stopped after the restart unless instance.auto_start is enabled. + + : "No instances are running on this host.", + okText: "Restart", + okButtonProps: { danger: true }, + autoFocusButton: "cancel", + onOk: () => { + control.sendTo( + { hostId }, + new lib.HostRestartRequest() + ).catch(notifyErrorHandler("Error restarting host")); + }, + }); }, }); } @@ -96,7 +120,10 @@ function HostControlButton({ hostId, canRestart, restartRequired }: HostControlB }); } - return ; + return <> + + {modalContext} + ; } type RevokeHostButtonProps = { host: lib.HostDetails, instances: ReadonlyMap }; @@ -146,7 +173,12 @@ export default function HostViewPage() { } let hostButtons = - + {account.hasPermission("core.host.revoke") && } {canShowNpm && (