Dashboard status banner, phone-friendly lists, and more command palette actions
- Dashboard: a banner that answers "is it fine?" (headline, root cause, kinds of problem, worst few); cards with a problem come first in their row - Phone: Alerts, Updates and Inventory rows become compact cards, finger-sized buttons, Alerts drops its figure row; scanned inventory labels get an Edit button - Command palette: acknowledge alerts, update a server, print a label, open hardware, "What depends on ...?" Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43fc5e0272
commit
b5384c1e03
12 files changed
+429
-118
No files matched your search
@@ -3,6 +3,8 @@ import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { IconSearch } from "@tabler/icons-react";
|
||||
import {
|
||||
api,
|
||||
type AlertItem,
|
||||
type Asset,
|
||||
type CurrentUser,
|
||||
type DnsProviderType,
|
||||
type IntegrationType,
|
||||
@@ -11,6 +13,7 @@ import {
|
||||
type MaintenanceWindow,
|
||||
type SearchResponse,
|
||||
type SecretType,
|
||||
type UpdatesServer,
|
||||
} from "../api/client";
|
||||
import { isCurrent, isGroup, visibleNav, type NavLeaf } from "../layout/nav";
|
||||
import { toggleFavorite, useFavorites } from "../utils/favorites";
|
||||
@@ -159,6 +162,10 @@ export default function CommandPalette({
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const [targets, setTargets] = useState<MaintenanceTargets | null>(null);
|
||||
const [windows, setWindows] = useState<MaintenanceWindow[]>([]);
|
||||
// What the actions below are offered for, read each time the palette opens.
|
||||
const [alertsToAck, setAlertsToAck] = useState<AlertItem[]>([]);
|
||||
const [updatable, setUpdatable] = useState<UpdatesServer[]>([]);
|
||||
const [assets, setAssets] = useState<Asset[]>([]);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const opener = useRef<HTMLElement | null>(null);
|
||||
const navigate = useNavigate();
|
||||
@@ -200,6 +207,21 @@ export default function CommandPalette({
|
||||
setWindows(res.windows);
|
||||
})
|
||||
.catch(() => {});
|
||||
if (canAct) {
|
||||
api.alerts
|
||||
.list(false)
|
||||
.then((res) => setAlertsToAck(res.alerts.filter((a) => !a.silenced && a.severity !== "info" && !a.ack?.active).sort((a, b) => Number(b.severity === "critical") - Number(a.severity === "critical"))))
|
||||
.catch(() => setAlertsToAck([]));
|
||||
api.servers
|
||||
.updates()
|
||||
.then((res) => setUpdatable(res.servers.filter((s) => (s.updates?.count ?? 0) > 0)))
|
||||
.catch(() => setUpdatable([]));
|
||||
}
|
||||
api.inventory
|
||||
.list()
|
||||
.then((res) => setAssets(res.assets))
|
||||
.catch(() => setAssets([]));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [open]);
|
||||
|
||||
// The commands: pages to go to, and things to do.
|
||||
@@ -248,6 +270,56 @@ export default function CommandPalette({
|
||||
},
|
||||
keywords: "refresh reload alerts",
|
||||
});
|
||||
// Quick acknowledgements: the worst few alerts nobody is on, and all of them at once.
|
||||
if (canAct && alertsToAck.length > 0) {
|
||||
const ack = async (list: AlertItem[]) => {
|
||||
try {
|
||||
await Promise.all(list.map((a) => api.alerts.ack({ alertId: a.id, note: "Acknowledged from the command palette", assigneeId: user.id, hours: 4 })));
|
||||
toast.success(list.length === 1 ? "Acknowledged for 4 hours, handed to you. Change that on the Alerts page." : `Acknowledged ${list.length} alerts for 4 hours, handed to you.`);
|
||||
window.dispatchEvent(new Event("maintenance-changed"));
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
}
|
||||
};
|
||||
for (const a of alertsToAck.slice(0, 5)) {
|
||||
items.push({ key: `ack-${a.id}`, category: "Alerts", title: `Acknowledge: ${a.message}`, subtitle: `${a.severity} · for 4 hours, handed to you`, run: () => ack([a]), keywords: "acknowledge ack alert on it mine" });
|
||||
}
|
||||
if (alertsToAck.length > 1) {
|
||||
items.push({ key: "ack-all", category: "Alerts", title: `Acknowledge all ${alertsToAck.length} alerts nobody is on`, subtitle: "for 4 hours, handed to you", run: () => ack(alertsToAck), keywords: "acknowledge ack alerts all" });
|
||||
}
|
||||
}
|
||||
items.push({ key: "go-alerts-open", category: "Alerts", title: "Show the alerts nobody is on", subtitle: "", path: "/alerts", keywords: "alerts unacknowledged attention" });
|
||||
|
||||
// Update a server straight from here: opens the update drawer for it, which asks before it does anything.
|
||||
if (canAct) {
|
||||
for (const s of updatable) {
|
||||
items.push({
|
||||
key: `update-${s.id}`,
|
||||
category: "Updates",
|
||||
title: `Update ${s.name} now`,
|
||||
subtitle: `${s.updates?.count ?? 0} waiting${s.updates?.security ? ` · ${s.updates.security} security` : ""}`,
|
||||
path: `/updates?update=${s.id}`,
|
||||
keywords: "update upgrade patch install run",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Hardware: open it, or print its label.
|
||||
items.push({ key: "inv-labels", category: "Inventory", title: "Print inventory labels", subtitle: "a sheet of QR stickers", path: "/inventory/labels", keywords: "label labels qr print sticker" });
|
||||
for (const a of assets) {
|
||||
items.push({ key: `inv-open-${a.id}`, category: "Inventory", title: `Open ${a.name} in the inventory`, subtitle: [a.manufacturer, a.model].filter(Boolean).join(" "), path: `/inventory?asset=${a.id}`, keywords: "hardware asset inventory serial" });
|
||||
items.push({ key: `inv-label-${a.id}`, category: "Inventory", title: `Print the label for ${a.name}`, subtitle: a.rackUnit ?? a.location ?? "", path: `/inventory/labels?only=${a.id}`, keywords: "label qr print sticker" });
|
||||
}
|
||||
|
||||
// What would go down with a server or a service.
|
||||
if (targets) {
|
||||
for (const s of targets.servers) {
|
||||
items.push({ key: `dep-server-${s.id}`, category: "Dependencies", title: `What depends on ${s.name}?`, subtitle: "server · opens the dependency map", path: `/map?view=dependencies&select=server:${s.id}`, keywords: "depends dependency impact reboot down" });
|
||||
}
|
||||
for (const i of targets.integrations) {
|
||||
items.push({ key: `dep-int-${i.id}`, category: "Dependencies", title: `What depends on ${i.name}?`, subtitle: `${i.type} · opens the dependency map`, path: `/map?view=dependencies&select=integration:${i.id}`, keywords: "depends dependency impact down" });
|
||||
}
|
||||
}
|
||||
items.push({ key: "act-shortcuts", category: "Actions", title: "Show keyboard shortcuts", subtitle: "", hint: "?", run: () => void window.dispatchEvent(new Event(SHOW_SHORTCUTS_EVENT)), keywords: "keys help" });
|
||||
if (user.role === "admin") {
|
||||
items.push({
|
||||
@@ -315,7 +387,7 @@ export default function CommandPalette({
|
||||
}
|
||||
return items;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [user.role, canAct, targets, windows, onToggleTheme, onSetDensity, pathname, favorites]);
|
||||
}, [user.role, user.id, canAct, targets, windows, alertsToAck, updatable, assets, onToggleTheme, onSetDensity, pathname, favorites]);
|
||||
|
||||
const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
||||
|
||||
@@ -438,7 +510,7 @@ export default function CommandPalette({
|
||||
aria-autocomplete="list"
|
||||
aria-label="Search, or type a command"
|
||||
className="form-control form-control-lg border-0"
|
||||
placeholder="Search, or type a command: silence, theme, wall…"
|
||||
placeholder="Search, or type a command: acknowledge, update, label…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
onKeyDown={handleInputKeyDown}
|
||||
|
||||
Reference in new issue
Block a user