From 1ba288be790f9ac12aac75ebfca8f1b62adb756a Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 12 May 2024 12:59:45 -0700 Subject: [PATCH] split sidebar home --- frontend/src/components/alert/index.tsx | 3 +- frontend/src/components/layouts.tsx | 19 +++++++- .../src/components/resources/server/hooks.ts | 2 +- frontend/src/components/sidebar.tsx | 45 +++++++++++++++++-- frontend/src/components/topbar.tsx | 19 +++----- frontend/src/lib/hooks.ts | 34 +++++++++----- frontend/src/lib/utils.ts | 14 +++--- frontend/src/main.tsx | 8 ++++ frontend/src/pages/home/index.tsx | 2 +- frontend/src/ui/card.tsx | 2 +- 10 files changed, 108 insertions(+), 40 deletions(-) diff --git a/frontend/src/components/alert/index.tsx b/frontend/src/components/alert/index.tsx index b0915a141..82c17aa33 100644 --- a/frontend/src/components/alert/index.tsx +++ b/frontend/src/components/alert/index.tsx @@ -3,11 +3,10 @@ import { alert_level_intention, text_color_class_by_intention, } from "@lib/color"; -import { useRead } from "@lib/hooks"; +import { useRead, atomWithStorage } from "@lib/hooks"; import { Types } from "@monitor/client"; import { Button } from "@ui/button"; import { useAtom } from "jotai"; -import { atomWithStorage } from "jotai/utils"; import { AlertTriangle } from "lucide-react"; import { AlertsTable } from "./table"; diff --git a/frontend/src/components/layouts.tsx b/frontend/src/components/layouts.tsx index 8ecdad71f..55cb2b50c 100644 --- a/frontend/src/components/layouts.tsx +++ b/frontend/src/components/layouts.tsx @@ -1,7 +1,7 @@ import { Button } from "@ui/button"; import { PlusCircle } from "lucide-react"; -import { ReactNode, useState } from "react"; -import { Link, Outlet } from "react-router-dom"; +import { ReactNode, useEffect, useState } from "react"; +import { Link, Outlet, useNavigate } from "react-router-dom"; import { Dialog, DialogContent, @@ -19,6 +19,21 @@ import { usableResourcePath } from "@lib/utils"; import { Sidebar } from "./sidebar"; export const Layout = () => { + const nav = useNavigate(); + useEffect(() => { + const keydown = (e: KeyboardEvent) => { + // This will ignore Shift + S if it is sent from input / textarea + const target = e.target as any; + if (target.matches("input") || target.matches("textarea")) return; + + if (e.shiftKey && e.key === "H") { + e.preventDefault(); + nav("/"); + } + }; + document.addEventListener("keydown", keydown); + return () => document.removeEventListener("keydown", keydown); + }); return ( <> diff --git a/frontend/src/components/resources/server/hooks.ts b/frontend/src/components/resources/server/hooks.ts index f4f9b7742..662ca0198 100644 --- a/frontend/src/components/resources/server/hooks.ts +++ b/frontend/src/components/resources/server/hooks.ts @@ -1,6 +1,6 @@ +import { atomWithStorage } from "@lib/hooks"; import { Types } from "@monitor/client"; import { useAtom } from "jotai"; -import { atomWithStorage } from "jotai/utils"; const statsGranularityAtom = atomWithStorage( "stats-granularity-v0", diff --git a/frontend/src/components/sidebar.tsx b/frontend/src/components/sidebar.tsx index 277171153..163502716 100644 --- a/frontend/src/components/sidebar.tsx +++ b/frontend/src/components/sidebar.tsx @@ -1,17 +1,49 @@ import { RESOURCE_TARGETS, cn, usableResourcePath } from "@lib/utils"; import { Button } from "@ui/button"; import { Card, CardContent } from "@ui/card"; -import { AlertTriangle, Bell, Box, Home, Tag, UserCircle2 } from "lucide-react"; +import { + AlertTriangle, + Bell, + Box, + Boxes, + FolderTree, + Tag, + UserCircle2, +} from "lucide-react"; import { Link, useLocation } from "react-router-dom"; import { ResourceComponents } from "./resources"; import { Separator } from "@ui/separator"; import { ReactNode } from "react"; +import { useAtom } from "jotai"; +import { homeViewAtom } from "@main"; export const Sidebar = () => { + const [view, setView] = useAtom(homeViewAtom); + console.log(view); return ( - } /> + } + onClick={() => setView("Dashboard")} + highlighted={view === "Dashboard"} + /> + } + onClick={() => setView("Resources")} + highlighted={view === "Resources"} + /> + } + onClick={() => setView("Tree")} + highlighted={view === "Tree"} + /> @@ -70,20 +102,27 @@ const SidebarLink = ({ to, icon, label, + onClick, + highlighted, }: { to: string; icon: ReactNode; label: string; + onClick?: () => void; + highlighted?: boolean; }) => { const location = useLocation(); + const hl = + "/" + location.pathname.split("/")[1] === to && (highlighted ?? true); return (