Add saved filter views, a customisable dashboard, server comparison, row keyboard navigation and share links

- Table search, status, tag and sort live in the address; Save view pins one as a favourite.
- Dashboard cards can be moved and hidden per user (users.dashboard_layout, migration 0022).
- Compare two to four servers' load, memory or disk on one chart.
- j/k move through table rows that open a detail panel.
- Share links open a read-only wall without signing in, numbers only or with names
  (share_links, migration 0023); the wall is split into a shared view over two data sources.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-16 22:15:29 +02:00
1 parent 906220040e
commit 44e393f172
50 files changed
+6114 -258

No files matched your search

+150 -36
View File
@@ -18,6 +18,7 @@ import { ErrorNotice } from "../components/Notice";
import { toast } from "../utils/toast";
import { SearchBox } from "../components/TableToolbar";
import { useTableSearch } from "../hooks/useTableSearch";
import SaveViewButton from "../components/SaveViewButton";
function typeBadgeStyle(colors: Record<string, string>, type: string): CSSProperties {
const color = colors[type];
@@ -36,8 +37,22 @@ export default function Servers({ user }: { user: CurrentUser }) {
// 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[]>([]);
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(() => {});
}, []);
@@ -104,7 +119,7 @@ export default function Servers({ user }: { user: CurrentUser }) {
}
const tableSearch = useTableSearch(servers);
const { sorted: sortedServers, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
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);
@@ -113,13 +128,81 @@ export default function Servers({ user }: { user: CurrentUser }) {
// 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 visibleServers = servers.filter((s) => selectedTags.every((t) => s.tags.includes(t)));
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) {
const next = selectedTags.includes(tag) ? selectedTags.filter((t) => t !== tag) : [...selectedTags, tag];
setSearchParams(next.length > 0 ? { tag: next } : {}, { replace: true });
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")));
}
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([]);
}
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 ? (
<span className="badge" style={typeBadgeStyle(integrationColors, "proxmox")}>
Proxmox
</span>
) : s.lastSeenAt ? (
<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(
@@ -359,6 +442,49 @@ export default function Servers({ user }: { user: CurrentUser }) {
</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={() => (comparing ? stopComparing() : setComparing(true))}>
Compare
</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>
)}
{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>
@@ -379,7 +505,7 @@ export default function Servers({ user }: { user: CurrentUser }) {
);
})}
{selectedTags.length > 0 && (
<button type="button" className="btn btn-link btn-sm p-0 ms-1" onClick={() => setSearchParams({}, { replace: true })}>
<button type="button" className="btn btn-link btn-sm p-0 ms-1" onClick={() => changeParams((next) => next.delete("tag"))}>
Clear
</button>
)}
@@ -387,42 +513,30 @@ export default function Servers({ user }: { user: CurrentUser }) {
)}
{visibleServers.length === 0 && (
<div className="card">
<div className="card-body text-secondary">No server has {selectedTags.length > 1 ? "all of those tags" : "that tag"}.</div>
<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}>
<Link to={`/servers/${s.id}`} className="card card-sm text-reset text-decoration-none">
<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 ? (
<span className="badge" style={typeBadgeStyle(integrationColors, "proxmox")}>
Proxmox
</span>
) : s.lastSeenAt ? (
<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>
</Link>
{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>
) : (
<Link to={`/servers/${s.id}`} className="card card-sm text-reset text-decoration-none">
{cardBody(s)}
</Link>
)}
</div>
))}
</div>