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: },
{
id: "infrastructure",
label: "Infrastructure",
icon: ,
items: [
{ to: "/servers", label: "Servers", icon: },
{ to: "/proxmox", label: "Proxmox", icon: },
{ to: "/synology", label: "Synology", icon: },
{ to: "/pbs", label: "Proxmox Backup", icon: },
{ to: "/docker", label: "Docker", icon: },
{ to: "/tailscale", label: "Tailscale", icon: },
{ to: "/backups", label: "Backup coverage", icon: },
{ to: "/map", label: "Map", icon: },
{ to: "/inventory", label: "Inventory", icon: },
{ to: "/dependencies", label: "Dependencies", icon: },
],
},
{
id: "network",
label: "Network",
icon: ,
items: [
{ to: "/dns", label: "DNS", icon: },
{ to: "/domains", label: "Domains", icon: },
{ to: "/ipam", label: "IP Addresses", icon: },
{ to: "/ports", label: "Ports", icon: },
{ to: "/endpoints", label: "Endpoints", icon: },
{ to: "/consistency", label: "Consistency", icon: },
],
},
{
id: "automation",
label: "Automation",
icon: ,
items: [
{ to: "/semaphore", label: "Semaphore", icon: },
{ to: "/gitea", label: "Gitea", icon: },
],
},
{ to: "/secrets", label: "Secrets", icon: },
{
id: "operations",
label: "Operations",
icon: ,
items: [
{ to: "/alerts", label: "Alerts", icon: },
{ to: "/incidents", label: "Incidents", icon: },
{ to: "/changes", label: "Change log", icon: , minRole: "operator" },
{ to: "/maintenance", label: "Maintenance", icon: },
{ to: "/updates", label: "Updates", icon: },
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: },
{ to: "/osticket", label: "osTicket", icon: },
{ to: "/admin-links", label: "Admin Links", icon: },
{ to: "/generator", label: "Generator", icon: },
],
},
{
id: "administration",
label: "Administration",
icon: ,
items: [
{ to: "/integrations", label: "Integrations", icon: },
{ to: "/users", label: "Users", icon: , minRole: "admin" },
{ to: "/sessions", label: "Sessions", icon: , minRole: "admin" },
{ to: "/audit-log", label: "Audit Log", icon: , minRole: "operator" },
{ to: "/diag-log", label: "Diagnostic Log", icon: , minRole: "admin" },
{ to: "/settings", label: "Settings", icon: , minRole: "admin" },
],
},
];
const roleRank: Record = { 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}/`);
}