Add icons for mis-matched version and restart required

This commit is contained in:
Cooldude2606 committed 2025-04-27 22:35:00 +01:00
1 parent 47c5e0fabd
commit cf9f087cba
10 files changed
+97 -51

No files matched your search

+1 -1
View File
@@ -523,7 +523,7 @@ export default class Controller {
}
requests.push(hostConnection.send(new lib.SystemInfoRequest()));
}
requests.push(lib.gatherSystemInfo("controller", this.canRestart));
requests.push(lib.gatherSystemInfo("controller", this.canRestart, this.config.restartRequired));
const newMetrics = await Promise.all(requests);
for (const metric of newMetrics) {
this.systems.set(metric);
+1 -1
View File
@@ -798,7 +798,7 @@ export default class Host extends lib.Link {
}
async handleSystemInfoRequest() {
return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart);
return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart, this.config.restartRequired);
}
async handleHostMetricsRequest() {
+27 -17
View File
@@ -203,6 +203,8 @@ export class Config<
/** Set to true when a field in the config is changed. */
dirty = false;
/** Set to true when a 'restart required' field in the config is changed. */
restartRequired = false;
/**
* Create a new instance of the given config
@@ -272,6 +274,27 @@ export class Config<
return true;
}
/**
* Set the value of a field, while also settings the required flags and events.
* This method does not perform any validation on the value being set
*
* @param name - Name of the field to set
* @param value - The new value of the field
* @param notify - False to skip setting dirty flags and emitting events
*/
_set(name: keyof Fields & string, value: FieldValue, notify: boolean = true) {
const prev = this.fields[name];
this.fields[name] = value as any;
if (notify && !isDeepStrictEqual(value, prev)) {
const def = this.constructor.fieldDefinitions[name];
if (def.restartRequired) {
this.restartRequired = true;
}
this.dirty = true;
this.emit("fieldChanged", name, value, prev);
}
}
static jsonSchema = ConfigSchema;
static validate = libSchema.compile(this.jsonSchema as any);
@@ -391,12 +414,7 @@ export class Config<
continue;
}
let prev = this.fields[name];
this.fields[name] = value as any;
if (notify && !isDeepStrictEqual(value, prev)) {
this.dirty = true;
this.emit("fieldChanged", name, value, prev);
}
this._set(name, value, notify);
}
}
@@ -511,12 +529,7 @@ export class Config<
throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`);
}
let prev = this.fields[name];
this.fields[name] = value as Fields[Field];
if (!isDeepStrictEqual(value, prev)) {
this.dirty = true;
this.emit("fieldChanged", name, value, prev);
}
this._set(name, value);
}
/**
@@ -559,10 +572,7 @@ export class Config<
} else {
delete updated[prop];
}
this.fields[name] = updated as Fields[Field];
if (!isDeepStrictEqual(updated, prev)) {
this.dirty = true;
this.emit("fieldChanged", name, updated, prev);
}
this._set(name, updated);
}
}
@@ -250,6 +250,7 @@ export class SystemInfo {
public diskCapacity: number,
public diskAvailable: number,
public canRestart: boolean,
public restartRequired: boolean,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAtMs: number,
public isDeleted: boolean,
@@ -268,6 +269,7 @@ export class SystemInfo {
"diskCapacity": Type.Number(),
"diskAvailable": Type.Number(),
"canRestart": Type.Boolean(),
"restartRequired": Type.Boolean(),
"updatedAtMs": Type.Number(),
"isDeleted": Type.Boolean(),
});
@@ -286,6 +288,7 @@ export class SystemInfo {
json.diskCapacity,
json.diskAvailable,
json.canRestart,
json.restartRequired,
json.updatedAtMs,
json.isDeleted,
);
+2 -1
View File
@@ -134,7 +134,7 @@ function minZip<T>(a: T[], b: T[]): [T, T][] {
let previousTotalCpuMs: number[] = [];
let previousIdleCpuMs: number[] = [];
export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean) {
export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean, restartRequired: boolean) {
const cpus = os.cpus();
const currentTotalCpuMs = cpus.map(({ times }) => times.user + times.idle + times.irq + times.nice + times.sys);
const currentIdleCpuMs = cpus.map(({ times }) => times.idle);
@@ -165,6 +165,7 @@ export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean
diskCapacity,
diskAvailable,
canRestart,
restartRequired,
Date.now(),
false,
);
@@ -1,5 +1,6 @@
import React, {useContext, useState} from "react";
import { Button, Descriptions, Flex, Popconfirm, Space, Typography } from "antd";
import { Button, Descriptions, Flex, Popconfirm, Space, Tooltip, Typography } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import * as lib from "@clusterio/lib";
@@ -54,16 +55,20 @@ export default function ControllerPage() {
}
{
account.hasPermission("core.controller.restart")
&& <Button
disabled={system?.canRestart === false}
onClick={() => {
control.send(
new lib.ControllerRestartRequest()
).catch(notifyErrorHandler("Error restarting controller"));
}}
>
Restart
</Button>
&& <Tooltip title={system?.restartRequired ? "Restart Required" : null}>
<Button
disabled={system?.canRestart === false}
onClick={() => {
control.send(
new lib.ControllerRestartRequest()
).catch(notifyErrorHandler("Error restarting controller"));
}}
>
Restart
{!system?.restartRequired ? undefined
: <ExclamationCircleOutlined style={{ color: "yellow" }}/>}
</Button>
</Tooltip>
}
</Space>}
/>
+17 -12
View File
@@ -1,5 +1,6 @@
import React, { useContext, useState } from "react";
import { Descriptions, Spin, Tag, Typography, Button, Space, Modal, Popconfirm, Flex } from "antd";
import { Descriptions, Spin, Tag, Typography, Button, Space, Modal, Popconfirm, Flex, Tooltip } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import { useParams } from "react-router-dom";
import * as lib from "@clusterio/lib";
@@ -89,17 +90,21 @@ export default function HostViewPage() {
}
{
account.hasPermission("core.host.restart")
&& <Button
disabled={system?.canRestart === false}
onClick={() => {
control.sendTo(
{ hostId },
new lib.HostRestartRequest()
).catch(notifyErrorHandler("Error restarting host"));
}}
>
Restart
</Button>
&& <Tooltip title={system?.restartRequired ? "Restart Required" : null}>
<Button
disabled={system?.canRestart === false}
onClick={() => {
control.sendTo(
{ hostId },
new lib.HostRestartRequest()
).catch(notifyErrorHandler("Error restarting host"));
}}
>
Restart
{!system?.restartRequired ? undefined
: <ExclamationCircleOutlined style={{ color: "yellow" }} />}
</Button>
</Tooltip>
}
</Space>;
+18 -7
View File
@@ -1,10 +1,11 @@
import React, { useContext, useRef, useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { Button, Flex, Form, InputNumber, Modal, Progress, Switch, Table, Tag, Typography } from "antd";
import CopyOutlined from "@ant-design/icons/lib/icons/CopyOutlined";
import { Button, Flex, Form, InputNumber, Modal, Progress, Space, Switch, Table, Tag, Tooltip, Typography } from "antd";
import { ExclamationCircleOutlined, CopyOutlined } from "@ant-design/icons";
import * as lib from "@clusterio/lib";
import webUiPackage from "../../package.json";
import { useAccount } from "../model/account";
import ControlContext from "./ControlContext";
import PageHeader from "./PageHeader";
@@ -13,6 +14,7 @@ import PluginExtra from "./PluginExtra";
import {
MetricCpuRatio, MetricCpuUsed, MetricMemoryRatio, MetricMemoryUsed,
MetricDiskUsed, MetricDiskRatio,
RestartRequired,
} from "./system_metrics";
import { useHosts } from "../model/host";
import { useSystems } from "../model/system";
@@ -268,6 +270,12 @@ export default function HostsPage() {
{
title: "Version",
dataIndex: "version",
render: (_, host) => <Space>
{host.version}
{webUiPackage.version === host.version ? undefined : <Tooltip title="Version Mismatch">
<ExclamationCircleOutlined style={{ color: "yellow" }}/>
</Tooltip>}
</Space>,
sorter: (a, b) => strcmp(a.version, b.version),
},
{
@@ -278,11 +286,14 @@ export default function HostsPage() {
{
title: "Connected",
key: "connected",
render: (_, host) => <Tag
color={host.connected ? "#389e0d" : "#cf1322"}
>
{host.connected ? "Connected" : "Disconnected"}
</Tag>,
render: (_, host) => <>
<Tag
color={host.connected ? "#389e0d" : "#cf1322"}
>
{host.connected ? "Connected" : "Disconnected"}
</Tag>
<RestartRequired system={systems.get(host.id)}/>
</>,
sorter: (a, b) => Number(a.connected) - Number(b.connected),
},
]}
@@ -1,7 +1,8 @@
import React from "react";
import * as lib from "@clusterio/lib";
import { Progress } from "antd";
import { Progress, Tooltip } from "antd";
import { ReloadOutlined } from "@ant-design/icons";
export function MetricCpuRatio(props: { system?: lib.SystemInfo }) {
if (!props.system) {
@@ -53,3 +54,12 @@ export function MetricDiskUsed(props: { system?: lib.SystemInfo }) {
const capacity = lib.formatBytes(props.system.diskCapacity);
return `${used} / ${capacity}`;
}
export function RestartRequired(props: { system?: lib.SystemInfo }) {
if (!props.system || !props.system.restartRequired) {
return "";
}
return <Tooltip title="Restart Required">
<ReloadOutlined style={{ color: "yellow" }}/>
</Tooltip>;
}
+1
View File
@@ -21,6 +21,7 @@ describe("lib/data/SystemInfo", function() {
2048,
512,
false,
false,
0,
false
);