mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8acb54985c
commit
c6bc81b0df
2 files changed
+59
-14
No files matched your search
@@ -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
|
||||
</Space></Tooltip>
|
||||
),
|
||||
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 <VariableDropdownButton actions={actions} />;
|
||||
return <>
|
||||
<VariableDropdownButton actions={actions} />
|
||||
{modalContext}
|
||||
</>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<number, lib.InstanceDetails>,
|
||||
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
|
||||
</Space></Tooltip>
|
||||
),
|
||||
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(", ")}.<br />
|
||||
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 <VariableDropdownButton actions={actions} />;
|
||||
return <>
|
||||
<VariableDropdownButton actions={actions} />
|
||||
{modalContext}
|
||||
</>;
|
||||
}
|
||||
|
||||
type RevokeHostButtonProps = { host: lib.HostDetails, instances: ReadonlyMap<number, lib.InstanceDetails> };
|
||||
@@ -146,7 +173,12 @@ export default function HostViewPage() {
|
||||
}
|
||||
|
||||
let hostButtons = <Space wrap>
|
||||
<HostControlButton hostId={hostId} canRestart={system?.canRestart} restartRequired={system?.restartRequired}/>
|
||||
<HostControlButton
|
||||
hostId={hostId}
|
||||
instances={hostInstances}
|
||||
canRestart={system?.canRestart}
|
||||
restartRequired={system?.restartRequired}
|
||||
/>
|
||||
{account.hasPermission("core.host.revoke") && <RevokeHostButton host={host} instances={hostInstances} />}
|
||||
{canShowNpm && (
|
||||
<NpmButton target={{ hostId }} canRestart={system?.canRestart} disabled={!host["connected"]}/>
|
||||
|
||||
Reference in new issue
Block a user