From c04f7deeffd689ce241892c187a4c4c3bdc13403 Mon Sep 17 00:00:00 2001 From: SpyTec Date: Mon, 9 Oct 2023 19:06:44 +0200 Subject: [PATCH] refactor: Move sidebar items around This will prepare us for more granular interaction with project selection in the future. For now until that is implemented we have this to go with. --- frontend/src/app/AppLayout/AppLayout.tsx | 118 +++++++++++++++++------ frontend/src/app/routes.tsx | 18 ++-- 2 files changed, 97 insertions(+), 39 deletions(-) diff --git a/frontend/src/app/AppLayout/AppLayout.tsx b/frontend/src/app/AppLayout/AppLayout.tsx index 9876f7c4..1112e53d 100644 --- a/frontend/src/app/AppLayout/AppLayout.tsx +++ b/frontend/src/app/AppLayout/AppLayout.tsx @@ -1,4 +1,10 @@ -import { NavLink, Outlet, matchRoutes, useLocation } from "react-router-dom"; +import { + NavLink, + Outlet, + RouteObject, + matchRoutes, + useLocation, +} from "react-router-dom"; import { Nav, NavList, @@ -19,10 +25,11 @@ import { Toolbar, ToolbarContent, ToolbarItem, + NavExpandable, } from "@patternfly/react-core"; import { routes } from "../routes"; import packitLogo from "../../static/logo.png"; -import { useState, useEffect } from "react"; +import React, { useState, useEffect } from "react"; import { ExternalLinkAltIcon, CodeBranchIcon, @@ -32,6 +39,7 @@ import { const AppLayout = () => { const location = useLocation(); const [activeLocationLabel, setActiveLocationLabel] = useState(""); + const [activeLocationCategory, setActiveLocationCategory] = useState(""); const currentRouteTree = matchRoutes(routes, location); // Dynamically set page title and update currently active page in sidebar useEffect(() => { @@ -43,6 +51,7 @@ const AppLayout = () => { const element = currentRouteTree[index]; if (element.route.handle?.label) { setActiveLocationLabel(element.route.handle.label); + setActiveLocationCategory(element.route.handle.category || ""); } } }, [currentRouteTree]); @@ -128,42 +137,87 @@ const AppLayout = () => { ); + const NavigationRoute: React.FC<{ route: RouteObject; index: string }> = ({ + route, + index, + }) => ( + + + {route.handle.label} + + + ); + const addedCategories: string[] = []; const Navigation = ( ); diff --git a/frontend/src/app/routes.tsx b/frontend/src/app/routes.tsx index 770fd283..579ae636 100644 --- a/frontend/src/app/routes.tsx +++ b/frontend/src/app/routes.tsx @@ -38,11 +38,21 @@ const routes: RouteObject[] = [ label: "Home", }, }, + { + element: , + path: "/projects", + handle: { + divider: true, + label: "Projects", + category: "Dashboards", + }, + }, { Component: Jobs, id: "jobs", path: "/jobs", handle: { + category: "Dashboards", label: "Jobs", }, children: [ @@ -101,16 +111,10 @@ const routes: RouteObject[] = [ element: , path: "/pipelines", handle: { + category: "Dashboards", label: "Pipelines", }, }, - { - element: , - path: "/projects", - handle: { - label: "Projects", - }, - }, { path: "/projects/:forge", element: ,