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