import type { ReactNode } from "react"; import { IconLayoutDashboard, IconServer2, IconWorld, IconNetwork, IconRouter, IconArrowsSplit2, IconHome2, IconBatteryCharging, IconTargetArrow, IconDatabaseExport, IconAdjustmentsAlt, IconChecklist, IconListDetails, IconKey, IconPlugConnected, IconBrandDocker, IconAffiliate, IconCloud, IconBinaryTree, IconBolt, IconFileText, IconFlame, IconLock, IconMovie, IconPhoto, IconPlayerPlay, IconBrandGit, IconServerCog, IconDatabase, IconUsers, IconSettings, IconWand, IconTool, IconListCheck, IconRefresh, IconDownload, IconBox, IconHeartbeat, IconGitCommit, IconShieldCheck, IconActivityHeartbeat, IconCopyCheck, IconTicket, IconPlug, IconExternalLink, IconAlertTriangle, IconSitemap, IconCalendarEvent, IconHeartRateMonitor, IconReportAnalytics, } 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: }, { to: "/my-work", label: "My work", icon: , minRole: "operator" }, { id: "infrastructure", label: "Infrastructure", icon: , items: [ { to: "/servers", label: "Servers", icon: }, { to: "/proxmox", label: "Proxmox", icon: }, { to: "/synology", label: "Synology", icon: }, { to: "/docker", label: "Docker", icon: }, { to: "/tailscale", label: "Tailscale", icon: }, { to: "/map", label: "Map", icon: }, { to: "/inventory", label: "Inventory", icon: }, { to: "/admin-links", label: "Admin Links", icon: }, ], }, { id: "backups", label: "Backups", icon: , items: [ { to: "/backups", label: "Backup coverage", icon: }, { to: "/pbs", label: "Proxmox Backup", icon: }, { to: "/duplicati", label: "Duplicati", icon: }, ], }, { id: "network", label: "Network", icon: , items: [ { to: "/dns", label: "DNS", icon: }, { to: "/network/devices", label: "Network devices", icon: }, { to: "/proxy-hosts", label: "Proxy hosts", icon: }, { to: "/ipam", label: "IP Addresses", icon: }, { to: "/ports", label: "Ports", icon: }, { to: "/consistency", label: "Consistency", icon: }, ], }, { id: "monitoring", label: "Monitoring", icon: , items: [ { to: "/endpoints", label: "Endpoints", icon: }, { to: "/alert-rules", label: "Alert rules", icon: }, { to: "/heartbeats", label: "Heartbeats", icon: }, { to: "/uptime-kuma", label: "Uptime Kuma", icon: }, { to: "/home-assistant", label: "Home Assistant", icon: }, { to: "/ups", label: "UPS", icon: }, { to: "/jellyfin", label: "Jellyfin", icon: }, { to: "/authentik", label: "Authentik", icon: }, { to: "/prometheus", label: "Prometheus", icon: }, { to: "/immich", label: "Immich", icon: }, { to: "/paperless", label: "Paperless", icon: }, { to: "/n8n", label: "n8n", icon: }, { to: "/netbox", label: "NetBox", icon: }, { to: "/nextcloud", label: "Nextcloud", icon: }, { to: "/service-levels", label: "Service levels", icon: }, ], }, { id: "automation", label: "Automation", icon: , items: [ { to: "/semaphore", label: "Semaphore", icon: }, { to: "/gitea", label: "Gitea", icon: }, { to: "/osticket", label: "osTicket", icon: }, ], }, { to: "/secrets", label: "Secrets", icon: }, { id: "operations", label: "Operations", icon: , items: [ { to: "/alerts", label: "Alerts", icon: }, { to: "/maintenance", label: "Maintenance", icon: }, { to: "/updates", label: "Updates", icon: }, { to: "/coming-up", label: "Coming up", icon: }, { to: "/todo", label: "To do", icon: }, { to: "/reports", label: "Monthly report", icon: }, { to: "/changes", label: "Change log", icon: , minRole: "operator" }, ], }, { id: "administration", label: "Administration", icon: , items: [ { to: "/integrations", label: "Integrations", icon: }, { to: "/generator", label: "Generator", icon: }, { to: "/users", label: "Users", 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}/`); }