From bb0f5aaa70d5e758bc4ffd9a9f5c236477385fb3 Mon Sep 17 00:00:00 2001 From: Chris Dymond Date: Sat, 18 Jan 2025 19:18:45 +0800 Subject: [PATCH] refactored Nav avoiding repetition, routes defined in NavConfig --- components/NavButton.tsx | 50 +++++++++ components/NavConfig.tsx | 57 ++++++++++ components/NavMenu.tsx | 223 +++++++++------------------------------ 3 files changed, 155 insertions(+), 175 deletions(-) create mode 100644 components/NavButton.tsx create mode 100644 components/NavConfig.tsx diff --git a/components/NavButton.tsx b/components/NavButton.tsx new file mode 100644 index 0000000..3bc9dfe --- /dev/null +++ b/components/NavButton.tsx @@ -0,0 +1,50 @@ +import React from "react"; +import { Button, Body1, tokens } from "@fluentui/react-components"; +import { DividerTallFilled } from "@fluentui/react-icons"; +import { useRouter, usePathname } from "next/navigation"; + +interface NavButtonProps { + label: string; + route: string; + showActiveIcon?: boolean; + icon?: React.ReactNode; +} + +const activeStyle = { + backgroundColor: tokens.colorNeutralBackground2, + color: tokens.colorNeutralForeground2BrandSelected, +}; + +export function NavButton({ + label, + route, + icon, + showActiveIcon = false, +}: NavButtonProps) { + const router = useRouter(); + const pathname = usePathname(); + + const isActive = pathname === route; + + return ( + + ); +} \ No newline at end of file diff --git a/components/NavConfig.tsx b/components/NavConfig.tsx new file mode 100644 index 0000000..4a04f56 --- /dev/null +++ b/components/NavConfig.tsx @@ -0,0 +1,57 @@ + +import { HomeRegular } from "@fluentui/react-icons"; +import IconAppRegistrations from "./styling/icons/IconAppRegistrations"; +import IconEnterpriseApps from "./styling/icons/IconEnterpriseApps"; + +interface NavItem { + label: string; + route: string; + icon?: React.ReactNode; // Icon for the header or button + showActiveIcon?: boolean; // Whether to show the active divider icon + children?: NavItem[]; // Sub-items if this item has an accordion +} + +export const navConfig: NavItem[] = [ + { + label: "Home", + route: "/", + icon: , + showActiveIcon: false, + }, + { + label: "App Registrations", + route: "/app-registrations", + icon: , + showActiveIcon: false, + children: [ + { + label: "Analytics", + route: "/app-registrations/analytics", + showActiveIcon: true, + }, + { + label: "Certificates & secrets", + route: "/app-registrations/certificates-and-secrets", + showActiveIcon: true, + }, + ], + }, + { + label: "Enterprise Applications", + route: "/enterprise-applications", + icon: , + showActiveIcon: false, + children: [ + { + label: "App role permissions", + route: "/enterprise-applications/app-role-permissions", + showActiveIcon: true, + }, + { + label: "SAML certificate status", + route: "/enterprise-applications/saml-certificate-expiry-status", + showActiveIcon: true, + }, + ], + }, +]; \ No newline at end of file diff --git a/components/NavMenu.tsx b/components/NavMenu.tsx index 4e60b7d..baed266 100644 --- a/components/NavMenu.tsx +++ b/components/NavMenu.tsx @@ -1,190 +1,63 @@ import { + Toolbar, + ToolbarGroup, Accordion, - AccordionHeader, AccordionItem, + AccordionHeader, AccordionPanel, - Body1, - Body1Strong, - Button, Divider, - tokens, - Toolbar, - ToolbarGroup, + Body1Strong, } from "@fluentui/react-components"; -import { DividerTallFilled, HomeRegular } from "@fluentui/react-icons"; -import { usePathname, useRouter } from "next/navigation"; -import IconAppRegistrations from "./styling/icons/IconAppRegistrations"; -import IconEnterpriseApps from "./styling/icons/IconEnterpriseApps"; - -export default function NavMenu() { - const router = useRouter(); - - const pathname = usePathname(); // Get the current route - const activeStyle = { - backgroundColor: tokens.colorNeutralBackground2, - color: tokens.colorNeutralForeground2BrandSelected, - }; +import { NavButton } from "./NavButton"; +import { navConfig } from "./NavConfig"; +export default function NavMenu() { return ( - + - - + {navConfig.map((item, index) => { + if (item.children && item.children.length > 0) { + return ( + + + + {item.label} + + + {item.children.map((child, childIndex) => ( + + ))} + + + + ); + } - {/* */} - - - } - expandIconPosition="end" - > - App Registrations - - - - - - - - {/* */} - - - } - expandIconPosition="end" - > - Enterprise Applications - - - - - - - + return ( +
+ + {index < navConfig.length - 1 && } +
+ ); + })}
-
); }