Files
Homelab-manager/web/src/pages/Servers.tsx
T
bobbanandClaude Sonnet 5.5 d69962528e Brand colours and logos for integrations and DNS providers
Kind tags (Integrations, Servers, DNS) are in the brand's colour with its logo
(Simple Icons, CC0), kept readable on both themes; the dashboard cards, the
kind picker and the menu show the logos too, with a per-browser switch for the
menu icons. Settings -> Display -> Badge colours shows the brand defaults and
Use the brand's goes back to them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 20:14:20 +01:00

713 lines
31 KiB
TypeScript

import { useCallback, useEffect, useState, type CSSProperties } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type AgentLatest, type CurrentUser, type ServerRecord } from "../api/client";
import CopyButton from "../components/CopyButton";
import { formatDateTime } from "../utils/date";
import TimeAgo from "../components/TimeAgo";
import UptimeRibbon from "../components/UptimeRibbon";
import { useSortable } from "../hooks/useSortable";
import SortableTh from "../components/SortableTh";
import { usePagination } from "../hooks/usePagination";
import Pagination from "../components/Pagination";
import { downloadCsv } from "../utils/csv";
import { TagBadges } from "../components/ServerTags";
import { AGENT_RUN_HINT, agentOsOf, installCommand, uninstallCommand, type AgentOs } from "../utils/agentCommands";
import { tagBadge, useTagColors } from "../utils/tags";
import { confirmDialog } from "../utils/dialogs";
import { ErrorNotice } from "../components/Notice";
import { toast } from "../utils/toast";
import { readableError } from "../utils/errors";
import { SearchBox } from "../components/TableToolbar";
import { useTableSearch } from "../hooks/useTableSearch";
import SaveViewButton from "../components/SaveViewButton";
import { agentState } from "../utils/agent";
import { BlockSkeleton } from "../components/Skeleton";
import EmptyState, { EmptyRow, LoadingRow } from "../components/EmptyState";
import BulkBar from "../components/BulkBar";
import { RunsOnBulkDrawer, SilenceBulkDrawer, TagBulkDrawer } from "../components/BulkDrawers";
import { doBulk, plural } from "../utils/bulk";
import { BrandTag } from "../components/BrandIcon";
export default function Servers({ user }: { user: CurrentUser }) {
const isAdmin = user.role === "admin";
const [servers, setServers] = useState<ServerRecord[]>([]);
// Until the first answer arrives there is nothing to say about "no servers", so show the page's shape instead of the empty message.
const [loaded, setLoaded] = useState(false);
const [agentLatest, setAgentLatest] = useState<AgentLatest | null>(null);
// Whether agents that are behind replace themselves (an administrator's switch).
const [autoUpdate, setAutoUpdate] = useState<boolean | null>(null);
const [error, setError] = useState<string | null>(null);
const [managingServers, setManagingServers] = useState(false);
const [integrationColors, setIntegrationColors] = useState<Record<string, string>>({});
// The active tag filter lives in the URL, so a tag chip on a server's page can link straight to "everything with this tag".
const [searchParams, setSearchParams] = useSearchParams();
const selectedTags = searchParams.getAll("tag");
// So is the status chosen ("?status=offline"), which the dashboard links to.
const statusParam = searchParams.get("status");
const status: "offline" | "online" | null = statusParam === "offline" || statusParam === "online" ? statusParam : null;
const [offlineIds, setOfflineIds] = useState<Set<number> | null>(null);
// Picking servers to compare their trends side by side.
const [comparing, setComparing] = useState(false);
const [picked, setPicked] = useState<number[]>([]);
// Picking servers to change several at once (tags, maintenance, what they run on), and which form is open.
const [selecting, setSelecting] = useState(false);
const [chosen, setChosen] = useState<Set<number>>(new Set());
const [bulkForm, setBulkForm] = useState<"tag" | "silence" | "runson" | null>(null);
const tagColors = useTagColors();
useEffect(() => {
api.servers
.summary()
.then((res) => setOfflineIds(new Set(res.offline.map((o) => o.id))))
.catch(() => {});
}, []);
useEffect(() => {
api.settings.integrationColors().then((res) => setIntegrationColors(res.integrationColors)).catch(() => {});
}, []);
const [serverName, setServerName] = useState("");
const [serverHostname, setServerHostname] = useState("");
const [serverDescription, setServerDescription] = useState("");
const [serverOs, setServerOs] = useState<AgentOs>("linux");
const [newToken, setNewToken] = useState<{ server: ServerRecord; token: string } | null>(null);
const [uninstallFor, setUninstallFor] = useState<ServerRecord | null>(null);
const [insecureAgent, setInsecureAgent] = useState(false);
const loadServers = useCallback(() => {
return api.servers
.list()
.then((res) => {
setServers(res.servers);
setAgentLatest(res.agentLatest);
setAutoUpdate(res.agentAutoUpdate);
})
.catch((err) => setError(String(err)))
.finally(() => setLoaded(true));
}, []);
useEffect(() => {
loadServers();
}, [loadServers]);
async function changeAutoUpdate(value: boolean) {
setAutoUpdate(value);
try {
await api.servers.setAgentAutoUpdate(value);
toast.success(value ? "Agents that are behind will update themselves at their next run." : "Agents will no longer update themselves.");
} catch (err) {
setAutoUpdate(!value);
toast.error(readableError(err));
}
}
async function createServer(e: React.FormEvent) {
e.preventDefault();
setError(null);
try {
const result = await api.servers.create({
name: serverName,
hostname: serverHostname || undefined,
description: serverDescription || undefined,
osType: serverOs,
});
setNewToken(result);
toast.success(`Added ${serverName}. Its install command is shown below.`);
setServerName("");
setServerHostname("");
setServerDescription("");
await loadServers();
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
}
}
async function rotateToken(id: number) {
try {
const result = await api.servers.rotateToken(id);
setNewToken(result);
await loadServers();
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
}
}
async function deleteServer(id: number) {
if (!(await confirmDialog({ title: "Remove server", message: "Remove this server and all its tracked tasks?", confirmLabel: "Remove", danger: true }))) return;
try {
await api.servers.remove(id);
toast.success("Server removed.");
await loadServers();
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
}
}
const tableSearch = useTableSearch(servers);
const { sorted: sortedServers, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
const { pageItems: serverPageItems, page: serverPage, setPage: setServerPage, pageCount: serverPageCount, totalCount: serverTotalCount } =
usePagination(sortedServers);
const tagCounts = new Map<string, number>();
for (const s of servers) for (const t of s.tags) tagCounts.set(t, (tagCounts.get(t) ?? 0) + 1);
// A tag from the URL that no server has (any more) stays listed, so it can still be switched off.
for (const t of selectedTags) if (!tagCounts.has(t)) tagCounts.set(t, 0);
const allTags = [...tagCounts.keys()].sort((a, b) => a.localeCompare(b, "sv"));
const matchesSearch = new Set((tableSearch.filtered ?? servers).map((s) => s.id));
const visibleServers = servers.filter((s) => {
if (!selectedTags.every((t) => s.tags.includes(t))) return false;
if (!matchesSearch.has(s.id)) return false;
if (status === "offline") return offlineIds?.has(s.id) ?? false;
if (status === "online") return !!s.lastSeenAt && !(offlineIds?.has(s.id) ?? false);
return true;
});
const offlineCount = servers.filter((s) => offlineIds?.has(s.id)).length;
const onlineCount = servers.filter((s) => s.lastSeenAt && !offlineIds?.has(s.id)).length;
// Change one part of the address and keep the rest (the search words, the sort).
function changeParams(change: (next: URLSearchParams) => void) {
setSearchParams(
(prev) => {
const next = new URLSearchParams(prev);
change(next);
return next;
},
{ replace: true },
);
}
function toggleTag(tag: string) {
changeParams((next) => {
const current = next.getAll("tag");
next.delete("tag");
for (const t of current.includes(tag) ? current.filter((x) => x !== tag) : [...current, tag]) next.append("tag", t);
});
}
function setStatus(value: "offline" | "online" | null) {
changeParams((next) => (value ? next.set("status", value) : next.delete("status")));
}
// Operators and administrators can change several servers at once; a viewer only looks.
const canChange = user.role === "admin" || user.role === "operator";
const MAX_COMPARE = 4;
function togglePicked(id: number) {
setPicked((prev) => (prev.includes(id) ? prev.filter((x) => x !== id) : prev.length >= MAX_COMPARE ? prev : [...prev, id]));
}
function stopComparing() {
setComparing(false);
setPicked([]);
}
function stopSelecting() {
setSelecting(false);
setChosen(new Set());
setBulkForm(null);
}
function toggleChosen(id: number) {
setChosen((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
const chosenIds = servers.filter((s) => chosen.has(s.id)).map((s) => s.id);
async function runBulk(body: Record<string, unknown>, done: (changed: number) => string): Promise<void> {
const r = await doBulk({ call: api.bulk.servers, body, done: (res) => done(res.changed), reload: () => void loadServers() });
if (r) {
setBulkForm(null);
setChosen(new Set());
}
}
const cardBody = (s: ServerRecord) => (
<div className="card-body">
<div className="d-flex align-items-center">
<div className="flex-fill">
<div className="font-weight-medium">{s.name}</div>
<div className="text-secondary small">{s.hostname ?? "no hostname reported"}</div>
</div>
{s.proxmoxIntegrationId ? (
<BrandTag kind="proxmox" custom={integrationColors.proxmox} />
) : s.lastSeenAt ? (
agentState(s, agentLatest) === "behind" ? (
<span className="badge bg-yellow-lt text-yellow" title="Its agent is older than the one this Homelab Manager would install now. Run its install command again to update it.">
Agent behind
</span>
) : (
<span className="badge bg-green-lt text-green">Agent</span>
)
) : (
<span className="badge bg-secondary-lt text-secondary">No data</span>
)}
</div>
{s.tags.length > 0 && (
<div className="d-flex flex-wrap gap-1 mt-2">
<TagBadges tags={s.tags} />
</div>
)}
<div className="text-secondary small mt-2">
{s.lastSeenAt ? <>Last seen <TimeAgo value={s.lastSeenAt} /></> : "Never reported"}
</div>
<div className="mt-2">
<UptimeRibbon kind="servers" id={s.id} name={s.name} />
</div>
</div>
);
function exportCsv() {
if (!sortedServers) return;
downloadCsv(
"servers.csv",
["Name", "Hostname", "Tags", "Token prefix", "Last seen"],
sortedServers.map((s) => [
s.name,
s.hostname ?? "",
s.tags.join(" "),
s.apiTokenPrefix,
s.lastSeenAt ? formatDateTime(new Date(s.lastSeenAt)) : "never",
]),
);
}
return (
<>
<div className="d-flex align-items-center mb-3">
<h2 className="page-title mb-0">Servers</h2>
{isAdmin && (
<button className="btn btn-outline-secondary ms-auto" onClick={() => setManagingServers((v) => !v)}>
{managingServers ? "Back to servers" : "Manage servers"}
</button>
)}
</div>
<ErrorNotice error={error} />
{isAdmin && autoUpdate !== null && servers.length > 0 && (
<div className="card mb-3">
<div className="card-body py-2">
<label className="form-check form-switch mb-0">
<input className="form-check-input" type="checkbox" checked={autoUpdate} onChange={(e) => void changeAutoUpdate(e.target.checked)} />
<span className="form-check-label">Update agents automatically</span>
</label>
<div className="text-secondary small mt-1">
An agent that is behind this app downloads the newer script from here, checks it against a checksum the server gives, and replaces itself at its next run. Off by default. An agent needs the
update code to use it (Linux version 4 or later, Windows 3 or later); an older one needs its install command run once (Manage servers).
</div>
</div>
</div>
)}
{managingServers ? (
<>
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Add a server</h3>
</div>
<form onSubmit={createServer}>
<div className="card-body row g-3">
<div className="col-md-3">
<label className="form-label">Server name</label>
<input
className="form-control"
required
placeholder="e.g. nas01"
value={serverName}
onChange={(e) => setServerName(e.target.value)}
/>
</div>
<div className="col-md-2">
<label className="form-label">Operating system</label>
<select className="form-select" value={serverOs} onChange={(e) => setServerOs(e.target.value as AgentOs)}>
<option value="linux">Linux</option>
<option value="windows">Windows</option>
</select>
</div>
<div className="col-md-3">
<label className="form-label">Hostname</label>
<input
className="form-control"
placeholder="optional"
value={serverHostname}
onChange={(e) => setServerHostname(e.target.value)}
/>
</div>
<div className="col-md-4">
<label className="form-label">Description</label>
<input
className="form-control"
placeholder="optional"
value={serverDescription}
onChange={(e) => setServerDescription(e.target.value)}
/>
</div>
</div>
<div className="card-footer">
<button type="submit" className="btn btn-primary">
Add server
</button>
</div>
</form>
</div>
{newToken && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Agent token for {newToken.server.name}</h3>
</div>
<div className="card-body">
<p className="text-secondary">This token is only shown once — copy it now.</p>
<div className="input-group mb-3">
<code className="form-control">{newToken.token}</code>
<CopyButton text={newToken.token} />
</div>
<label className="form-check mb-2">
<input
type="checkbox"
className="form-check-input"
checked={insecureAgent}
onChange={(e) => setInsecureAgent(e.target.checked)}
/>
<span className="form-check-label">
This Homelab Manager instance uses a self-signed certificate (skip TLS verification on the agent)
</span>
</label>
<p className="text-secondary">{AGENT_RUN_HINT[agentOsOf(newToken.server.osType)].install}</p>
<div className="input-group">
<pre className="form-control text-wrap mb-0">
{installCommand(agentOsOf(newToken.server.osType), window.location.origin, newToken.token, insecureAgent)}
</pre>
<CopyButton text={installCommand(agentOsOf(newToken.server.osType), window.location.origin, newToken.token, insecureAgent)} />
</div>
{agentOsOf(newToken.server.osType) === "windows" && insecureAgent && (
<div className="text-secondary small mt-2">
This form is for Windows PowerShell 5.1, the one built into Windows. In PowerShell 7 the download step needs{" "}
<code>-SkipCertificateCheck</code> instead.
</div>
)}
</div>
<div className="card-footer">
<button className="btn" onClick={() => setNewToken(null)}>
Dismiss
</button>
</div>
</div>
)}
{uninstallFor && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Uninstall agent from {uninstallFor.name}</h3>
</div>
<div className="card-body">
<p className="text-secondary">{AGENT_RUN_HINT[agentOsOf(uninstallFor.osType)].uninstall}</p>
<div className="input-group">
<pre className="form-control text-wrap mb-0">
{uninstallCommand(agentOsOf(uninstallFor.osType), window.location.origin, insecureAgent)}
</pre>
<CopyButton text={uninstallCommand(agentOsOf(uninstallFor.osType), window.location.origin, insecureAgent)} />
</div>
</div>
<div className="card-footer">
<button className="btn" onClick={() => setUninstallFor(null)}>
Dismiss
</button>
</div>
</div>
)}
<div className="card">
<div className="card-header">
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} />
<button className="btn btn-outline-secondary btn-sm ms-auto" onClick={exportCsv} disabled={servers.length === 0}>
Export CSV
</button>
</div>
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<SortableTh<ServerRecord> label="Name" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<ServerRecord>
label="Hostname"
sortKeyName="hostname"
activeKey={sortKey}
direction={sortDir}
onSort={requestSort}
/>
<th>Tags</th>
<th>Token</th>
<SortableTh<ServerRecord>
label="Last seen"
sortKeyName="lastSeenAt"
activeKey={sortKey}
direction={sortDir}
onSort={requestSort}
/>
<th>Last 30 days</th>
<th className="w-1">Actions</th>
</tr>
</thead>
<tbody>
{serverPageItems?.map((s) => (
<tr key={s.id}>
<td>
<Link to={`/servers/${s.id}`}>{s.name}</Link>
{agentState(s, agentLatest) === "behind" && (
<span className="badge bg-yellow-lt text-yellow ms-2" title="Its agent is older than the one this Homelab Manager would install now. Run its install command again to update it.">
agent behind
</span>
)}
</td>
<td>{s.hostname ?? "—"}</td>
<td>
<div className="d-flex flex-wrap gap-1">
<TagBadges tags={s.tags} />
</div>
</td>
<td className="text-secondary">{s.apiTokenPrefix}…</td>
<td>{s.lastSeenAt ? <TimeAgo value={s.lastSeenAt} /> : "never"}</td>
<td>
<UptimeRibbon kind="servers" id={s.id} name={s.name} />
</td>
<td>
<div className="btn-list flex-nowrap">
<button className="btn btn-sm" onClick={() => rotateToken(s.id)}>
Rotate token
</button>
<button className="btn btn-sm" onClick={() => setUninstallFor(s)}>
Uninstall
</button>
<button className="btn btn-sm btn-outline-danger" onClick={() => deleteServer(s.id)}>
Delete
</button>
</div>
</td>
</tr>
))}
{!loaded && <LoadingRow colSpan={7} />}
{loaded && sortedServers?.length === 0 && (
<EmptyRow colSpan={7} title="No servers yet" hint="Add a server with the form above and install its agent: it then reports its tasks, disks, memory, open ports and waiting updates." filtered={tableSearch.active ? () => tableSearch.setQuery("") : undefined} />
)}
</tbody>
</table>
</div>
<Pagination page={serverPage} pageCount={serverPageCount} totalCount={serverTotalCount} onPageChange={setServerPage} />
</div>
</>
) : !loaded ? (
<div className="card">
<div className="card-body">
<BlockSkeleton lines={4} />
</div>
</div>
) : servers.length === 0 ? (
<div className="card">
<EmptyState
title="No servers yet"
hint="Add a server and install its agent: it then reports its tasks, disks, memory, open ports and waiting updates, and the app can tell when it goes quiet."
action={isAdmin ? { label: "Add a server", onClick: () => setManagingServers(true) } : undefined}
/>
</div>
) : (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} placeholder="Search servers…" />
<div className="btn-group btn-group-sm" role="group" aria-label="Show servers that are">
<button type="button" className={`btn btn-sm ${status === null ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={status === null} onClick={() => setStatus(null)}>
All
</button>
<button type="button" className={`btn btn-sm ${status === "offline" ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={status === "offline"} onClick={() => setStatus("offline")}>
Not reporting{offlineIds ? ` (${offlineCount})` : ""}
</button>
<button type="button" className={`btn btn-sm ${status === "online" ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={status === "online"} onClick={() => setStatus("online")}>
Reporting{offlineIds ? ` (${onlineCount})` : ""}
</button>
</div>
<div className="ms-auto d-flex flex-wrap gap-2">
<SaveViewButton />
{servers.length > 1 && (
<button
type="button"
className={`btn btn-sm ${comparing ? "btn-primary" : "btn-outline-secondary"}`}
aria-pressed={comparing}
onClick={() => {
if (comparing) stopComparing();
else {
stopSelecting();
setComparing(true);
}
}}
>
Compare
</button>
)}
{canChange && (
<button
type="button"
className={`btn btn-sm ${selecting ? "btn-primary" : "btn-outline-secondary"}`}
aria-pressed={selecting}
onClick={() => {
if (selecting) stopSelecting();
else {
stopComparing();
setSelecting(true);
}
}}
>
Select
</button>
)}
</div>
</div>
{comparing && (
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2" role="status">
<span>
Pick two to {MAX_COMPARE} servers to compare their load, memory and disks side by side. {picked.length} picked.
</span>
<div className="ms-auto d-flex gap-2">
{picked.length >= 2 ? (
<Link to={`/servers/compare?ids=${picked.join(",")}`} className="btn btn-sm btn-primary">
Compare {picked.length} servers
</Link>
) : (
<button type="button" className="btn btn-sm btn-primary" disabled>
Compare
</button>
)}
<button type="button" className="btn btn-sm" onClick={stopComparing}>
Cancel
</button>
</div>
</div>
)}
{selecting && (
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2" role="status">
<span>Pick the servers to change together, then choose what to do from the bar at the foot of the page. {chosenIds.length} picked.</span>
<div className="ms-auto d-flex gap-2">
<button type="button" className="btn btn-sm" onClick={() => setChosen(new Set(visibleServers.map((s) => s.id)))} disabled={visibleServers.length === 0}>
Pick all {visibleServers.length} shown
</button>
<button type="button" className="btn btn-sm" onClick={stopSelecting}>
Done
</button>
</div>
</div>
)}
{allTags.length > 0 && (
<div className="d-flex flex-wrap align-items-center gap-1 mb-3">
<span className="text-secondary small me-1">Tags</span>
{allTags.map((tag) => {
const active = selectedTags.includes(tag);
const look = tagBadge(tag, tagColors);
return (
<button
key={tag}
type="button"
className={active ? "badge border-0 bg-primary text-white" : `${look.className} border-0`}
style={active ? undefined : look.style}
aria-pressed={active}
onClick={() => toggleTag(tag)}
>
{tag} <span className="opacity-75">· {tagCounts.get(tag)}</span>
</button>
);
})}
{selectedTags.length > 0 && (
<button type="button" className="btn btn-link btn-sm p-0 ms-1" onClick={() => changeParams((next) => next.delete("tag"))}>
Clear
</button>
)}
</div>
)}
{visibleServers.length === 0 && (
<div className="card">
<div className="card-body text-secondary">
{selectedTags.length > 0 && !status && !tableSearch.active
? `No server has ${selectedTags.length > 1 ? "all of those tags" : "that tag"}.`
: "No server matches that."}
</div>
</div>
)}
<div className="row row-cards">
{visibleServers.map((s) => (
<div className="col-sm-6 col-lg-3" key={s.id}>
{comparing ? (
<button
type="button"
className={`card card-sm text-reset text-start w-100 compare-card ${picked.includes(s.id) ? "compare-card-on" : ""}`}
aria-pressed={picked.includes(s.id)}
onClick={() => togglePicked(s.id)}
>
{cardBody(s)}
</button>
) : selecting ? (
<button
type="button"
className={`card card-sm text-reset text-start w-100 compare-card ${chosen.has(s.id) ? "compare-card-on" : ""}`}
aria-pressed={chosen.has(s.id)}
onClick={() => toggleChosen(s.id)}
>
{cardBody(s)}
</button>
) : (
<Link to={`/servers/${s.id}`} className="card card-sm text-reset text-decoration-none">
{cardBody(s)}
</Link>
)}
</div>
))}
</div>
</>
)}
{selecting && chosenIds.length > 0 && (
<>
<div className="has-bulk-bar" />
<BulkBar count={chosenIds.length} noun={chosenIds.length === 1 ? "server" : "servers"} onClear={() => setChosen(new Set())}>
<button type="button" className="btn btn-sm btn-primary" onClick={() => setBulkForm("tag")}>
Tag…
</button>
<button type="button" className="btn btn-sm" onClick={() => setBulkForm("silence")}>
Silence…
</button>
{isAdmin && (
<button type="button" className="btn btn-sm" onClick={() => setBulkForm("runson")}>
Runs on…
</button>
)}
</BulkBar>
</>
)}
{bulkForm === "tag" && (
<TagBulkDrawer
count={chosenIds.length}
tags={allTags}
onClose={() => setBulkForm(null)}
onSubmit={(v) =>
runBulk({ action: v.mode === "add" ? "add_tag" : "remove_tag", ids: chosenIds, tag: v.tag }, (n) => (v.mode === "add" ? `Tagged ${plural(n, "server")} ${v.tag}.` : `Took ${v.tag} off ${plural(n, "server")}.`))
}
/>
)}
{bulkForm === "silence" && (
<SilenceBulkDrawer
noun={chosenIds.length === 1 ? "server" : "servers"}
count={chosenIds.length}
canSilenceDependents
onClose={() => setBulkForm(null)}
onSubmit={(v) => runBulk({ action: "silence", ids: chosenIds, ...v }, (n) => `${plural(n, "server")} put under maintenance.`)}
/>
)}
{bulkForm === "runson" && (
<RunsOnBulkDrawer
count={chosenIds.length}
servers={servers.filter((s) => !chosen.has(s.id)).map((s) => ({ id: s.id, name: s.name }))}
onClose={() => setBulkForm(null)}
onSubmit={(parentServerId) => runBulk({ action: "set_parent", ids: chosenIds, parentServerId }, (n) => `${plural(n, "server")} changed.`)}
/>
)}
</>
);
}