Dashboard status strip, "Not set up yet" list, sidebar badges and user menu
The dashboard opens with one line saying whether anything needs attention (from the same alert report as the Alerts page) and never claims "all clear" when some checks couldn't run. Widgets with nothing configured are listed once under "Not set up yet" instead of one grey card each. The sidebar shows the active alert count and open maintenance windows next to their pages (and on a closed group), and the foot of the sidebar is one user menu holding theme, privacy and sign-out. One shared alert poll serves the strip and the badge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aab2f8cb4a
commit
7d56ad18b7
5 files changed
+369
-22
No files matched your search
+111
-21
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { Link, NavLink, useLocation } from "react-router-dom";
|
||||
import {
|
||||
IconLayoutDashboard,
|
||||
@@ -33,12 +33,27 @@ import {
|
||||
IconPlug,
|
||||
IconExternalLink,
|
||||
IconAlertTriangle,
|
||||
IconChevronUp,
|
||||
IconLogout,
|
||||
} from "@tabler/icons-react";
|
||||
import { api, type CurrentUser, type MaintenanceWindow } from "../api/client";
|
||||
import { formatRemaining } from "../utils/duration";
|
||||
import { getTheme, setTheme, type Theme } from "../utils/theme";
|
||||
import CommandPalette from "../components/CommandPalette";
|
||||
import { isLightColor, useEnvironment } from "../utils/environment";
|
||||
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
|
||||
|
||||
interface NavBadge {
|
||||
text: string;
|
||||
className: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
/** Up to two initials for the little avatar in the user menu. */
|
||||
function initialsOf(name: string): string {
|
||||
const words = name.replace(/@.*$/, "").split(/[\s._-]+/).filter(Boolean);
|
||||
return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
||||
}
|
||||
|
||||
type Role = "operator" | "admin";
|
||||
|
||||
@@ -165,6 +180,24 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
const [theme, setThemeState] = useState<Theme>(() => getTheme());
|
||||
const [maintenance, setMaintenance] = useState<MaintenanceWindow[]>([]);
|
||||
const environment = useEnvironment();
|
||||
const { report } = useAlertsReport();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Closes the user menu when you click elsewhere or press Escape.
|
||||
useEffect(() => {
|
||||
if (!menuOpen) return;
|
||||
const onDown = (e: MouseEvent) => {
|
||||
if (menuRef.current && !menuRef.current.contains(e.target as Node)) setMenuOpen(false);
|
||||
};
|
||||
const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMenuOpen(false);
|
||||
document.addEventListener("mousedown", onDown);
|
||||
document.addEventListener("keydown", onKey);
|
||||
return () => {
|
||||
document.removeEventListener("mousedown", onDown);
|
||||
document.removeEventListener("keydown", onKey);
|
||||
};
|
||||
}, [menuOpen]);
|
||||
|
||||
// Everyone sees what's currently silenced, so nobody is left wondering why an alert never came.
|
||||
useEffect(() => {
|
||||
@@ -214,6 +247,32 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
});
|
||||
}
|
||||
|
||||
// What needs a look, shown next to the page that deals with it.
|
||||
const badges: Record<string, NavBadge> = {};
|
||||
const alerts = alertBadge(report);
|
||||
if (alerts) {
|
||||
badges["/alerts"] = {
|
||||
text: String(alerts.count),
|
||||
className: alerts.level === "critical" ? "bg-red text-red-fg" : "bg-yellow text-yellow-fg",
|
||||
title: `${alerts.count} active alert${alerts.count === 1 ? "" : "s"}`,
|
||||
};
|
||||
}
|
||||
if (maintenance.length > 0) {
|
||||
badges["/maintenance"] = {
|
||||
text: String(maintenance.length),
|
||||
className: "bg-blue text-blue-fg",
|
||||
title: `${maintenance.length} maintenance window${maintenance.length === 1 ? "" : "s"} open`,
|
||||
};
|
||||
}
|
||||
const badgeOf = (to: string) => {
|
||||
const b = badges[to];
|
||||
return b ? (
|
||||
<span className={`badge ms-auto ${b.className}`} title={b.title}>
|
||||
{b.text}
|
||||
</span>
|
||||
) : null;
|
||||
};
|
||||
|
||||
function toggleTheme() {
|
||||
const next: Theme = theme === "dark" ? "light" : "dark";
|
||||
setTheme(next);
|
||||
@@ -252,6 +311,7 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
<NavLink to={entry.to} end={entry.to === "/"} className="nav-link" onClick={() => setSidebarOpen(false)}>
|
||||
<span className="nav-link-icon d-md-none d-lg-inline-block">{entry.icon}</span>
|
||||
<span className="nav-link-title">{entry.label}</span>
|
||||
{badgeOf(entry.to)}
|
||||
</NavLink>
|
||||
</li>
|
||||
);
|
||||
@@ -268,16 +328,29 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
>
|
||||
<span className="nav-link-icon d-md-none d-lg-inline-block">{entry.icon}</span>
|
||||
<span className="nav-link-title">{entry.label}</span>
|
||||
{/* A closed group still says that something inside it needs a look. */}
|
||||
{!open &&
|
||||
(() => {
|
||||
const inside = entry.items.map((item) => badges[item.to]).filter(Boolean);
|
||||
if (inside.length === 0) return null;
|
||||
const worst = inside.find((b) => b.className.includes("bg-red")) ?? inside.find((b) => b.className.includes("bg-yellow")) ?? inside[0];
|
||||
return (
|
||||
<span className={`badge ms-auto me-4 ${worst.className}`} title={inside.map((b) => b.title).join(", ")}>
|
||||
{inside.reduce((n, b) => n + Number(b.text), 0)}
|
||||
</span>
|
||||
);
|
||||
})()}
|
||||
</button>
|
||||
<div className={`dropdown-menu ${open ? "show" : ""}`}>
|
||||
{entry.items.map((item) => (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={({ isActive }) => `dropdown-item ${isActive ? "active" : ""}`}
|
||||
className={({ isActive }) => `dropdown-item d-flex align-items-center ${isActive ? "active" : ""}`}
|
||||
onClick={() => setSidebarOpen(false)}
|
||||
>
|
||||
{item.label}
|
||||
{badgeOf(item.to)}
|
||||
</NavLink>
|
||||
))}
|
||||
</div>
|
||||
@@ -285,29 +358,46 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<div className="navbar-footer px-3">
|
||||
<div className="navbar-footer px-3 user-menu" ref={menuRef}>
|
||||
{menuOpen && (
|
||||
<div className="user-menu-list" role="menu">
|
||||
<button type="button" className="user-menu-item" role="menuitem" onClick={toggleTheme}>
|
||||
{theme === "dark" ? <IconSun size={16} /> : <IconMoon size={16} />}
|
||||
{theme === "dark" ? "Light mode" : "Dark mode"}
|
||||
</button>
|
||||
<NavLink
|
||||
to="/privacy"
|
||||
className="user-menu-item"
|
||||
role="menuitem"
|
||||
onClick={() => {
|
||||
setMenuOpen(false);
|
||||
setSidebarOpen(false);
|
||||
}}
|
||||
>
|
||||
<IconShieldLock size={16} />
|
||||
Privacy
|
||||
</NavLink>
|
||||
<a className="user-menu-item" role="menuitem" href="/auth/logout">
|
||||
<IconLogout size={16} />
|
||||
Sign out
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-outline-secondary btn-sm w-100 mb-2 d-flex align-items-center justify-content-center gap-2"
|
||||
onClick={toggleTheme}
|
||||
className="user-menu-toggle"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
title={user.email ?? undefined}
|
||||
onClick={() => setMenuOpen((open) => !open)}
|
||||
>
|
||||
{theme === "dark" ? <IconSun size={16} /> : <IconMoon size={16} />}
|
||||
{theme === "dark" ? "Light mode" : "Dark mode"}
|
||||
<span className="avatar avatar-sm">{initialsOf(user.name ?? user.email ?? user.sub)}</span>
|
||||
<span className="user-menu-who">
|
||||
<span className="d-block text-truncate">{user.name ?? user.email ?? user.sub}</span>
|
||||
<span className="d-block small opacity-75">{user.role}</span>
|
||||
</span>
|
||||
<IconChevronUp size={16} className={menuOpen ? "" : "user-menu-chevron-closed"} />
|
||||
</button>
|
||||
<NavLink
|
||||
to="/privacy"
|
||||
className="btn btn-outline-secondary btn-sm w-100 mb-2 d-flex align-items-center justify-content-center gap-2"
|
||||
onClick={() => setSidebarOpen(false)}
|
||||
>
|
||||
<IconShieldLock size={16} />
|
||||
Privacy
|
||||
</NavLink>
|
||||
<div className="text-secondary small mb-2">
|
||||
Signed in as {user.name ?? user.email ?? user.sub} · {user.role}
|
||||
</div>
|
||||
<a className="btn btn-outline-secondary btn-sm w-100" href="/auth/logout">
|
||||
Sign out
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user