Files
Homelab-manager/web/src/layout/nav.tsx
T
bobbanandClaude Sonnet 5.5 92726568b7 Endpoint checks, restore tests, and a change log
- Endpoints: HTTP, TCP and TLS checks with answer time, uptime and certificate expiry; failures and expiring certificates become alerts and notifications; linked to a server for maintenance and tags
- Restore tests: record when a backup was restored and how it went; failed tests always alert, overdue ones with a limit set; shown on the Backup coverage page
- Change log: one filterable timeline made from the audit log and the incident record

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 23:03:56 +02:00

162 lines
5.8 KiB
TypeScript

import type { ReactNode } from "react";
import {
IconLayoutDashboard,
IconServer2,
IconWorld,
IconNetwork,
IconKey,
IconPlugConnected,
IconBrandDocker,
IconAffiliate,
IconPlayerPlay,
IconBrandGit,
IconServerCog,
IconDatabase,
IconUsers,
IconDevices,
IconHistory,
IconTimeline,
IconStethoscope,
IconSettings,
IconWand,
IconTool,
IconWorldWww,
IconListCheck,
IconRefresh,
IconDownload,
IconBox,
IconHierarchy2,
IconHeartbeat,
IconGitCommit,
IconShieldCheck,
IconActivityHeartbeat,
IconCopyCheck,
IconTicket,
IconPlug,
IconExternalLink,
IconAlertTriangle,
IconSitemap,
} from "@tabler/icons-react";
import type { CurrentUser } from "../api/client";
// The menu: what pages there are, how they are grouped, and which role is needed to see each. Used by the sidebar, the command
// palette, the keyboard shortcuts and the breadcrumbs, so they always agree.
type Role = "operator" | "admin";
export interface NavLeaf {
to: string;
label: string;
/** Shown for top-level links, and when a group is left with a single visible page and so is drawn as that page's own link. */
icon: ReactNode;
minRole?: Role;
}
export interface NavGroup {
id: string;
label: string;
icon: ReactNode;
items: NavLeaf[];
}
export type NavEntry = NavLeaf | NavGroup;
export const isGroup = (entry: NavEntry): entry is NavGroup => "items" in entry;
export const NAV: NavEntry[] = [
{ to: "/", label: "Dashboard", icon: <IconLayoutDashboard size={20} /> },
{
id: "infrastructure",
label: "Infrastructure",
icon: <IconServer2 size={20} />,
items: [
{ to: "/servers", label: "Servers", icon: <IconServer2 size={20} /> },
{ to: "/proxmox", label: "Proxmox", icon: <IconServerCog size={20} /> },
{ to: "/synology", label: "Synology", icon: <IconDatabase size={20} /> },
{ to: "/pbs", label: "Proxmox Backup", icon: <IconShieldCheck size={20} /> },
{ to: "/docker", label: "Docker", icon: <IconBrandDocker size={20} /> },
{ to: "/tailscale", label: "Tailscale", icon: <IconAffiliate size={20} /> },
{ to: "/backups", label: "Backup coverage", icon: <IconCopyCheck size={20} /> },
{ to: "/map", label: "Map", icon: <IconSitemap size={20} /> },
{ to: "/inventory", label: "Inventory", icon: <IconBox size={20} /> },
{ to: "/dependencies", label: "Dependencies", icon: <IconHierarchy2 size={20} /> },
],
},
{
id: "network",
label: "Network",
icon: <IconWorld size={20} />,
items: [
{ to: "/dns", label: "DNS", icon: <IconWorld size={20} /> },
{ to: "/domains", label: "Domains", icon: <IconWorldWww size={20} /> },
{ to: "/ipam", label: "IP Addresses", icon: <IconNetwork size={20} /> },
{ to: "/ports", label: "Ports", icon: <IconPlug size={20} /> },
{ to: "/endpoints", label: "Endpoints", icon: <IconHeartbeat size={20} /> },
{ to: "/consistency", label: "Consistency", icon: <IconListCheck size={20} /> },
],
},
{
id: "automation",
label: "Automation",
icon: <IconRefresh size={20} />,
items: [
{ to: "/semaphore", label: "Semaphore", icon: <IconPlayerPlay size={20} /> },
{ to: "/gitea", label: "Gitea", icon: <IconBrandGit size={20} /> },
],
},
{ to: "/secrets", label: "Secrets", icon: <IconKey size={20} /> },
{
id: "operations",
label: "Operations",
icon: <IconTool size={20} />,
items: [
{ to: "/alerts", label: "Alerts", icon: <IconAlertTriangle size={20} /> },
{ to: "/incidents", label: "Incidents", icon: <IconTimeline size={20} /> },
{ to: "/changes", label: "Change log", icon: <IconGitCommit size={20} />, minRole: "operator" },
{ to: "/maintenance", label: "Maintenance", icon: <IconTool size={20} /> },
{ to: "/updates", label: "Updates", icon: <IconDownload size={20} /> },
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
{ to: "/osticket", label: "osTicket", icon: <IconTicket size={20} /> },
{ to: "/admin-links", label: "Admin Links", icon: <IconExternalLink size={20} /> },
{ to: "/generator", label: "Generator", icon: <IconWand size={20} /> },
],
},
{
id: "administration",
label: "Administration",
icon: <IconSettings size={20} />,
items: [
{ to: "/integrations", label: "Integrations", icon: <IconPlugConnected size={20} /> },
{ to: "/users", label: "Users", icon: <IconUsers size={20} />, minRole: "admin" },
{ to: "/sessions", label: "Sessions", icon: <IconDevices size={20} />, minRole: "admin" },
{ to: "/audit-log", label: "Audit Log", icon: <IconHistory size={20} />, minRole: "operator" },
{ to: "/diag-log", label: "Diagnostic Log", icon: <IconStethoscope size={20} />, minRole: "admin" },
{ to: "/settings", label: "Settings", icon: <IconSettings size={20} />, minRole: "admin" },
],
},
];
const roleRank: Record<CurrentUser["role"], number> = { viewer: 0, operator: 1, admin: 2 };
/** What this role can see: pages it isn't allowed are dropped, an emptied group disappears, and a group down to one page becomes that page's own link. */
export function visibleNav(role: CurrentUser["role"]): NavEntry[] {
const allowed = (leaf: NavLeaf) => !leaf.minRole || roleRank[role] >= roleRank[leaf.minRole];
const out: NavEntry[] = [];
for (const entry of NAV) {
if (!isGroup(entry)) {
if (allowed(entry)) out.push(entry);
continue;
}
const items = entry.items.filter(allowed);
if (items.length === 1) out.push(items[0]);
else if (items.length > 1) out.push({ ...entry, items });
}
return out;
}
/** Is this the current page (or a page beneath it, like /servers/3 under /servers)? */
export function isCurrent(pathname: string, to: string): boolean {
return to === "/" ? pathname === "/" : pathname === to || pathname.startsWith(`${to}/`);
}