From b5c8b3ad0f41f135c86a283418cd83daa0ea8c39 Mon Sep 17 00:00:00 2001 From: "andrii.dudar" Date: Thu, 12 Dec 2024 17:05:23 +0100 Subject: [PATCH] [OPIK-563] Add sections to the sidebar menu (#882) * [OPIK-563] Add sections to the sidebar menu * fix experiment link on home page --- .../layout/PageLayout/PageLayout.tsx | 2 +- .../src/components/layout/SideBar/SideBar.tsx | 130 +++++++++++++----- .../pages/HomePage/EvaluationSection.tsx | 5 +- 3 files changed, 97 insertions(+), 40 deletions(-) diff --git a/apps/opik-frontend/src/components/layout/PageLayout/PageLayout.tsx b/apps/opik-frontend/src/components/layout/PageLayout/PageLayout.tsx index 380bc75afc..d8f5d5f413 100644 --- a/apps/opik-frontend/src/components/layout/PageLayout/PageLayout.tsx +++ b/apps/opik-frontend/src/components/layout/PageLayout/PageLayout.tsx @@ -6,7 +6,7 @@ import { cn } from "@/lib/utils"; import useLocalStorageState from "use-local-storage-state"; const PageLayout = () => { - const [expanded = false, setExpanded] = + const [expanded = true, setExpanded] = useLocalStorageState("sidebar-expanded"); return ( diff --git a/apps/opik-frontend/src/components/layout/SideBar/SideBar.tsx b/apps/opik-frontend/src/components/layout/SideBar/SideBar.tsx index 5354603ded..e22ffd0f82 100644 --- a/apps/opik-frontend/src/components/layout/SideBar/SideBar.tsx +++ b/apps/opik-frontend/src/components/layout/SideBar/SideBar.tsx @@ -47,53 +47,89 @@ type MenuItem = { onClick?: MouseEventHandler; }; -const MAIN_MENU_ITEMS: MenuItem[] = [ +type MenuItemGroup = { + id: string; + label?: string; + items: MenuItem[]; +}; + +const MAIN_MENU_ITEMS: MenuItemGroup[] = [ { id: "home", - path: "/$workspaceName/home", - type: MENU_ITEM_TYPE.router, - icon: LucideHome, - label: "Home", + items: [ + { + id: "home", + path: "/$workspaceName/home", + type: MENU_ITEM_TYPE.router, + icon: LucideHome, + label: "Home", + }, + ], }, { - id: "projects", - path: "/$workspaceName/projects", - type: MENU_ITEM_TYPE.router, - icon: LayoutGrid, - label: "Projects", - count: "projects", - }, - { - id: "prompts", - path: "/$workspaceName/prompts", - type: MENU_ITEM_TYPE.router, - icon: FileTerminal, - label: "Prompt library", - count: "prompts", + id: "observability", + label: "Observability", + items: [ + { + id: "projects", + path: "/$workspaceName/projects", + type: MENU_ITEM_TYPE.router, + icon: LayoutGrid, + label: "Projects", + count: "projects", + }, + ], }, + { - id: "datasets", - path: "/$workspaceName/datasets", - type: MENU_ITEM_TYPE.router, - icon: Database, - label: "Datasets", - count: "datasets", + id: "evaluation", + label: "Evaluation", + items: [ + { + id: "datasets", + path: "/$workspaceName/datasets", + type: MENU_ITEM_TYPE.router, + icon: Database, + label: "Datasets", + count: "datasets", + }, + { + id: "experiments", + path: "/$workspaceName/experiments", + type: MENU_ITEM_TYPE.router, + icon: FlaskConical, + label: "Experiments", + count: "experiments", + }, + ], }, { - id: "experiments", - path: "/$workspaceName/experiments", - type: MENU_ITEM_TYPE.router, - icon: FlaskConical, - label: "Experiments", - count: "experiments", + id: "prompt_engineering", + label: "Prompt engineering", + items: [ + { + id: "prompts", + path: "/$workspaceName/prompts", + type: MENU_ITEM_TYPE.router, + icon: FileTerminal, + label: "Prompt library", + count: "prompts", + }, + ], }, { - id: "feedback-definitions", - path: "/$workspaceName/feedback-definitions", - type: MENU_ITEM_TYPE.router, - icon: MessageSquare, - label: "Feedback definitions", - count: "feedbackDefinitions", + id: "configuration", + label: "Configuration", + items: [ + { + id: "feedback-definitions", + path: "/$workspaceName/feedback-definitions", + type: MENU_ITEM_TYPE.router, + icon: MessageSquare, + label: "Feedback definitions", + count: "feedbackDefinitions", + }, + ], }, ]; @@ -330,6 +366,24 @@ const SideBar: React.FunctionComponent = ({ }); }; + const renderGroups = (groups: MenuItemGroup[]) => { + return groups.map((group) => { + return ( +
  • +
    + {group.label && expanded && ( +
    + {group.label} +
    + )} + +
      {renderItems(group.items)}
    +
    +
  • + ); + }); + }; + return ( <>