fix(review): sort proxy hosts by the status their upstream health gives them

The proxy hosts' status column also shows a warning when an upstream is down
(health monitor); its sort now uses the same health per host, so such hosts
sort with the warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Winnerl 2026-11-13 06:31:53 +01:00
parent 029ea5c8a6
commit 400a0aaa8a
3 changed files with 34 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import {
isVariableHost,
locationHostPart,
sortByHostStatus,
sortByHostStatusWithHealth,
} from "./HostStatus";
const row = (name: string, enabled: boolean, meta: HostMeta | null) => ({ name, original: { enabled, meta } });
@ -41,6 +42,25 @@ describe("sorting the status column", () => {
expect([...rows].sort(sortByHostStatus).map((r) => r.name)).toEqual(["error", "warning", "disabled", "online"]);
});
it("ranks a proxy host whose upstream is down as a warning, with the health of its id", () => {
const down = health([target({ locationIndex: null })]);
const rows = [
{ name: "online", original: { id: 1, enabled: true, meta: { nginxOnline: true } } },
{ name: "upstream down", original: { id: 2, enabled: true, meta: { nginxOnline: true } } },
{ name: "disabled", original: { id: 3, enabled: false, meta: null } },
];
expect([...rows].sort(sortByHostStatusWithHealth({ 2: down })).map((r) => r.name)).toEqual([
"upstream down",
"disabled",
"online",
]);
expect([...rows].sort(sortByHostStatusWithHealth(undefined)).map((r) => r.name)).toEqual([
"disabled",
"online",
"upstream down",
]);
});
it("ranks a disabled host as disabled whatever its stored status", () => {
expect(hostStatusRank(false, { nginxOnline: false })).toBe(hostStatusRank(false, null));
});

View file

@ -285,16 +285,25 @@ export const getHostStatus = (
// The order of the status column, ascending: the hosts that need attention first
const HOST_STATE_RANK: Record<HostState, number> = { error: 0, warning: 1, disabled: 2, online: 3 };
export const hostStatusRank = (enabled: boolean, meta?: HostMeta | null): number =>
HOST_STATE_RANK[getHostStatus(enabled, meta).state];
export const hostStatusRank = (enabled: boolean, meta?: HostMeta | null, health?: UpstreamHostHealth | null): number =>
HOST_STATE_RANK[getHostStatus(enabled, meta, health).state];
interface HostRow {
original: { enabled: boolean; meta?: HostMeta | null };
original: { id?: number; enabled: boolean; meta?: HostMeta | null };
}
/** sortFn of a table's status column: sorts by the status it shows, not only enabled / disabled */
export const sortByHostStatus = (a: HostRow, b: HostRow): number =>
hostStatusRank(a.original.enabled, a.original.meta) - hostStatusRank(b.original.enabled, b.original.meta);
/** sortByHostStatus() with the upstream health of each host (by id), which the proxy hosts' status shows too */
export const sortByHostStatusWithHealth =
(health?: Record<string, UpstreamHostHealth> | null) =>
(a: HostRow, b: HostRow): number => {
const rank = (row: HostRow) =>
hostStatusRank(row.original.enabled, row.original.meta, health?.[`${row.original.id}`]);
return rank(a) - rank(b);
};
/** Whether a successful save still needs the user's attention */
export const hasSaveWarnings = (meta?: HostMeta | null) =>
meta?.nginxOnline === false || getProblemLocations(meta).length > 0;

View file

@ -14,7 +14,7 @@ import {
import { type Features, features } from "src/components/Table/features";
import { TableLayout } from "src/components/Table/TableLayout";
import { intl, T } from "src/locale";
import { getProblemLocations, sortByHostStatus } from "src/modules/HostStatus";
import { getProblemLocations, sortByHostStatusWithHealth } from "src/modules/HostStatus";
import { MANAGE, PROXY_HOSTS } from "src/modules/Permissions";
// "+2 locations · 1 problem" under the main destination
@ -127,7 +127,7 @@ export default function Table({
columnHelper.accessor((row: any) => row.enabled, {
id: "enabled",
header: intl.formatMessage({ id: "column.status" }),
sortFn: sortByHostStatus,
sortFn: sortByHostStatusWithHealth(health),
cell: (info: any) => {
const row: ProxyHost = info.row.original;
return (