Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(ui): nested main navigation for tracing (#834)

Marc Klingen133fc9071849
diff --git a/src/components/layouts/layout.tsx b/src/components/layouts/layout.tsx
index 3d8b20a8d9..7202c46c8f 100644
--- a/src/components/layouts/layout.tsx
+++ b/src/components/layouts/layout.tsx
@@ -1,12 +1,12 @@
-import { ROUTES } from "@/src/components/layouts/routes";
+import { ROUTES, type Route } from "@/src/components/layouts/routes";
import { Fragment, type PropsWithChildren, useState } from "react";
-import { Dialog, Menu, Transition } from "@headlessui/react";
+import { Dialog, Disclosure, Menu, Transition } from "@headlessui/react";
import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline";
import Link from "next/link";
import { useRouter } from "next/router";
import clsx from "clsx";
-import { Code, MessageSquarePlus, Info } from "lucide-react";
+import { Code, MessageSquarePlus, Info, ChevronRightIcon } from "lucide-react";
import { signOut, useSession } from "next-auth/react";
import { ChevronDownIcon } from "@heroicons/react/20/solid";
import { cn } from "@/src/utils/tailwind";
@@ -50,30 +50,47 @@ export default function Layout(props: PropsWithChildren) {
api.environment.enableExperimentalFeatures.useQuery().data ?? false;
const projectId = router.query.projectId as string | undefined;
- const navigation = ROUTES.filter(
- ({ pathname }) => projectId || !pathname.includes("[projectId]"),
- )
- .filter(
- ({ featureFlag }) =>
- featureFlag === undefined ||
+
+ const mapNavigation = (route: Route): NavigationItem | null => {
+ // Project-level routes
+ if (!projectId && route.pathname?.includes("[projectId]")) return null;
+
+ // Feature Flags
+ if (
+ !(
+ route.featureFlag === undefined ||
enableExperimentalFeatures ||
- session.data?.user?.featureFlags[featureFlag],
+ session.data?.user?.featureFlags[route.featureFlag]
+ )
)
- .filter(
- ({ rbacScope }) =>
- rbacScope === undefined ||
- (projectId && hasAccess({ projectId, scope: rbacScope, session })),
+ return null;
+
+ // RBAC
+ if (
+ route.rbacScope !== undefined &&
+ (!projectId || !hasAccess({ projectId, scope: route.rbacScope, session }))
)
- .map(({ pathname, ...rest }) => ({
- pathname,
- href: pathname.replace("[projectId]", projectId ?? ""),
- ...rest,
- }))
- .map(({ pathname, ...rest }) => ({
- pathname,
- current: router.pathname === pathname,
- ...rest,
- }));
+ return null;
+
+ // apply to children as well
+ const children: (NavigationItem | null)[] =
+ route.children?.map((child) => mapNavigation(child)).filter(Boolean) ??
+ [];
+ return {
+ ...route,
+ href: route.pathname?.replace("[projectId]", projectId ?? ""),
+ current: router.pathname === route.pathname,
+ children:
+ children.length > 0
+ ? (children as NavigationItem[]) // does not include null due to filter
+ : undefined,
+ };
+ };
+
+ const navigationMapped: (NavigationItem | null)[] = ROUTES.map((route) =>
+ mapNavigation(route),
+ ).filter(Boolean);
+ const navigation = navigationMapped.filter(Boolean) as NavigationItem[]; // does not include null due to filter
const currentPathName = navigation.find(({ current }) => current)?.name;
@@ -207,58 +224,7 @@ export default function Layout(props: PropsWithChildren) {
<LangfuseLogo version size="xl" />
<nav className="flex flex-1 flex-col">
<ul role="list" className="flex flex-1 flex-col gap-y-7">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li
- key={item.name}
- onClick={() => setSidebarOpen(false)}
- >
- <Link
- href={item.href}
- className={clsx(
- item.current
- ? "bg-gray-50 text-indigo-600"
- : "text-gray-700 hover:bg-gray-50 hover:text-indigo-600",
- "group flex gap-x-3 rounded-md p-2 text-sm font-semibold leading-6",
- )}
- >
- <item.icon
- className={clsx(
- item.current
- ? "text-indigo-600"
- : "text-gray-400 group-hover:text-indigo-600",
- "h-6 w-6 shrink-0",
- )}
- aria-hidden="true"
- />
- {item.name}
- {item.label && (
- <span
- className={cn(
- "self-center whitespace-nowrap break-keep rounded-sm border px-1 py-0.5 text-xs",
- item.current
- ? "border-indigo-600 text-indigo-600"
- : "border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600",
- )}
- >
- {item.label}
- </span>
- )}
- </Link>
- </li>
- ))}
- <FeedbackButtonWrapper className="w-full">
- <li className="group flex cursor-pointer gap-x-3 rounded-md p-2 text-sm font-semibold leading-6 text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
- <MessageSquarePlus
- className="h-6 w-6 shrink-0 text-gray-400 group-hover:text-indigo-600"
- aria-hidden="true"
- />
- Feedback
- </li>
- </FeedbackButtonWrapper>
- </ul>
- </li>
+ <MainNavigation nav={navigation} />
<li>
<div className="flex flex-row place-content-between items-center">
<div className="text-xs font-semibold leading-6 text-gray-400">
@@ -324,56 +290,7 @@ export default function Layout(props: PropsWithChildren) {
<LangfuseLogo version size="xl" className="mb-2 px-6" />
<nav className="flex h-full flex-1 flex-col overflow-y-auto px-6 pb-3">
<ul role="list" className="flex h-full flex-col gap-y-4">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li key={item.name}>
- <Link
- href={item.href}
- className={clsx(
- item.current
- ? "bg-gray-50 text-indigo-600"
- : "text-gray-700 hover:bg-gray-50 hover:text-indigo-600",
- "group flex gap-x-3 rounded-md p-2 text-sm font-semibold leading-6",
- )}
- >
- <item.icon
- className={clsx(
- item.current
- ? "text-indigo-600"
- : "text-gray-400 group-hover:text-indigo-600",
- "h-6 w-6 shrink-0",
- )}
- aria-hidden="true"
- />
- {item.name}
- {item.label && (
- <span
- className={cn(
- "self-center whitespace-nowrap break-keep rounded-sm border px-1 py-0.5 text-xs",
- item.current
- ? "border-indigo-600 text-indigo-600"
- : "border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600",
- )}
- >
- {item.label}
- </span>
- )}
- </Link>
- </li>
- ))}
- <FeedbackButtonWrapper className="w-full">
- <li className="group flex cursor-pointer gap-x-3 rounded-md p-2 text-sm font-semibold leading-6 text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
- <MessageSquarePlus
- className="h-6 w-6 shrink-0 text-gray-400 group-hover:text-indigo-600"
- aria-hidden="true"
- />
- Feedback
- </li>
- </FeedbackButtonWrapper>
- </ul>
- </li>
-
+ <MainNavigation nav={navigation} />
<li className="mt-auto">
<div className="flex flex-row place-content-between items-center">
<div className="text-xs font-semibold leading-6 text-gray-400">
@@ -575,3 +492,133 @@ export default function Layout(props: PropsWithChildren) {
</>
);
}
+
+type NavigationItem = NestedNavigationItem & {
+ children?: NestedNavigationItem[];
+};
+
+type NestedNavigationItem = Omit<Route, "children"> & {
+ href?: string;
+ current: boolean;
+};
+
+const MainNavigation: React.FC<{
+ nav: NavigationItem[];
+ onNavitemClick?: () => void;
+}> = ({ nav, onNavitemClick }) => (
+ <li>
+ <ul role="list" className="-mx-2 space-y-1">
+ {nav.map((item) => (
+ <li key={item.name}>
+ {(!item.children || item.children.length === 0) && item.href ? (
+ <Link
+ href={item.href}
+ className={clsx(
+ item.current
+ ? "bg-gray-50 text-indigo-600"
+ : "text-gray-700 hover:bg-gray-50 hover:text-indigo-600",
+ "group flex gap-x-3 rounded-md p-2 text-sm font-semibold leading-6",
+ )}
+ onClick={onNavitemClick}
+ >
+ {item.icon && (
+ <item.icon
+ className={clsx(
+ item.current
+ ? "text-indigo-600"
+ : "text-gray-400 group-hover:text-indigo-600",
+ "h-6 w-6 shrink-0",
+ )}
+ aria-hidden="true"
+ />
+ )}
+ {item.name}
+ {item.label && (
+ <span
+ className={cn(
+ "self-center whitespace-nowrap break-keep rounded-sm border px-1 py-0.5 text-xs",
+ item.current
+ ? "border-indigo-600 text-indigo-600"
+ : "border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600",
+ )}
+ >
+ {item.label}
+ </span>
+ )}
+ </Link>
+ ) : item.children && item.children.length > 0 ? (
+ <Disclosure
+ as="div"
+ defaultOpen={item.children.some((child) => child.current)}
+ >
+ {({ open }) => (
+ <>
+ <Disclosure.Button className="group flex w-full items-center gap-x-3 rounded-md p-2 text-left text-sm font-semibold leading-6 hover:bg-gray-50 hover:text-indigo-600">
+ {item.icon && (
+ <item.icon
+ className="h-6 w-6 shrink-0 text-gray-400 group-hover:text-indigo-600"
+ aria-hidden="true"
+ />
+ )}
+ {item.name}
+ {item.label && (
+ <span
+ className={cn(
+ "self-center whitespace-nowrap break-keep rounded-sm border px-1 py-0.5 text-xs",
+ item.current
+ ? "border-indigo-600 text-indigo-600"
+ : "border-gray-200 text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600",
+ )}
+ >
+ {item.label}
+ </span>
+ )}
+ <ChevronRightIcon
+ className={clsx(
+ open ? "rotate-90 text-gray-500" : "text-gray-400",
+ "ml-auto h-5 w-5 shrink-0",
+ )}
+ aria-hidden="true"
+ />
+ </Disclosure.Button>
+ <Disclosure.Panel as="ul" className="mt-1 px-2">
+ {item.children?.map((subItem) => (
+ <li key={subItem.name}>
+ {/* 44px */}
+ <Link
+ href={subItem.href ?? "#"}
+ className={clsx(
+ subItem.current
+ ? "bg-gray-50 text-indigo-600"
+ : "text-gray-700 hover:bg-gray-50 hover:text-indigo-600",
+ "flex w-full items-center gap-x-3 rounded-md py-2 pl-9 pr-2 text-sm leading-6",
+ )}
+ >
+ {subItem.name}
+ {subItem.label && (
+ <span className="self-center whitespace-nowrap break-keep rounded-sm border border-gray-200 px-1 py-0.5 text-xs text-gray-400 group-hover:border-indigo-600 group-hover:text-indigo-600">
+ {subItem.label}
+ </span>
+ )}
+ </Link>
+ </li>
+ ))}
+ </Disclosure.Panel>
+ </>
+ )}
+ </Disclosure>
+ ) : null}
+ </li>
+ ))}
+ <FeedbackButtonWrapper className="w-full">
+ <li className="group flex cursor-pointer gap-x-3 rounded-md p-2 text-sm font-semibold leading-6 text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
+ <MessageSquarePlus
+ className="h-6 w-6 shrink-0 text-gray-400 group-hover:text-indigo-600"
+ aria-hidden="true"
+ />
+ Feedback
+ </li>
+ </FeedbackButtonWrapper>
+ </ul>
+ </li>
+);
diff --git a/src/components/layouts/routes.ts b/src/components/layouts/routes.ts
index e58ff0e4f6..f51e9d5c48 100644
--- a/src/components/layouts/routes.ts
+++ b/src/components/layouts/routes.ts
@@ -4,48 +4,50 @@ import {
Database,
LayoutDashboard,
LifeBuoy,
- LineChart,
ListTree,
type LucideIcon,
Settings,
- TextSelect,
UsersIcon,
- Route,
PenSquareIcon,
} from "lucide-react";
-export const ROUTES: Array<{
+export type Route = {
name: string;
- pathname: string;
- icon: LucideIcon;
featureFlag?: Flag;
label?: string;
rbacScope?: Scope;
-}> = [
+ icon?: LucideIcon; // ignored for nested routes
+ pathname?: string; // link, ignored if children
+ children?: Array<Route>; // folder
+};
+
+export const ROUTES: Route[] = [
{
name: "Dashboard",
pathname: `/project/[projectId]`,
icon: LayoutDashboard,
},
{
- name: "Sessions",
- pathname: `/project/[projectId]/sessions`,
- icon: Route,
- },
- {
- name: "Traces",
- pathname: `/project/[projectId]/traces`,
+ name: "Tracing",
icon: ListTree,
- },
- {
- name: "Generations",
- pathname: `/project/[projectId]/generations`,
- icon: TextSelect,
- },
- {
- name: "Scores",
- pathname: `/project/[projectId]/scores`,
- icon: LineChart,
+ children: [
+ {
+ name: "Traces",
+ pathname: `/project/[projectId]/traces`,
+ },
+ {
+ name: "Sessions",
+ pathname: `/project/[projectId]/sessions`,
+ },
+ {
+ name: "Generations",
+ pathname: `/project/[projectId]/generations`,
+ },
+ {
+ name: "Scores",
+ pathname: `/project/[projectId]/scores`,
+ },
+ ],
},
{
name: "Users",