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:
1 parent
906220040e
commit
44e393f172
50 files changed
+6114
-258
No files matched your search
@@ -54,7 +54,7 @@ export default function AuditLog() {
|
||||
}, []);
|
||||
|
||||
const tableSearch = useTableSearch(entries);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "createdAt", "desc");
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "createdAt", "desc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
|
||||
function exportCsv() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { IconArrowLeft, IconArrowRight, IconEye, IconEyeOff } from "@tabler/icons-react";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import WhatChanged from "../components/WhatChanged";
|
||||
import { UNPLACED, moveCard, resetDashboardLayout, setCardHidden, setEditingDashboard, useDashboardLayout } from "../utils/dashboardLayout";
|
||||
import { Link } from "react-router-dom";
|
||||
import {
|
||||
api,
|
||||
@@ -187,10 +189,30 @@ function MiniStat({ label, value, accent }: { label: string; value: ReactNode; a
|
||||
|
||||
/** The single card shape shared by every dashboard widget — DNS, Secrets, and each integration — so they all read as one family: a label + status badge, then whatever stats/breakdown that widget has. */
|
||||
function WidgetCard({ label, badge, hide, children }: { label: string; badge?: ReactNode; /** Nothing is set up for this yet: it is listed under "Not set up yet" instead of taking a card. */ hide?: boolean; children: ReactNode }) {
|
||||
const { layout, editing } = useDashboardLayout();
|
||||
if (hide) return null;
|
||||
// The person's own arrangement: cards they hid are gone (shown dimmed while arranging, so they can be brought back), and the
|
||||
// rest follow the order they chose — a card nobody has placed goes last, in the order it was drawn.
|
||||
const hidden = layout.hidden.includes(label);
|
||||
if (hidden && !editing) return null;
|
||||
return (
|
||||
<div className="col-md-6">
|
||||
<div className="card h-100">
|
||||
<div className="col-md-6" data-card={label} style={{ order: layout.order[label] ?? UNPLACED }}>
|
||||
<div className={`card h-100 ${hidden ? "card-hidden" : ""}`}>
|
||||
{editing && (
|
||||
<div className="card-customise">
|
||||
<button type="button" className="btn btn-sm btn-icon" aria-label={`Move ${label} earlier`} title="Move earlier" onClick={(e) => void moveCard(e.currentTarget.closest<HTMLElement>("[data-card]")!, -1)}>
|
||||
<IconArrowLeft size={16} aria-hidden="true" />
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-icon" aria-label={`Move ${label} later`} title="Move later" onClick={(e) => void moveCard(e.currentTarget.closest<HTMLElement>("[data-card]")!, 1)}>
|
||||
<IconArrowRight size={16} aria-hidden="true" />
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm ms-auto d-inline-flex align-items-center gap-1" aria-pressed={hidden} onClick={() => void setCardHidden(label, !hidden)}>
|
||||
{hidden ? <IconEye size={16} aria-hidden="true" /> : <IconEyeOff size={16} aria-hidden="true" />}
|
||||
{hidden ? "Show" : "Hide"}
|
||||
<span className="visually-hidden"> {label}</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="card-body">
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<div className="subheader">{label}</div>
|
||||
@@ -291,6 +313,7 @@ function formatBytes(bytes: number | null): string {
|
||||
}
|
||||
|
||||
export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
const { editing } = useDashboardLayout();
|
||||
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
||||
const [tailscaleSummary, setTailscaleSummary] = useState<TailscaleDevicesResponse["summary"] | null>(null);
|
||||
const [tailscaleExtra, setTailscaleExtra] = useState<TailscaleExtra | null>(null);
|
||||
@@ -588,10 +611,23 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
<div className="col-12">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
|
||||
<h2 className="page-title mb-0">Dashboard</h2>
|
||||
<Link to="/wall" className="btn btn-sm btn-outline-secondary ms-auto" title="A full-screen status board for a spare monitor or tablet">
|
||||
Wall display
|
||||
</Link>
|
||||
<div className="ms-auto d-flex gap-2">
|
||||
<button type="button" className={`btn btn-sm ${editing ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={editing} onClick={() => setEditingDashboard(!editing)}>
|
||||
{editing ? "Done" : "Customise"}
|
||||
</button>
|
||||
<Link to="/wall" className="btn btn-sm btn-outline-secondary" title="A full-screen status board for a spare monitor or tablet">
|
||||
Wall display
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
{editing && (
|
||||
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2" role="status">
|
||||
<span>Move the cards with the arrows and hide the ones you don't use. It saves as you go, for you only, and follows you to other browsers.</span>
|
||||
<button type="button" className="btn btn-sm ms-auto" onClick={() => void resetDashboardLayout()}>
|
||||
Reset to default
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-secondary">
|
||||
Welcome back, {user.name ?? user.email ?? user.sub}.
|
||||
</p>
|
||||
@@ -760,7 +796,12 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
{serverSummary.offline.length > 3 && <span className="text-secondary"> +{serverSummary.offline.length - 3} more</span>}
|
||||
{serverSummary.offline.length > 3 && (
|
||||
<>
|
||||
{" "}
|
||||
<Link to="/servers?status=offline">+{serverSummary.offline.length - 3} more</Link>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{serverSummary.fullDisks.length > 0 && (
|
||||
|
||||
@@ -98,7 +98,7 @@ export default function Docker({ user }: { user: CurrentUser }) {
|
||||
const filteredContainers = (data?.containers ?? []).filter((c) => !hostFilter || c.environmentName === hostFilter);
|
||||
|
||||
const tableSearch = useTableSearch(filteredContainers);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
const detail = useRowDetail<NonNullable<typeof pageItems>[number]>();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function Domains({ user }: { user: CurrentUser }) {
|
||||
}, []);
|
||||
|
||||
const tableSearch = useTableSearch(data?.domains);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "expiresAt");
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "expiresAt", "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
|
||||
async function add(e: React.FormEvent) {
|
||||
|
||||
@@ -99,7 +99,7 @@ export default function Gitea({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(repos);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
const detail = useRowDetail<NonNullable<typeof pageItems>[number]>();
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ function typeBadgeStyle(colors: Record<string, string>, type: IntegrationType):
|
||||
|
||||
export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
const isAdmin = user.role === "admin";
|
||||
const [searchParams] = useSearchParams();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
@@ -137,7 +137,12 @@ export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(integrations);
|
||||
const sortedIntegrations = tableSearch.filtered ? [...tableSearch.filtered].sort((a, b) => a.name.localeCompare(b.name)) : null;
|
||||
const statusParam = searchParams.get("status");
|
||||
const statusFilter = statusParam === "failing" || statusParam === "working" || statusParam === "disabled" ? statusParam : "";
|
||||
const matchesStatus = (i: IntegrationSummary) =>
|
||||
statusFilter === "" ||
|
||||
(statusFilter === "disabled" ? !i.enabled : statusFilter === "failing" ? i.enabled && i.health?.status === "failing" : i.enabled && i.health?.status === "ok");
|
||||
const sortedIntegrations = tableSearch.filtered ? [...tableSearch.filtered].filter(matchesStatus).sort((a, b) => a.name.localeCompare(b.name)) : null;
|
||||
|
||||
function exportCsv() {
|
||||
if (!sortedIntegrations) return;
|
||||
@@ -192,6 +197,29 @@ export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
search={tableSearch.query}
|
||||
onSearch={tableSearch.setQuery}
|
||||
placeholder="Search integrations…"
|
||||
filters={
|
||||
<select
|
||||
className="form-select form-select-sm w-auto"
|
||||
aria-label="Show integrations that are"
|
||||
value={statusFilter}
|
||||
onChange={(e) =>
|
||||
setSearchParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (e.target.value) next.set("status", e.target.value);
|
||||
else next.delete("status");
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Any status</option>
|
||||
<option value="failing">Failing</option>
|
||||
<option value="working">Working</option>
|
||||
<option value="disabled">Disabled</option>
|
||||
</select>
|
||||
}
|
||||
shown={sortedIntegrations?.length}
|
||||
total={integrations?.length}
|
||||
onExport={exportCsv}
|
||||
@@ -262,8 +290,8 @@ export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary text-center">
|
||||
{tableSearch.active ? "Nothing matches that search." : "No integrations configured yet."}
|
||||
{isAdmin && !tableSearch.active && (
|
||||
{tableSearch.active || statusFilter ? "Nothing matches that." : "No integrations configured yet."}
|
||||
{isAdmin && !tableSearch.active && !statusFilter && (
|
||||
<>
|
||||
{" "}
|
||||
<button className="btn btn-link p-0 align-baseline" onClick={() => setAdding(true)}>
|
||||
|
||||
@@ -62,7 +62,7 @@ export default function OsTicket({ user: _user }: { user: CurrentUser }) {
|
||||
}, [selectedId]);
|
||||
|
||||
const tableSearch = useTableSearch(data?.tickets);
|
||||
const { sorted: sortedTickets, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted: sortedTickets, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
|
||||
function exportCsv() {
|
||||
if (!sortedTickets) return;
|
||||
|
||||
@@ -199,7 +199,7 @@ export default function Proxmox({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(data?.guests);
|
||||
const { sorted: sortedGuests, sortKey: guestSortKey, sortDir: guestSortDir, requestSort: requestGuestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted: sortedGuests, sortKey: guestSortKey, sortDir: guestSortDir, requestSort: requestGuestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
const { pageItems: guestPageItems, page: guestPage, setPage: setGuestPage, pageCount: guestPageCount, totalCount: guestTotalCount } =
|
||||
usePagination(sortedGuests);
|
||||
const detail = useRowDetail<NonNullable<typeof guestPageItems>[number]>();
|
||||
|
||||
@@ -107,7 +107,7 @@ export default function Semaphore({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(data?.templates);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
const detail = useRowDetail<NonNullable<typeof pageItems>[number]>();
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type ServerMetricSeries, type ServerRecord } from "../api/client";
|
||||
import MultiLineChart, { type ChartSeries } from "../components/MultiLineChart";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
|
||||
const MAX_SERVERS = 4;
|
||||
const RANGES = [
|
||||
{ days: 1, label: "24 hours" },
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
];
|
||||
// A colour and a dash pattern for each line, so they can be told apart by either.
|
||||
const LOOKS = [
|
||||
{ color: "#4299e1", dash: "" },
|
||||
{ color: "#f59f00", dash: "7 4" },
|
||||
{ color: "#2fb344", dash: "2 4" },
|
||||
{ color: "#ae3ec9", dash: "9 3 2 3" },
|
||||
];
|
||||
|
||||
interface Loaded {
|
||||
server: ServerRecord;
|
||||
series: ServerMetricSeries[] | null;
|
||||
}
|
||||
|
||||
function percent(v: number | null | undefined): string {
|
||||
return v === null || v === undefined ? "—" : `${Math.round(v)}%`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two to four servers' load, memory or a disk on one chart, so "which of them is the busy one" and "did they spike together" are
|
||||
* answered at a glance. Uses the same history as each server's own Trends card; servers without an agent have none to draw.
|
||||
*/
|
||||
export default function ServerCompare() {
|
||||
const [params] = useSearchParams();
|
||||
const ids = useMemo(() => {
|
||||
const seen = new Set<number>();
|
||||
for (const part of (params.get("ids") ?? "").split(",")) {
|
||||
const n = Number(part);
|
||||
if (Number.isInteger(n) && n > 0) seen.add(n);
|
||||
}
|
||||
return [...seen].slice(0, MAX_SERVERS);
|
||||
}, [params]);
|
||||
|
||||
const [days, setDays] = useState(7);
|
||||
const [metric, setMetric] = useState("cpu");
|
||||
const [loaded, setLoaded] = useState<Loaded[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [to, setTo] = useState(() => Date.now());
|
||||
|
||||
useEffect(() => {
|
||||
if (ids.length < 2) return;
|
||||
let alive = true;
|
||||
setFailed(false);
|
||||
setLoaded(null);
|
||||
Promise.all([api.servers.list(), ...ids.map((id) => api.servers.metrics(id, days).catch(() => null))])
|
||||
.then(([list, ...metrics]) => {
|
||||
if (!alive) return;
|
||||
const byId = new Map((list as { servers: ServerRecord[] }).servers.map((s) => [s.id, s]));
|
||||
setTo(Date.now());
|
||||
setLoaded(
|
||||
ids.flatMap((id, i) => {
|
||||
const server = byId.get(id);
|
||||
const m = metrics[i] as { series: ServerMetricSeries[] } | null;
|
||||
return server ? [{ server, series: m ? m.series : null }] : [];
|
||||
}),
|
||||
);
|
||||
})
|
||||
.catch(() => alive && setFailed(true));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [ids, days]);
|
||||
|
||||
// Every measure at least one of them has: load, memory, and each disk by its mount.
|
||||
const metrics = useMemo(() => {
|
||||
const found = new Map<string, string>([
|
||||
["cpu", "CPU load"],
|
||||
["mem", "Memory"],
|
||||
]);
|
||||
for (const l of loaded ?? []) for (const s of l.series ?? []) if (s.kind === "disk") found.set(s.metric, s.label);
|
||||
return [...found.entries()];
|
||||
}, [loaded]);
|
||||
const metricName = metrics.find(([key]) => key === metric)?.[1] ?? "CPU load";
|
||||
|
||||
const rows = (loaded ?? []).map((l, i) => {
|
||||
const s = l.series?.find((x) => x.metric === metric) ?? null;
|
||||
const values = s?.points.map((p) => p.v) ?? [];
|
||||
return {
|
||||
server: l.server,
|
||||
look: LOOKS[i % LOOKS.length],
|
||||
series: s,
|
||||
now: s?.latest ?? null,
|
||||
average: values.length ? values.reduce((a, b) => a + b, 0) / values.length : null,
|
||||
peak: values.length ? Math.max(...values) : null,
|
||||
hasAgent: l.series !== null,
|
||||
};
|
||||
});
|
||||
const chart: ChartSeries[] = rows.filter((r) => r.series).map((r) => ({ name: r.server.name, color: r.look.color, dash: r.look.dash, points: r.series!.points }));
|
||||
const summary = `${metricName} over the last ${RANGES.find((r) => r.days === days)?.label}: ${rows.map((r) => `${r.server.name} ${percent(r.now)} now`).join(", ")}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
|
||||
<h2 className="page-title mb-0">Compare servers</h2>
|
||||
<Link to="/servers" className="btn btn-sm btn-outline-secondary ms-auto">
|
||||
Pick different servers
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{ids.length < 2 ? (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary">
|
||||
Pick two to {MAX_SERVERS} servers to compare. On the <Link to="/servers">Servers</Link> page, press Compare and choose them.
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header d-flex flex-wrap gap-2">
|
||||
<h3 className="card-title me-auto">{metricName}</h3>
|
||||
<select className="form-select form-select-sm w-auto" aria-label="What to compare" value={metric} onChange={(e) => setMetric(e.target.value)}>
|
||||
{metrics.map(([key, name]) => (
|
||||
<option key={key} value={key}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select className="form-select form-select-sm w-auto" aria-label="Time range" value={days} onChange={(e) => setDays(Number(e.target.value))}>
|
||||
{RANGES.map((r) => (
|
||||
<option key={r.days} value={r.days}>
|
||||
Last {r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{failed ? (
|
||||
<div className="text-secondary">Couldn't load the history.</div>
|
||||
) : loaded === null ? (
|
||||
<BlockSkeleton lines={5} />
|
||||
) : (
|
||||
<>
|
||||
{chart.length === 0 ? (
|
||||
<div className="text-secondary mb-3">None of these servers has a history for this yet. A sample is kept about every ten minutes once an agent has reported.</div>
|
||||
) : (
|
||||
<MultiLineChart series={chart} from={to - days * 86_400_000} to={to} label={summary} />
|
||||
)}
|
||||
<div className="table-responsive mt-3">
|
||||
<table className="table table-vcenter">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th>Now</th>
|
||||
<th>Average</th>
|
||||
<th>Peak</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.server.id}>
|
||||
<td>
|
||||
<svg width="34" height="10" aria-hidden="true" className="me-2">
|
||||
<line x1="1" x2="33" y1="5" y2="5" stroke={r.look.color} strokeWidth="3" strokeDasharray={r.look.dash || undefined} strokeLinecap="round" />
|
||||
</svg>
|
||||
<Link to={`/servers/${r.server.id}`}>{r.server.name}</Link>
|
||||
</td>
|
||||
{r.series ? (
|
||||
<>
|
||||
<td>{percent(r.now)}</td>
|
||||
<td>{percent(r.average)}</td>
|
||||
<td>{percent(r.peak)}</td>
|
||||
</>
|
||||
) : (
|
||||
<td colSpan={3} className="text-secondary">
|
||||
{r.hasAgent ? "No history for this" : "No agent history (not reported by an agent)"}
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
+150
-36
@@ -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>
|
||||
|
||||
@@ -77,7 +77,7 @@ export default function Sessions() {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(sessions);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
|
||||
@@ -8,6 +8,7 @@ const SUB_NAV = [
|
||||
{ to: "/settings/tags", label: "Tags" },
|
||||
{ to: "/settings/alert-tickets", label: "Alert tickets" },
|
||||
{ to: "/settings/names", label: "Names" },
|
||||
{ to: "/settings/share", label: "Share links" },
|
||||
{ to: "/settings/cache", label: "Cache" },
|
||||
{ to: "/settings/logs", label: "Logs" },
|
||||
{ to: "/settings/backup", label: "Backup" },
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { api, type PublicWall } from "../api/client";
|
||||
import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView";
|
||||
import { setDateTimeSettings } from "../utils/date";
|
||||
|
||||
/**
|
||||
* The wall display behind a share link: the same board, read-only and without signing in. The address carries the secret, and the
|
||||
* server decides how much it may show — this only draws what comes back. A link that doesn't work (never made, ended, taken back)
|
||||
* says so and stops asking.
|
||||
*/
|
||||
export default function SharedWall() {
|
||||
const { token = "" } = useParams();
|
||||
const [wall, setWall] = useState<PublicWall | null>(null);
|
||||
const [state, setState] = useState<"loading" | "ok" | "dead" | "unreachable">("loading");
|
||||
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
||||
const [idle, setIdle] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
const load = () =>
|
||||
api.publicWall
|
||||
.get(token)
|
||||
.then((w) => {
|
||||
if (!alive) return;
|
||||
setDateTimeSettings({ dateFormat: w.display.dateFormat as "ymd" | "dmy" | "mdy", timeFormat: w.display.timeFormat as "24h" | "12h" });
|
||||
setWall(w);
|
||||
setUpdatedAt(new Date());
|
||||
setState("ok");
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (!alive) return;
|
||||
const status = (err as { status?: number }).status;
|
||||
if (status === 404 || status === 429) {
|
||||
// 404: this link doesn't work (any more). Asking again would only repeat that.
|
||||
if (status === 404) {
|
||||
setState("dead");
|
||||
if (timer) clearInterval(timer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
setState((s) => (s === "ok" ? "ok" : "unreachable"));
|
||||
});
|
||||
void load();
|
||||
timer = setInterval(load, REFRESH_MS);
|
||||
return () => {
|
||||
alive = false;
|
||||
if (timer) clearInterval(timer);
|
||||
};
|
||||
}, [token]);
|
||||
|
||||
// The pointer hides itself when nobody is using it.
|
||||
useEffect(() => {
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
const onMove = () => {
|
||||
setIdle(false);
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => setIdle(true), 5000);
|
||||
};
|
||||
onMove();
|
||||
window.addEventListener("mousemove", onMove);
|
||||
return () => {
|
||||
window.removeEventListener("mousemove", onMove);
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (state === "dead") {
|
||||
return (
|
||||
<div className="wall" data-bs-theme="dark">
|
||||
<section className="wall-status wall-status-unsure" role="alert">
|
||||
<span className="wall-status-symbol" aria-hidden="true">
|
||||
?
|
||||
</span>
|
||||
<span>This link doesn't work any more</span>
|
||||
</section>
|
||||
<div className="wall-empty">It may have ended or been taken back. Ask whoever gave it to you for a new one.</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const count = wall ? wall.alerts.critical + wall.alerts.warning : 0;
|
||||
const data: WallData = {
|
||||
level: wall?.level ?? "unsure",
|
||||
headline: wallHeadline(wall?.level ?? "unsure", count, { loaded: !!wall, failed: state === "unreachable" }),
|
||||
servers: wall ? { online: wall.servers.online, total: wall.servers.online + wall.servers.offline } : null,
|
||||
alerts: wall ? wall.alerts : null,
|
||||
maintenance: wall?.maintenance ?? 0,
|
||||
integrationsFailing: wall ? wall.integrationsFailing : null,
|
||||
problems: wall?.problems ?? null,
|
||||
windows: wall?.maintenanceWindows ?? null,
|
||||
integrations: (wall?.integrations as WallData["integrations"]) ?? null,
|
||||
environmentName: wall?.environment ?? null,
|
||||
updatedAt,
|
||||
};
|
||||
|
||||
return (
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
footerActions={
|
||||
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
||||
Full screen
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ export default function Tailscale({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(data?.devices);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
const detail = useRowDetail<NonNullable<typeof pageItems>[number]>();
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ export default function UptimeKuma({ user: _user }: { user: CurrentUser }) {
|
||||
}, [selectedId]);
|
||||
|
||||
const tableSearch = useTableSearch(data?.monitors);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "name");
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "name", "asc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
const detail = useRowDetail<NonNullable<typeof pageItems>[number]>();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function Users() {
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(users);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
|
||||
+26
-165
@@ -3,56 +3,7 @@ import { Link, useNavigate } from "react-router-dom";
|
||||
import { api, type IntegrationSummary, type MaintenanceWindow, type ServerSummary } from "../api/client";
|
||||
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
|
||||
import { useEnvironment } from "../utils/environment";
|
||||
import { formatRemaining } from "../utils/duration";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
|
||||
const REFRESH_MS = 30_000;
|
||||
|
||||
const TYPE_LABELS: Record<IntegrationSummary["type"], string> = {
|
||||
tailscale: "Tailscale",
|
||||
proxmox: "Proxmox",
|
||||
synology: "Synology",
|
||||
semaphore: "Semaphore",
|
||||
gitea: "Gitea",
|
||||
dockhand: "Docker",
|
||||
uptimekuma: "Uptime Kuma",
|
||||
phpipam: "phpIPAM",
|
||||
pbs: "Proxmox Backup",
|
||||
osticket: "osTicket",
|
||||
};
|
||||
|
||||
function useClock(): Date {
|
||||
const [now, setNow] = useState(() => new Date());
|
||||
useEffect(() => {
|
||||
const t = setInterval(() => setNow(new Date()), 1000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return now;
|
||||
}
|
||||
|
||||
/** Keeps the screen awake while the page is open, where the browser allows it. */
|
||||
function useWakeLock() {
|
||||
useEffect(() => {
|
||||
let lock: { release: () => Promise<void> } | null = null;
|
||||
let gone = false;
|
||||
const request = async () => {
|
||||
try {
|
||||
const nav = navigator as Navigator & { wakeLock?: { request: (type: "screen") => Promise<{ release: () => Promise<void> }> } };
|
||||
if (nav.wakeLock && !gone) lock = await nav.wakeLock.request("screen");
|
||||
} catch {
|
||||
// not allowed (battery saver, no permission): the screen may sleep like any other
|
||||
}
|
||||
};
|
||||
void request();
|
||||
const onVisible = () => document.visibilityState === "visible" && void request();
|
||||
document.addEventListener("visibilitychange", onVisible);
|
||||
return () => {
|
||||
gone = true;
|
||||
document.removeEventListener("visibilitychange", onVisible);
|
||||
void lock?.release().catch(() => {});
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView";
|
||||
|
||||
/**
|
||||
* A full-screen status board for a spare monitor or tablet: how things are, in type big enough to read across a room, refreshing
|
||||
@@ -61,14 +12,12 @@ function useWakeLock() {
|
||||
export default function Wall() {
|
||||
const navigate = useNavigate();
|
||||
const environment = useEnvironment();
|
||||
const now = useClock();
|
||||
const { report, failed, reload } = useAlertsReport();
|
||||
const [servers, setServers] = useState<ServerSummary | null>(null);
|
||||
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
|
||||
const [windows, setWindows] = useState<MaintenanceWindow[]>([]);
|
||||
const [updatedAt, setUpdatedAt] = useState<Date | null>(null);
|
||||
const [idle, setIdle] = useState(false);
|
||||
useWakeLock();
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -112,129 +61,41 @@ export default function Wall() {
|
||||
|
||||
const badge = alertBadge(report);
|
||||
const blind = report?.couldntCheck.length ?? 0;
|
||||
const level: "critical" | "warning" | "ok" | "unsure" = !report ? "unsure" : badge ? badge.level : blind > 0 ? "unsure" : "ok";
|
||||
const level: WallData["level"] = !report ? "unsure" : badge ? badge.level : blind > 0 ? "unsure" : "ok";
|
||||
const active = (report?.alerts ?? []).filter((a) => !a.silenced && a.severity !== "info").sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "critical" ? -1 : 1));
|
||||
const failing = (integrations ?? []).filter((i) => i.enabled && i.health?.status === "failing");
|
||||
const offline = servers?.offline.length ?? 0;
|
||||
|
||||
const headline =
|
||||
level === "critical" || level === "warning"
|
||||
? `${badge!.count} ${badge!.count === 1 ? "thing needs" : "things need"} attention`
|
||||
: level === "unsure"
|
||||
? report
|
||||
? "No alerts — but some checks couldn't run"
|
||||
: failed
|
||||
? "Can't reach the server"
|
||||
: "Checking…"
|
||||
: "All clear";
|
||||
const data: WallData = {
|
||||
level,
|
||||
headline: wallHeadline(level, badge?.count ?? 0, { loaded: !!report, failed }),
|
||||
servers: servers ? { online: servers.online, total: servers.online + servers.offline.length } : null,
|
||||
alerts: report ? { critical: report.counts.critical, warning: report.counts.warning } : null,
|
||||
maintenance: windows.length,
|
||||
integrationsFailing: integrations ? failing.length : null,
|
||||
problems: active.map((a) => ({ id: a.id, severity: a.severity as "critical" | "warning", message: a.message })),
|
||||
windows: windows.map((w) => ({ id: w.id, name: w.targetName, endsAt: w.endsAt })),
|
||||
integrations: (integrations ?? [])
|
||||
.filter((i) => i.enabled)
|
||||
.sort((a, b) => Number(b.health?.status === "failing") - Number(a.health?.status === "failing") || a.name.localeCompare(b.name))
|
||||
.map((i) => ({ id: i.id, name: i.name, type: i.type, status: i.health?.status === "failing" ? "failing" : i.health?.status === "ok" ? "ok" : "unknown" })),
|
||||
environmentName: environment?.name || null,
|
||||
updatedAt,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`wall ${idle ? "wall-idle" : ""}`} data-bs-theme="dark">
|
||||
<header className="wall-header">
|
||||
<img src="/logo.webp" alt="Homelab Manager" width={901} height={460} className="wall-logo" />
|
||||
{environment?.name && <span className="badge env-badge">{environment.name}</span>}
|
||||
<div className="wall-clock" aria-label="Time">
|
||||
<div className="wall-time">{formatTime(now, false)}</div>
|
||||
<div className="wall-date">{now.toLocaleDateString([], { weekday: "long" })} {formatDate(now)}</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section className={`wall-status wall-status-${level}`} role="status" aria-live="polite">
|
||||
<span className="wall-status-symbol" aria-hidden="true">
|
||||
{level === "critical" ? "✕" : level === "warning" ? "▲" : level === "ok" ? "✓" : "?"}
|
||||
</span>
|
||||
<span>{headline}</span>
|
||||
</section>
|
||||
|
||||
<section className="wall-tiles" aria-label="Summary">
|
||||
<div className={`wall-tile ${offline > 0 ? "wall-tile-bad" : ""}`}>
|
||||
<div className="wall-tile-figure">{servers ? (servers.online + offline === 0 ? "—" : `${servers.online}/${servers.online + offline}`) : "…"}</div>
|
||||
<div className="wall-tile-label">servers online</div>
|
||||
</div>
|
||||
<div className={`wall-tile ${(report?.counts.critical ?? 0) > 0 ? "wall-tile-bad" : (report?.counts.warning ?? 0) > 0 ? "wall-tile-warn" : ""}`}>
|
||||
<div className="wall-tile-figure">{report ? report.counts.critical + report.counts.warning : "…"}</div>
|
||||
<div className="wall-tile-label">
|
||||
alerts{report && report.counts.critical + report.counts.warning > 0 ? ` (${report.counts.critical} critical, ${report.counts.warning} warning)` : ""}
|
||||
</div>
|
||||
</div>
|
||||
<div className={`wall-tile ${windows.length > 0 ? "wall-tile-info" : ""}`}>
|
||||
<div className="wall-tile-figure">{windows.length}</div>
|
||||
<div className="wall-tile-label">in maintenance</div>
|
||||
</div>
|
||||
<div className={`wall-tile ${failing.length > 0 ? "wall-tile-bad" : ""}`}>
|
||||
<div className="wall-tile-figure">{integrations ? failing.length : "…"}</div>
|
||||
<div className="wall-tile-label">integrations failing</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="wall-columns">
|
||||
<div>
|
||||
<h2 className="wall-heading">Needs attention</h2>
|
||||
{active.length === 0 ? (
|
||||
<div className="wall-empty">Nothing right now.</div>
|
||||
) : (
|
||||
<ul className="wall-list">
|
||||
{active.slice(0, 7).map((a) => (
|
||||
<li key={a.id} className={a.severity === "critical" ? "wall-bad" : "wall-warn"}>
|
||||
<span aria-hidden="true">{a.severity === "critical" ? "✕" : "▲"}</span> <span className="visually-hidden">{a.severity}: </span>
|
||||
{a.message}
|
||||
</li>
|
||||
))}
|
||||
{active.length > 7 && <li className="wall-more">and {active.length - 7} more</li>}
|
||||
</ul>
|
||||
)}
|
||||
{windows.length > 0 && (
|
||||
<>
|
||||
<h2 className="wall-heading mt-4">In maintenance</h2>
|
||||
<ul className="wall-list wall-list-small">
|
||||
{windows.slice(0, 8).map((w) => (
|
||||
<li key={w.id}>
|
||||
{w.targetName} <span className="wall-dim">· {formatRemaining(w.endsAt, now.getTime())} left</span>
|
||||
</li>
|
||||
))}
|
||||
{windows.length > 8 && <li className="wall-more">and {windows.length - 8} more</li>}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="wall-heading">Integrations</h2>
|
||||
{(integrations ?? []).filter((i) => i.enabled).length === 0 ? (
|
||||
<div className="wall-empty">None connected.</div>
|
||||
) : (
|
||||
<ul className="wall-list wall-list-small">
|
||||
{[...(integrations ?? [])]
|
||||
.filter((i) => i.enabled)
|
||||
.sort((a, b) => Number(b.health?.status === "failing") - Number(a.health?.status === "failing") || a.name.localeCompare(b.name))
|
||||
.map((i) => {
|
||||
const status = i.health?.status;
|
||||
return (
|
||||
<li key={i.id} className={status === "failing" ? "wall-bad" : status === "ok" ? "wall-good" : "wall-dim"}>
|
||||
<span aria-hidden="true">{status === "failing" ? "✕" : status === "ok" ? "✓" : "·"}</span> {i.name}{" "}
|
||||
<span className="wall-dim">
|
||||
{TYPE_LABELS[i.type]} — {status === "failing" ? "failing" : status === "ok" ? "working" : "not checked yet"}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer className="wall-footer">
|
||||
<span>
|
||||
{updatedAt ? `Updated ${formatTime(updatedAt)}` : "Loading…"} · refreshes every {REFRESH_MS / 1000} s
|
||||
</span>
|
||||
<span className="wall-footer-actions">
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
footerActions={
|
||||
<>
|
||||
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
||||
Full screen
|
||||
</button>
|
||||
<Link to="/" className="wall-link">
|
||||
Exit (Esc)
|
||||
</Link>
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type ShareLink, type ShareLinkDetail } from "../../api/client";
|
||||
import CopyButton from "../../components/CopyButton";
|
||||
import TimeAgo from "../../components/TimeAgo";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import { confirmDialog } from "../../utils/dialogs";
|
||||
import { formatDateTime } from "../../utils/date";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
|
||||
const LASTS: { days: number | null; label: string }[] = [
|
||||
{ days: null, label: "Until I remove it" },
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
{ days: 90, label: "90 days" },
|
||||
{ days: 365, label: "1 year" },
|
||||
];
|
||||
|
||||
const DETAIL_WORDS: Record<ShareLinkDetail, string> = {
|
||||
summary: "Numbers only",
|
||||
names: "With names",
|
||||
};
|
||||
|
||||
export default function ShareSettings() {
|
||||
const [links, setLinks] = useState<ShareLink[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [label, setLabel] = useState("");
|
||||
const [detail, setDetail] = useState<ShareLinkDetail>("summary");
|
||||
const [days, setDays] = useState<number | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [created, setCreated] = useState<{ label: string; url: string } | null>(null);
|
||||
|
||||
function load() {
|
||||
api.shareLinks
|
||||
.list()
|
||||
.then((res) => setLinks(res.links))
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
async function create(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await api.shareLinks.create({ label: label.trim(), detail, expiresInDays: days });
|
||||
setCreated({ label: res.link.label, url: `${window.location.origin}${res.path}` });
|
||||
setLabel("");
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(link: ShareLink) {
|
||||
if (!(await confirmDialog({ title: "Remove share link", message: `Remove "${link.label}"? Any screen showing it stops working at once.`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.shareLinks.remove(link.id);
|
||||
toast.success(`Removed ${link.label}.`);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3 className="mb-3">Share links</h3>
|
||||
<p className="text-secondary">
|
||||
A share link opens the wall display — how things are, on one screen — <strong>without signing in</strong>, for a TV in the hall or someone who only wants to know whether things are up. It can only look; it can't change anything.
|
||||
</p>
|
||||
<div className="alert alert-warning">
|
||||
Anyone who has the address can open it, so treat it like a password: give it only to people and screens you trust, and remove it when it isn't needed. The address is shown once, when you make it.
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{created && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Address for {created.label}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">Copy it now — it can't be shown again. If it's lost, remove the link and make a new one.</p>
|
||||
<div className="input-group">
|
||||
<input className="form-control" readOnly value={created.url} aria-label="The share link address" onFocus={(e) => e.currentTarget.select()} />
|
||||
<CopyButton text={created.url} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer">
|
||||
<button className="btn" onClick={() => setCreated(null)}>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Make a link</h3>
|
||||
</div>
|
||||
<form onSubmit={create}>
|
||||
<div className="card-body row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="share-label">
|
||||
What it is for
|
||||
</label>
|
||||
<input id="share-label" className="form-control" required maxLength={60} placeholder="e.g. Hall TV" value={label} onChange={(e) => setLabel(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="share-detail">
|
||||
What it shows
|
||||
</label>
|
||||
<select id="share-detail" className="form-select" value={detail} onChange={(e) => setDetail(e.target.value as ShareLinkDetail)}>
|
||||
<option value="summary">Numbers only — servers online, alerts, maintenance</option>
|
||||
<option value="names">With names — also what is wrong, and the integrations</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="share-lasts">
|
||||
How long it works
|
||||
</label>
|
||||
<select id="share-lasts" className="form-select" value={days ?? ""} onChange={(e) => setDays(e.target.value === "" ? null : Number(e.target.value))}>
|
||||
{LASTS.map((l) => (
|
||||
<option key={l.label} value={l.days ?? ""}>
|
||||
{l.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-12 text-secondary small">
|
||||
“Numbers only” never shows a name. “With names” shows the text of the alerts (which can mention server names, disks and secrets), what is in maintenance, and the names of your integrations — never addresses, tokens or settings.
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || label.trim() === ""}>
|
||||
{busy ? "Making…" : "Make link"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Links</h3>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Shows</th>
|
||||
<th>Made</th>
|
||||
<th>Works until</th>
|
||||
<th>Last opened</th>
|
||||
<th className="w-1">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{links?.map((l) => (
|
||||
<tr key={l.id}>
|
||||
<td>
|
||||
{l.label} <span className="text-secondary small">{l.tokenPrefix}…</span>
|
||||
</td>
|
||||
<td>{DETAIL_WORDS[l.detail]}</td>
|
||||
<td className="text-secondary">
|
||||
{l.createdBy ?? "—"}, <TimeAgo value={l.createdAt} fromDb />
|
||||
</td>
|
||||
<td>{l.expired ? <span className="badge bg-red-lt text-red">Ended</span> : l.expiresAt ? formatDateTime(new Date(l.expiresAt)) : "Until removed"}</td>
|
||||
<td className="text-secondary">{l.lastUsedAt ? <TimeAgo value={l.lastUsedAt} /> : "Never"}</td>
|
||||
<td>
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(l)}>
|
||||
Remove
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{links?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="text-secondary text-center">
|
||||
No share links yet.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{links === null && !error && (
|
||||
<tr>
|
||||
<td colSpan={6} className="text-secondary text-center">
|
||||
Loading…
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user