Export CSV on every table, edit recurring maintenance, runs-on nothing, and run package checks outside the agent sandbox
- Export CSV for the small tables that had none (reads the table as shown) - Servers page shows a skeleton while loading instead of "No servers registered yet" - Recurring maintenance schedules can be edited (PUT /schedules/:id) - A server can be set to run on nothing (servers.no_parent, migration 0028) - Linux agent v3: package-manager question runs in ExecStartPre=-+ outside the sandbox, with --prepare-updates and --check-updates modes - Docs: README, DATABASE, AGENT_UPDATE Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c17e9aa140
commit
540ab704b7
32 files changed
+3003
-66
No files matched your search
@@ -518,6 +518,8 @@ export interface ServerRecord {
|
||||
proxmoxGuestType: "qemu" | "lxc" | null;
|
||||
proxmoxVmid: number | null;
|
||||
hideProxmoxLink: boolean;
|
||||
/** An admin said it runs on nothing, so nothing is worked out for it. */
|
||||
noParent: boolean;
|
||||
tags: string[];
|
||||
/** The server this one runs on, when an admin said so; null means it is worked out from the Proxmox node. */
|
||||
parentServerId: number | null;
|
||||
@@ -851,6 +853,8 @@ export interface ServerUpdateInput {
|
||||
hideProxmoxLink?: boolean;
|
||||
/** The server this one runs on; null goes back to working it out from the Proxmox node. */
|
||||
parentServerId?: number | null;
|
||||
/** True says it runs on nothing, which stops the guess from its Proxmox node. */
|
||||
noParent?: boolean;
|
||||
}
|
||||
|
||||
/** A maintenance that repeats: "every Sunday 02:00–04:00 on these servers". */
|
||||
@@ -1489,6 +1493,7 @@ export const api = {
|
||||
schedules: {
|
||||
list: () => request<{ schedules: MaintenanceSchedule[] }>("/api/maintenance/schedules"),
|
||||
create: (data: MaintenanceScheduleInput) => request<{ id: number; windowsMade: number }>("/api/maintenance/schedules", { method: "POST", body: JSON.stringify(data) }),
|
||||
update: (id: number, data: MaintenanceScheduleInput) => request<{ windowsMade: number }>(`/api/maintenance/schedules/${id}`, { method: "PUT", body: JSON.stringify(data) }),
|
||||
setEnabled: (id: number, enabled: boolean) => request<{ enabled: boolean }>(`/api/maintenance/schedules/${id}`, { method: "PATCH", body: JSON.stringify({ enabled }) }),
|
||||
remove: (id: number) => request<void>(`/api/maintenance/schedules/${id}`, { method: "DELETE" }),
|
||||
},
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { downloadCsv, tableToRows } from "../utils/csv";
|
||||
|
||||
/**
|
||||
* "Export CSV" for a table that has no export of its own. It reads the table as it is on screen, so what you see is what you get.
|
||||
* By default it takes the first table in the same card; `of="next"` takes the table that follows the element this button sits in
|
||||
* (for a card with several tables, each under its own small heading). With no table to read it shows nothing.
|
||||
*/
|
||||
export default function ExportTableButton({ filename, of = "card", className = "btn btn-sm btn-outline-secondary" }: { filename: string; of?: "card" | "next"; className?: string }) {
|
||||
const ref = useRef<HTMLButtonElement>(null);
|
||||
const [hasTable, setHasTable] = useState(true);
|
||||
|
||||
function findTable(): HTMLTableElement | null {
|
||||
const button = ref.current;
|
||||
if (!button) return null;
|
||||
const scope = of === "next" ? button.parentElement?.nextElementSibling : button.closest(".card");
|
||||
return scope instanceof HTMLTableElement ? scope : (scope?.querySelector("table") ?? null);
|
||||
}
|
||||
|
||||
// The table may arrive after the button (loading, an empty list filling up), so look again after every render.
|
||||
useEffect(() => {
|
||||
const found = findTable() !== null;
|
||||
if (found !== hasTable) setHasTable(found);
|
||||
});
|
||||
|
||||
function exportNow() {
|
||||
const table = findTable();
|
||||
if (!table) return;
|
||||
const { headers, rows } = tableToRows(table);
|
||||
downloadCsv(filename.endsWith(".csv") ? filename : `${filename}.csv`, headers, rows);
|
||||
}
|
||||
|
||||
return (
|
||||
<button ref={ref} type="button" className={className} onClick={exportNow} hidden={!hasTable}>
|
||||
Export CSV
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import ExportTableButton from "./ExportTableButton";
|
||||
|
||||
// Monday first, as a week reads; the numbers are what the server keeps (0 = Sunday).
|
||||
const DAYS: { value: number; short: string }[] = [
|
||||
@@ -57,9 +58,14 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
const [schedules, setSchedules] = useState<MaintenanceSchedule[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
// The schedule being changed, if the form is open to change one rather than to add one.
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
||||
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
||||
// A schedule keeps the zone it was made in when it is changed; a new one uses this browser's.
|
||||
const [scheduleZone, setScheduleZone] = useState<string | null>(null);
|
||||
const timezone = scheduleZone ?? browserTimezone;
|
||||
const [name, setName] = useState("");
|
||||
const [reason, setReason] = useState("");
|
||||
const [days, setDays] = useState<number[]>([0]);
|
||||
@@ -91,6 +97,31 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
});
|
||||
}
|
||||
|
||||
function closeForm() {
|
||||
setAdding(false);
|
||||
setEditingId(null);
|
||||
setScheduleZone(null);
|
||||
setName("");
|
||||
setReason("");
|
||||
setDays([0]);
|
||||
setStartTime("02:00");
|
||||
setMinutes(120);
|
||||
setPicked(new Set());
|
||||
}
|
||||
|
||||
function startEditing(s: MaintenanceSchedule) {
|
||||
setError(null);
|
||||
setEditingId(s.id);
|
||||
setScheduleZone(s.timezone);
|
||||
setName(s.name);
|
||||
setReason(s.reason ?? "");
|
||||
setDays(s.days);
|
||||
setStartTime(s.startTime);
|
||||
setMinutes(s.durationMinutes);
|
||||
setPicked(new Set(s.targets.map((t) => key(t.type, t.id))));
|
||||
setAdding(true);
|
||||
}
|
||||
|
||||
async function create(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
@@ -100,12 +131,10 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
const [type, id] = k.split(":");
|
||||
return { type: type as MaintenanceTargetType, id: Number(id) };
|
||||
});
|
||||
const res = await api.maintenance.schedules.create({ name: name.trim(), reason: reason.trim() || undefined, targets: chosen, days, startTime, durationMinutes: minutes, timezone });
|
||||
const input = { name: name.trim(), reason: reason.trim() || undefined, targets: chosen, days, startTime, durationMinutes: minutes, timezone };
|
||||
const res = editingId === null ? await api.maintenance.schedules.create(input) : await api.maintenance.schedules.update(editingId, input);
|
||||
toast.success(`Saved. ${res.windowsMade} maintenance window${res.windowsMade === 1 ? "" : "s"} made for the coming week.`);
|
||||
setName("");
|
||||
setReason("");
|
||||
setPicked(new Set());
|
||||
setAdding(false);
|
||||
closeForm();
|
||||
load();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
@@ -143,13 +172,14 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Recurring</h3>
|
||||
{canEdit && !adding && (
|
||||
<div className="card-actions">
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => setAdding(true)}>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="maintenance-recurring" />
|
||||
{canEdit && !adding && (
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => { setError(null); setAdding(true); }}>
|
||||
Add recurring maintenance
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{adding && (
|
||||
@@ -194,6 +224,8 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
For
|
||||
</label>
|
||||
<select id="rec-length" className="form-select" value={minutes} onChange={(e) => setMinutes(Number(e.target.value))}>
|
||||
{/* A schedule made some other way (or before these choices) keeps whatever length it has. */}
|
||||
{!LENGTHS.some((l) => l.minutes === minutes) && <option value={minutes}>{minutes} minutes</option>}
|
||||
{LENGTHS.map((l) => (
|
||||
<option key={l.minutes} value={l.minutes}>
|
||||
{l.label}
|
||||
@@ -245,9 +277,9 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
</div>
|
||||
<div className="card-footer d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || picked.size === 0 || days.length === 0 || name.trim() === ""}>
|
||||
{busy ? "Saving…" : "Save"}
|
||||
{busy ? "Saving…" : editingId === null ? "Save" : "Save changes"}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setAdding(false)}>
|
||||
<button type="button" className="btn" onClick={closeForm}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
@@ -277,12 +309,15 @@ export default function RecurringMaintenance({ canEdit, targets, onChanged }: {
|
||||
<td>{namesWords(s.targets.map((t) => t.name))}</td>
|
||||
<td>
|
||||
{daysWords(s.days)} {timeWords(s.startTime, s.durationMinutes)}
|
||||
{s.timezone !== timezone && <span className="text-secondary small"> ({s.timezone})</span>}
|
||||
{s.timezone !== browserTimezone && <span className="text-secondary small"> ({s.timezone})</span>}
|
||||
</td>
|
||||
<td>{s.nextStart ? <TimeAgo value={s.nextStart} /> : "—"}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => startEditing(s)} disabled={editingId === s.id}>
|
||||
Edit
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => void toggle(s)}>
|
||||
{s.enabled ? "Turn off" : "Turn on"}
|
||||
</button>
|
||||
|
||||
@@ -7,9 +7,12 @@ import { toast } from "../utils/toast";
|
||||
/**
|
||||
* Which server this one runs on (a virtual machine on its host). When the host stops reporting, this server's own "offline" alert is
|
||||
* folded under the host's instead of being a second one. Left alone it is worked out from the Proxmox node the server is linked to;
|
||||
* an admin can say it by hand. Everyone sees it; only admins change it.
|
||||
* an admin can say it by hand, or say it runs on nothing (a physical machine that happens to carry a Proxmox node name).
|
||||
* Everyone sees it; only admins change it.
|
||||
*/
|
||||
export default function RunsOn({ serverId, parent, canEdit, onChanged }: { serverId: number; parent: ServerRelation | null; canEdit: boolean; onChanged: () => void }) {
|
||||
const NONE = "none";
|
||||
|
||||
export default function RunsOn({ serverId, parent, noParent, canEdit, onChanged }: { serverId: number; parent: ServerRelation | null; noParent: boolean; canEdit: boolean; onChanged: () => void }) {
|
||||
const [servers, setServers] = useState<ServerRecord[] | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
@@ -24,8 +27,8 @@ export default function RunsOn({ serverId, parent, canEdit, onChanged }: { serve
|
||||
async function change(value: string) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.servers.update(serverId, { parentServerId: value === "" ? null : Number(value) });
|
||||
toast.success(value === "" ? "Back to working it out from the Proxmox node." : "Saved.");
|
||||
await api.servers.update(serverId, value === NONE ? { noParent: true } : { parentServerId: value === "" ? null : Number(value) });
|
||||
toast.success(value === "" ? "Back to working it out from the Proxmox node." : value === NONE ? "It runs on nothing, so its alerts always stand alone." : "Saved.");
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
@@ -39,8 +42,9 @@ export default function RunsOn({ serverId, parent, canEdit, onChanged }: { serve
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<select className="form-select form-select-sm" aria-label="The server this one runs on" value={parent && !parent.auto ? String(parent.id) : ""} disabled={busy || servers === null} onChange={(e) => void change(e.target.value)}>
|
||||
<option value="">{parent?.auto ? `Automatic: ${parent.name}` : "None (automatic)"}</option>
|
||||
<select className="form-select form-select-sm" aria-label="The server this one runs on" value={noParent ? NONE : parent && !parent.auto ? String(parent.id) : ""} disabled={busy || servers === null} onChange={(e) => void change(e.target.value)}>
|
||||
<option value="">{parent?.auto ? `Automatic: ${parent.name}` : "Automatic (none found)"}</option>
|
||||
<option value={NONE}>Nothing — it runs on its own</option>
|
||||
{(servers ?? [])
|
||||
.filter((s) => s.id !== serverId)
|
||||
.map((s) => (
|
||||
@@ -49,7 +53,7 @@ export default function RunsOn({ serverId, parent, canEdit, onChanged }: { serve
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">Automatic means worked out from its Proxmox node. If it stops reporting, this server's offline alert is folded under its host's.</div>
|
||||
<div className="form-hint text-secondary small mt-1">Automatic means worked out from its Proxmox node. If it stops reporting, this server's offline alert is folded under its host's. "Nothing" stops that, so it always alerts for itself.</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { toast } from "../utils/toast";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import MaintenanceTimeline from "../components/MaintenanceTimeline";
|
||||
import RecurringMaintenance from "../components/RecurringMaintenance";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
const DURATIONS: { minutes: number; label: string }[] = [
|
||||
{ minutes: 30, label: "30 minutes" },
|
||||
@@ -479,6 +480,9 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Address aliases</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="maintenance-aliases" />
|
||||
</div>
|
||||
</div>
|
||||
<form onSubmit={addAlias}>
|
||||
<div className="card-body row g-3">
|
||||
@@ -579,6 +583,9 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Scheduled</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="maintenance-scheduled" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
@@ -598,11 +605,11 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
{w.targetName} <span className="text-secondary">· {w.targetKind}</span>
|
||||
</td>
|
||||
<td className="text-secondary">{w.reason ?? "—"}</td>
|
||||
<td>
|
||||
<td data-csv={w.startedAt}>
|
||||
<span className="badge bg-blue-lt text-blue me-2">in {formatRemaining(w.startedAt, now)}</span>
|
||||
<span className="text-secondary small">{formatDateTime(new Date(w.startedAt))}</span>
|
||||
</td>
|
||||
<td className="text-secondary small">{formatDateTime(new Date(w.endsAt))}</td>
|
||||
<td className="text-secondary small" data-csv={w.endsAt}>{formatDateTime(new Date(w.endsAt))}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => end(w)}>
|
||||
@@ -625,13 +632,14 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Active</h3>
|
||||
{canEdit && (windows?.length ?? 0) > 1 && (
|
||||
<div className="card-actions">
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="maintenance-active" />
|
||||
{canEdit && (windows?.length ?? 0) > 1 && (
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => void endAll()}>
|
||||
End all ({windows?.length})
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
@@ -652,7 +660,7 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
{w.source?.startsWith("kuma:") && <span className="badge bg-cyan-lt ms-2">Uptime Kuma</span>}
|
||||
</td>
|
||||
<td className="text-secondary">{w.reason ?? "—"}</td>
|
||||
<td>
|
||||
<td data-csv={w.endsAt}>
|
||||
<span className="badge bg-yellow-lt text-yellow me-2">{formatRemaining(w.endsAt, now)} left</span>
|
||||
<span className="text-secondary small">{formatDateTime(new Date(w.endsAt))}</span>
|
||||
</td>
|
||||
|
||||
@@ -14,6 +14,7 @@ import { formatDateTime } from "../utils/date";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import IntegrationPageTitle from "../components/IntegrationPageTitle";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
function formatBytes(bytes: number | null): string {
|
||||
if (bytes === null) return "—";
|
||||
@@ -297,6 +298,9 @@ export default function PbsBackup({ user: _user }: { user: CurrentUser }) {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Recent verification failures</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="pbs-verification-failures" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
|
||||
@@ -25,6 +25,7 @@ import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import DetailDrawer, { ObjectDetails } from "../components/DetailDrawer";
|
||||
import { useRowDetail } from "../hooks/useRowDetail";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
function proxmoxStatusBadge(status: string) {
|
||||
return status === "running" ? (
|
||||
@@ -381,7 +382,10 @@ export default function Proxmox({ user }: { user: CurrentUser }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-secondary small mb-1">Scheduled jobs</div>
|
||||
<div className="text-secondary small mb-1 d-flex align-items-center justify-content-between">
|
||||
Scheduled jobs
|
||||
<ExportTableButton of="next" filename="proxmox-backup-jobs" className="btn btn-sm btn-ghost-secondary" />
|
||||
</div>
|
||||
{backupJobs && backupJobs.length > 0 ? (
|
||||
<table className="table table-sm table-vcenter mb-4">
|
||||
<thead>
|
||||
@@ -413,7 +417,10 @@ export default function Proxmox({ user }: { user: CurrentUser }) {
|
||||
!backupsError && <div className="text-secondary small mb-4">No backup jobs configured in Proxmox.</div>
|
||||
)}
|
||||
|
||||
<div className="text-secondary small mb-1">Guests without backup coverage</div>
|
||||
<div className="text-secondary small mb-1 d-flex align-items-center justify-content-between">
|
||||
Guests without backup coverage
|
||||
<ExportTableButton of="next" filename="proxmox-uncovered-guests" className="btn btn-sm btn-ghost-secondary" />
|
||||
</div>
|
||||
{uncoveredGuests && uncoveredGuests.length > 0 ? (
|
||||
<table className="table table-sm table-vcenter mb-4">
|
||||
<thead>
|
||||
@@ -444,7 +451,10 @@ export default function Proxmox({ user }: { user: CurrentUser }) {
|
||||
uncoveredGuests && <div className="text-secondary small mb-4">Every VM/LXC is covered by at least one enabled backup job.</div>
|
||||
)}
|
||||
|
||||
<div className="text-secondary small mb-1">Recent runs</div>
|
||||
<div className="text-secondary small mb-1 d-flex align-items-center justify-content-between">
|
||||
Recent runs
|
||||
<ExportTableButton of="next" filename="proxmox-backup-runs" className="btn btn-sm btn-ghost-secondary" />
|
||||
</div>
|
||||
{backupTasks && backupTasks.length > 0 ? (
|
||||
<table className="table table-sm table-vcenter mb-0">
|
||||
<thead>
|
||||
|
||||
@@ -3,6 +3,7 @@ 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";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
const MAX_SERVERS = 4;
|
||||
const RANGES = [
|
||||
@@ -132,6 +133,7 @@ export default function ServerCompare() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<ExportTableButton filename={`compare-${metric}`} />
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{failed ? (
|
||||
|
||||
@@ -762,7 +762,7 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
|
||||
</dd>
|
||||
<dt className="col-5">Runs on</dt>
|
||||
<dd className="col-7">
|
||||
<RunsOn serverId={server.id} parent={detail.relations.parent} canEdit={isAdmin} onChanged={() => void loadDetail()} />
|
||||
<RunsOn serverId={server.id} parent={detail.relations.parent} noParent={server.noParent} canEdit={isAdmin} onChanged={() => void loadDetail()} />
|
||||
</dd>
|
||||
{detail.relations.children.length > 0 && (
|
||||
<>
|
||||
|
||||
@@ -20,6 +20,7 @@ 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";
|
||||
|
||||
function typeBadgeStyle(colors: Record<string, string>, type: string): CSSProperties {
|
||||
const color = colors[type];
|
||||
@@ -32,6 +33,8 @@ 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);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [managingServers, setManagingServers] = useState(false);
|
||||
@@ -74,7 +77,8 @@ export default function Servers({ user }: { user: CurrentUser }) {
|
||||
setServers(res.servers);
|
||||
setAgentLatest(res.agentLatest);
|
||||
})
|
||||
.catch((err) => setError(String(err)));
|
||||
.catch((err) => setError(String(err)))
|
||||
.finally(() => setLoaded(true));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -428,7 +432,7 @@ export default function Servers({ user }: { user: CurrentUser }) {
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{sortedServers?.length === 0 && (
|
||||
{loaded && sortedServers?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={7} className="text-secondary text-center">
|
||||
No servers registered yet.
|
||||
@@ -441,6 +445,12 @@ export default function Servers({ user }: { user: CurrentUser }) {
|
||||
<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">
|
||||
<div className="card-body text-secondary">
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useSortable } from "../hooks/useSortable";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { readableError } from "../utils/errors";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
|
||||
interface Row {
|
||||
id: number;
|
||||
@@ -220,6 +221,9 @@ export default function Updates() {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Docker containers with a newer image</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="docker-newer-images" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ErrorNotice } from "../../components/Notice";
|
||||
import { confirmDialog } from "../../utils/dialogs";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
import ExportTableButton from "../../components/ExportTableButton";
|
||||
|
||||
const EVENT_WORDS: Record<WebhookEventName, string> = {
|
||||
"alert.opened": "A problem begins",
|
||||
@@ -139,6 +140,9 @@ export default function ApiSettings() {
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Metrics for Prometheus</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="metrics-tokens" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
@@ -218,13 +222,14 @@ export default function ApiSettings() {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Event webhooks</h3>
|
||||
{!adding && (
|
||||
<div className="card-actions">
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="event-webhooks" />
|
||||
{!adding && (
|
||||
<button className="btn btn-sm btn-primary" onClick={() => setAdding(true)}>
|
||||
Add a webhook
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
|
||||
@@ -7,6 +7,7 @@ import { confirmDialog } from "../../utils/dialogs";
|
||||
import { formatDateTime } from "../../utils/date";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
import ExportTableButton from "../../components/ExportTableButton";
|
||||
|
||||
const LASTS: { days: number | null; label: string }[] = [
|
||||
{ days: null, label: "Until I remove it" },
|
||||
@@ -144,6 +145,9 @@ export default function ShareSettings() {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Links</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="share-links" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ErrorNotice } from "../../components/Notice";
|
||||
import { PageSkeleton } from "../../components/Skeleton";
|
||||
import { readableError } from "../../utils/errors";
|
||||
import { toast } from "../../utils/toast";
|
||||
import ExportTableButton from "../../components/ExportTableButton";
|
||||
|
||||
const DEFAULTS: SignInSettingsData = { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" };
|
||||
|
||||
@@ -147,6 +148,9 @@ export default function SignInSettings() {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">What these rules would do</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="role-preview" />
|
||||
</div>
|
||||
</div>
|
||||
{preview.adminsAfter === 0 && (
|
||||
<div className="alert alert-danger m-3 mb-0" role="alert">
|
||||
|
||||
@@ -4,6 +4,7 @@ import { readableError } from "../../utils/errors";
|
||||
import { normalizeTagInput, refreshTagColors, tagBadge } from "../../utils/tags";
|
||||
import { confirmDialog, promptDialog } from "../../utils/dialogs";
|
||||
import { ErrorNotice, SuccessNotice } from "../../components/Notice";
|
||||
import ExportTableButton from "../../components/ExportTableButton";
|
||||
|
||||
const DEFAULT_PICK = "#3b82f6";
|
||||
|
||||
@@ -145,6 +146,9 @@ export default function TagSettings() {
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">All tags</h3>
|
||||
<div className="card-actions">
|
||||
<ExportTableButton filename="tags" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
|
||||
@@ -13,3 +13,39 @@ export function downloadCsv(filename: string, headers: string[], rows: unknown[]
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a cell says as a person reads it — except times, which give their exact ISO value rather than "5 min ago". A cell, or anything in it,
|
||||
* can say what it should be in a CSV with `data-csv="…"` (for a cell that mixes a badge and a date, say).
|
||||
*/
|
||||
function cellText(cell: Element): string {
|
||||
const own = cell.getAttribute("data-csv");
|
||||
if (own !== null) return own;
|
||||
const clone = cell.cloneNode(true) as Element;
|
||||
clone.querySelectorAll("button, svg, input, select, textarea, .dropdown-menu, .visually-hidden").forEach((n) => n.remove());
|
||||
clone.querySelectorAll("[data-csv]").forEach((n) => n.replaceWith(n.getAttribute("data-csv") ?? ""));
|
||||
clone.querySelectorAll("time[datetime]").forEach((t) => t.replaceWith(t.getAttribute("datetime") ?? ""));
|
||||
// Lines and paragraphs inside a cell are words apart, not run together.
|
||||
clone.querySelectorAll("div, p, li, br").forEach((n) => n.prepend(" "));
|
||||
return (clone.textContent ?? "").replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
const ACTION_HEADERS = new Set(["", "action", "actions"]);
|
||||
|
||||
/**
|
||||
* Reads a table as it is on screen — the header row, then each body row — for the many small tables that have no export of their own.
|
||||
* Columns with no heading or headed "Actions" are left out, and so are rows that span the table (an empty message, an open detail).
|
||||
*/
|
||||
export function tableToRows(table: HTMLTableElement): { headers: string[]; rows: string[][] } {
|
||||
const headCells = Array.from(table.tHead?.rows[table.tHead.rows.length - 1]?.cells ?? []);
|
||||
const keep = headCells.map((th, i) => (ACTION_HEADERS.has(cellText(th).toLowerCase()) ? -1 : i)).filter((i) => i >= 0);
|
||||
const headers = keep.map((i) => cellText(headCells[i]));
|
||||
const rows: string[][] = [];
|
||||
for (const body of Array.from(table.tBodies)) {
|
||||
for (const tr of Array.from(body.rows)) {
|
||||
if (tr.cells.length !== headCells.length) continue;
|
||||
rows.push(keep.map((i) => cellText(tr.cells[i])));
|
||||
}
|
||||
}
|
||||
return { headers, rows };
|
||||
}
|
||||
Reference in new issue
Block a user