UniFi: servers plugged into switches; server page in sections; My work; settings search and undo

UniFi: the controller's client list is matched to servers by IP address, so a
server is connected through a switch or access point (and port). That is a
dependency made by itself, shown on the server page, the Network devices page
and the Connections map. IP Addresses can sync the devices' addresses.

A server's page is split into Overview, Health, Network, History, Tasks and
Settings, by ?view=; alerts link to the section they are about.

My work lists what has your name on it: alerts you have, maintenance you
started (extend, end with undo) and update runs you started, with a badge.

Settings has a search box (and the command palette lists every setting).
Removing a dependency, admin link, runbook, hand-made IP address, port opening
or restore test is undone from the message instead of asked about first.

Two backup tests used a fixed date and failed as days passed; they follow the
real clock now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-20 19:35:45 +02:00
1 parent 396e074108
commit 5e26e77340
45 files changed
+6224 -194

No files matched your search

+161 -109
View File
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { Link, useParams, useSearchParams } from "react-router-dom";
import {
api,
type CurrentUser,
@@ -32,9 +32,12 @@ import ServerTaskTable, { SCHEDULE_TYPE_LABELS } from "../components/ServerTaskT
import { formatDateTime } from "../utils/date";
import { guessAdminUrl, portOptionLabel } from "../utils/adminLinkUrl";
import { confirmDialog } from "../utils/dialogs";
import { removeWithUndo } from "../utils/undoable";
import { ErrorNotice } from "../components/Notice";
import { useBreadcrumbTail } from "../utils/breadcrumb";
import { PageSkeleton } from "../components/Skeleton";
import ViewTabs from "../components/ViewTabs";
import ConnectedThrough from "../components/ConnectedThrough";
const SCHEDULE_TYPE_OPTIONS: { value: ScheduleType; label: string }[] = Object.entries(SCHEDULE_TYPE_LABELS).map(
([value, label]) => ({ value: value as ScheduleType, label }),
@@ -101,8 +104,22 @@ const emptyTaskForm = {
enabled: true,
};
/** The sections of a server's page, switched by `?view=`: what it is, how it is doing, how it is connected, how it has been, what runs on it, and how it is set up. */
const SECTIONS = [
{ key: "overview", label: "Overview" },
{ key: "health", label: "Health" },
{ key: "network", label: "Network" },
{ key: "history", label: "History" },
{ key: "tasks", label: "Tasks" },
{ key: "settings", label: "Settings" },
] as const;
type SectionKey = (typeof SECTIONS)[number]["key"];
export default function ServerDetail({ user }: { user: CurrentUser }) {
const { id } = useParams<{ id: string }>();
const [searchParams] = useSearchParams();
const requested = searchParams.get("view");
const view: SectionKey = SECTIONS.some((t) => t.key === requested) ? (requested as SectionKey) : "overview";
const serverId = Number(id);
const isAdmin = user.role === "admin";
const canEditTasks = user.role === "admin" || user.role === "operator";
@@ -349,13 +366,13 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
}
async function removeAdminLink(link: ServerLink) {
if (!(await confirmDialog({ title: "Remove admin link", message: `Remove the "${link.label}" link?`, confirmLabel: "Remove", danger: true }))) return;
try {
await api.servers.removeLink(serverId, link.id);
await loadDetail();
} catch (err) {
setAdminLinkError(err instanceof Error ? err.message : String(err));
}
await removeWithUndo({
remove: () => api.servers.removeLink(serverId, link.id),
restore: () => api.servers.addLink(serverId, { label: link.label, url: link.url }),
message: `Removed the "${link.label}" link.`,
reload: () => void loadDetail(),
onError: setAdminLinkError,
});
}
if (loading) return <PageSkeleton />;
@@ -418,6 +435,13 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
onSaved={(tags) => setDetail((d) => (d ? { ...d, server: { ...d.server, tags } } : d))}
/>
<ViewTabs
label="Sections of this server's page"
tabs={SECTIONS.map((t) => ({ to: t.key === "overview" ? `/servers/${serverId}` : `/servers/${serverId}?view=${t.key}`, label: t.key === "tasks" && tasks && tasks.length > 0 ? `Tasks (${tasks.length})` : t.label, active: view === t.key }))}
/>
{view === "overview" && (
<>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Admin Links</h3>
@@ -510,91 +534,6 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
</div>
{isAdmin && (server.proxmoxIntegrationId || !server.hideProxmoxLink) ? (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Proxmox link</h3>
{!server.proxmoxIntegrationId && (
<div className="card-actions">
<button className="btn btn-link btn-sm p-0" onClick={() => toggleHideProxmoxLink(true)}>
Not a VM? Hide this
</button>
</div>
)}
</div>
<div className="card-body">
{server.proxmoxIntegrationId ? (
<div className="d-flex align-items-center gap-3">
<span className="text-secondary">
Linked to {hardware.integrationName ?? "a Proxmox integration"} — {server.proxmoxGuestType}/{server.proxmoxVmid} on{" "}
{server.proxmoxNode}
</span>
<button className="btn btn-outline-danger btn-sm ms-auto" onClick={unlinkProxmox} disabled={linking}>
Unlink
</button>
</div>
) : (proxmoxIntegrations?.length ?? 0) === 0 ? (
<div className="text-secondary">No enabled Proxmox integrations configured yet.</div>
) : (
<div className="row g-2 align-items-end">
<div className="col-md-4">
<label className="form-label">Proxmox integration</label>
<select
className="form-select"
value={pickedIntegrationId ?? ""}
onChange={(e) => {
setPickedIntegrationId(e.target.value ? Number(e.target.value) : null);
setPickedGuestKey("");
}}
>
<option value="">Choose…</option>
{proxmoxIntegrations?.map((i) => (
<option key={i.id} value={i.id}>
{i.name}
</option>
))}
</select>
</div>
<div className="col-md-5">
<label className="form-label">VM / LXC</label>
<select
className="form-select"
value={pickedGuestKey}
disabled={!proxmoxGuests}
onChange={(e) => setPickedGuestKey(e.target.value)}
>
<option value="">Choose…</option>
{proxmoxGuests?.map((g) => (
<option key={`${g.node}/${g.type}/${g.vmid}`} value={`${g.node}/${g.type}/${g.vmid}`}>
{g.name} ({g.type} #{g.vmid} on {g.node})
</option>
))}
</select>
</div>
<div className="col-md-3">
<button className="btn btn-primary w-100" onClick={linkProxmox} disabled={linking || !pickedGuestKey}>
{linking ? "Linking…" : "Link"}
</button>
</div>
{linkError && (
<div className="col-12">
<div className="alert alert-danger mb-0 mt-2">{linkError}</div>
</div>
)}
</div>
)}
</div>
</div>
) : (
isAdmin && (
<div className="mb-3">
<button className="btn btn-link btn-sm p-0" onClick={() => toggleHideProxmoxLink(false)}>
+ Show Proxmox link options
</button>
</div>
)
)}
<div className="row row-cards mb-3">
<div className="col-lg-7">
<div className="card h-100">
@@ -604,7 +543,7 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
<div className="card-body">
{hardware.source === "none" && (
<div className="text-secondary">
No hardware data yet. Install the agent on this server, or link it to a Proxmox VM/LXC above.
No hardware data yet. Install the agent on this server, or link it to a Proxmox VM/LXC (under Settings).
</div>
)}
{hardware.error && <div className="alert alert-danger">{hardware.error}</div>}
@@ -812,6 +751,19 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
</div>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Runbooks</h3>
</div>
<div className="card-body">
<RunbookPanel targetType="server" targetId={server.id} targetName={server.name} canEdit={canEditTasks} />
</div>
</div>
</>
)}
{view === "health" && (
<>
<HostHealthCard
health={server.hostHealth}
ignored={server.thresholds?.ignoreServices ?? []}
@@ -831,17 +783,30 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
}
/>
<AgentDiagnostics notes={detail.diagnostics ?? []} />
</>
)}
{view === "network" && (
<>
<ConnectedThrough serverId={serverId} />
<ServerPorts
serverId={serverId}
addresses={[...ipAddresses, ...(server.hostname && !ipAddresses.includes(server.hostname) ? [server.hostname] : [])]}
canEdit={canEditTasks}
/>
</>
)}
{view === "history" && (
<>
{hardware.source === "agent" && <ServerTrends serverId={serverId} />}
<ServerThresholds key={JSON.stringify(server.thresholds)} server={server} defaults={detail.thresholdDefaults} disks={(hardware.disks ?? []).map((d) => d.mount)} canEdit={isAdmin} onChanged={() => void loadDetail()} />
{(user.role === "admin" || user.role === "operator") && <ServerActivity serverId={serverId} />}
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Runbooks</h3>
</div>
<div className="card-body">
<RunbookPanel targetType="server" targetId={server.id} targetName={server.name} canEdit={canEditTasks} />
</div>
</div>
</>
)}
{view === "tasks" && (
<>
{canEditTasks && (
<div className="card mb-3">
<div className="card-header">
@@ -853,12 +818,6 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
)}
<ServerPorts
serverId={serverId}
addresses={[...ipAddresses, ...(server.hostname && !ipAddresses.includes(server.hostname) ? [server.hostname] : [])]}
canEdit={canEditTasks}
/>
<div className="d-flex align-items-center mb-3">
<h3 className="mb-0">Tasks</h3>
{canEditTasks && (
@@ -956,6 +915,99 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
<ServerTaskTable tasks={tasks} canEditTasks={canEditTasks} onEdit={openEditTask} onDelete={deleteTask} />
)}
</div>
</>
)}
{view === "settings" && (
<>
{isAdmin && (server.proxmoxIntegrationId || !server.hideProxmoxLink) ? (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Proxmox link</h3>
{!server.proxmoxIntegrationId && (
<div className="card-actions">
<button className="btn btn-link btn-sm p-0" onClick={() => toggleHideProxmoxLink(true)}>
Not a VM? Hide this
</button>
</div>
)}
</div>
<div className="card-body">
{server.proxmoxIntegrationId ? (
<div className="d-flex align-items-center gap-3">
<span className="text-secondary">
Linked to {hardware.integrationName ?? "a Proxmox integration"} — {server.proxmoxGuestType}/{server.proxmoxVmid} on{" "}
{server.proxmoxNode}
</span>
<button className="btn btn-outline-danger btn-sm ms-auto" onClick={unlinkProxmox} disabled={linking}>
Unlink
</button>
</div>
) : (proxmoxIntegrations?.length ?? 0) === 0 ? (
<div className="text-secondary">No enabled Proxmox integrations configured yet.</div>
) : (
<div className="row g-2 align-items-end">
<div className="col-md-4">
<label className="form-label">Proxmox integration</label>
<select
className="form-select"
value={pickedIntegrationId ?? ""}
onChange={(e) => {
setPickedIntegrationId(e.target.value ? Number(e.target.value) : null);
setPickedGuestKey("");
}}
>
<option value="">Choose…</option>
{proxmoxIntegrations?.map((i) => (
<option key={i.id} value={i.id}>
{i.name}
</option>
))}
</select>
</div>
<div className="col-md-5">
<label className="form-label">VM / LXC</label>
<select
className="form-select"
value={pickedGuestKey}
disabled={!proxmoxGuests}
onChange={(e) => setPickedGuestKey(e.target.value)}
>
<option value="">Choose…</option>
{proxmoxGuests?.map((g) => (
<option key={`${g.node}/${g.type}/${g.vmid}`} value={`${g.node}/${g.type}/${g.vmid}`}>
{g.name} ({g.type} #{g.vmid} on {g.node})
</option>
))}
</select>
</div>
<div className="col-md-3">
<button className="btn btn-primary w-100" onClick={linkProxmox} disabled={linking || !pickedGuestKey}>
{linking ? "Linking…" : "Link"}
</button>
</div>
{linkError && (
<div className="col-12">
<div className="alert alert-danger mb-0 mt-2">{linkError}</div>
</div>
)}
</div>
)}
</div>
</div>
) : (
isAdmin && (
<div className="mb-3">
<button className="btn btn-link btn-sm p-0" onClick={() => toggleHideProxmoxLink(false)}>
+ Show Proxmox link options
</button>
</div>
)
)}
<ServerThresholds key={JSON.stringify(server.thresholds)} server={server} defaults={detail.thresholdDefaults} disks={(hardware.disks ?? []).map((d) => d.mount)} canEdit={isAdmin} onChanged={() => void loadDetail()} />
</>
)}
</>
);
}