Skip to content

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

fix(web): Improve nav route active checking (#17647)

Ben Bachem4686e8f7ff31
diff --git a/web/src/components/layouts/app-layout/hooks/useFilteredNavigation.ts b/web/src/components/layouts/app-layout/hooks/useFilteredNavigation.ts
index bc0b6467f8..30242d7df4 100644
--- a/web/src/components/layouts/app-layout/hooks/useFilteredNavigation.ts
+++ b/web/src/components/layouts/app-layout/hooks/useFilteredNavigation.ts
@@ -147,7 +147,7 @@ export function useFilteredNavigation(
return useMemo(() => {
const mapRouteToNavigationItem = (route: Route): NavigationItem => {
const pathname = resolveRoutePathname({
- pathname: route.pathname,
+ pathname: route.href,
legacyPathname: route.legacyPathname,
v4Enabled: session?.user?.v4BetaEnabled === true,
forceV3Experience,
@@ -164,12 +164,13 @@ export function useFilteredNavigation(
return {
...route,
url,
- isActive:
- isPathActive(route.pathname, router.pathname) ||
- Boolean(
- route.legacyPathname &&
- isPathActive(route.legacyPathname, router.pathname),
- ),
+ isActive: route.isActive
+ ? route.isActive(router.pathname)
+ : isPathActive(route.href, router.pathname) ||
+ Boolean(
+ route.legacyPathname &&
+ isPathActive(route.legacyPathname, router.pathname),
+ ),
items: items && items.length > 0 ? items : undefined,
};
};
diff --git a/web/src/components/layouts/app-layout/utils/navigationFilters.ts b/web/src/components/layouts/app-layout/utils/navigationFilters.ts
index 90a41a0860..f67d00b843 100644
--- a/web/src/components/layouts/app-layout/utils/navigationFilters.ts
+++ b/web/src/components/layouts/app-layout/utils/navigationFilters.ts
@@ -24,7 +24,7 @@ const filters = {
* Filter routes that require a project ID when none is available
*/
projectScope: (route: Route, ctx: NavigationFilterContext): Route | null => {
- if (!ctx.routerProjectId && route.pathname.includes("[projectId]")) {
+ if (!ctx.routerProjectId && route.href.includes("[projectId]")) {
return null;
}
return route;
@@ -37,10 +37,7 @@ const filters = {
route: Route,
ctx: NavigationFilterContext,
): Route | null => {
- if (
- !ctx.routerOrganizationId &&
- route.pathname.includes("[organizationId]")
- ) {
+ if (!ctx.routerOrganizationId && route.href.includes("[organizationId]")) {
return null;
}
return route;
diff --git a/web/src/components/layouts/app-layout/utils/pathClassification.ts b/web/src/components/layouts/app-layout/utils/pathClassification.ts
index d4836ccb63..112a780599 100644
--- a/web/src/components/layouts/app-layout/utils/pathClassification.ts
+++ b/web/src/components/layouts/app-layout/utils/pathClassification.ts
@@ -108,3 +108,10 @@ export function isPathActive(routePath: string, currentPath: string): boolean {
return currentPath.startsWith(routePath + "/");
}
+
+export function matchesPathname(routePathnames: string[]) {
+ return (pathname: string) =>
+ routePathnames.some((routePathname) =>
+ isPathActive(routePathname, pathname),
+ );
+}
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsx
index 7d44592aca..9438a659eb 100644
--- a/web/src/components/layouts/routes.tsx
+++ b/web/src/components/layouts/routes.tsx
@@ -35,6 +35,7 @@ import { useCommandMenu } from "@/src/features/command-k-menu/CommandMenuProvide
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { CloudStatusMenu } from "@/src/features/cloud-status-notification/components/CloudStatusMenu";
import { type ProductModule } from "@/src/ee/features/ui-customization/productModuleSchema";
+import { matchesPathname } from "@/src/components/layouts/app-layout/utils/pathClassification";
export enum RouteSection {
Main = "main",
@@ -55,7 +56,8 @@ export type Route = {
projectRbacScopes?: ProjectScope[]; // array treated as OR
organizationRbacScope?: OrganizationScope;
icon?: LucideIcon; // ignored for nested routes
- pathname: string; // link
+ href: string;
+ isActive?: (pathname: string) => boolean;
legacyPathname?: string; // link used when the V4 preview is disabled
items?: Array<Route>; // folder
section?: RouteSection; // which section of the sidebar (top/main/bottom)
@@ -80,33 +82,37 @@ export type Route = {
export const ROUTES: Route[] = [
{
title: "Go to...",
- pathname: "", // Empty pathname since this is a dropdown
+ href: "", // Empty pathname since this is a dropdown
icon: Search,
menuNode: <CommandMenuTrigger />,
section: RouteSection.Main,
},
{
title: "Organizations",
- pathname: "/",
+ href: "/",
icon: Grid2X2,
show: ({ organization }) => organization === undefined,
section: RouteSection.Main,
},
{
title: "Projects",
- pathname: "/organization/[organizationId]",
+ href: "/organization/[organizationId]",
icon: Grid2X2,
section: RouteSection.Main,
},
{
title: "Home",
- pathname: `/project/[projectId]`,
+ href: `/project/[projectId]`,
icon: Home,
section: RouteSection.Main,
},
{
title: "Dashboards",
- pathname: `/project/[projectId]/dashboards`,
+ href: `/project/[projectId]/dashboards`,
+ isActive: matchesPathname([
+ `/project/[projectId]/dashboards`,
+ `/project/[projectId]/widgets`,
+ ]),
icon: LayoutDashboard,
productModule: "dashboards",
section: RouteSection.Main,
@@ -117,7 +123,11 @@ export const ROUTES: Route[] = [
productModule: "tracing",
group: RouteGroup.Observability,
section: RouteSection.Main,
- pathname: `/project/[projectId]/traces`,
+ href: `/project/[projectId]/traces`,
+ isActive: matchesPathname([
+ `/project/[projectId]/traces`,
+ `/project/[projectId]/observations`,
+ ]),
},
{
title: "Sessions",
@@ -125,11 +135,11 @@ export const ROUTES: Route[] = [
productModule: "tracing",
group: RouteGroup.Observability,
section: RouteSection.Main,
- pathname: `/project/[projectId]/sessions`,
+ href: `/project/[projectId]/sessions`,
},
{
title: "Users",
- pathname: `/project/[projectId]/users`,
+ href: `/project/[projectId]/users`,
icon: UsersIcon,
productModule: "tracing",
group: RouteGroup.Observability,
@@ -137,7 +147,7 @@ export const ROUTES: Route[] = [
},
{
title: "Alerts",
- pathname: "/project/[projectId]/alerts",
+ href: "/project/[projectId]/alerts",
icon: BellRing,
projectRbacScopes: ["alerts:read"],
show: ({ v4WriteMode }) => Boolean(v4WriteMode) && v4WriteMode !== "legacy",
@@ -146,7 +156,7 @@ export const ROUTES: Route[] = [
},
{
title: "Prompts",
- pathname: "/project/[projectId]/prompts",
+ href: "/project/[projectId]/prompts",
icon: FileJson,
projectRbacScopes: ["prompts:read"],
productModule: "prompt-management",
@@ -155,7 +165,7 @@ export const ROUTES: Route[] = [
},
{
title: "Playground",
- pathname: "/project/[projectId]/playground",
+ href: "/project/[projectId]/playground",
icon: TerminalIcon,
productModule: "playground",
group: RouteGroup.PromptManagement,
@@ -163,7 +173,7 @@ export const ROUTES: Route[] = [
},
{
title: "Scores",
- pathname: `/project/[projectId]/scores`,
+ href: `/project/[projectId]/scores`,
group: RouteGroup.Evaluation,
section: RouteSection.Main,
icon: SquarePercent,
@@ -175,12 +185,12 @@ export const ROUTES: Route[] = [
projectRbacScopes: ["evaluator:read", "evaluationRule:read"],
group: RouteGroup.Evaluation,
section: RouteSection.Main,
- pathname: `/project/[projectId]/evals`,
+ href: `/project/[projectId]/evals`,
legacyPathname: `/project/[projectId]/evals/legacy`,
},
{
title: "Human Annotation",
- pathname: `/project/[projectId]/annotation-queues`,
+ href: `/project/[projectId]/annotation-queues`,
projectRbacScopes: ["annotationQueues:read"],
group: RouteGroup.Evaluation,
section: RouteSection.Main,
@@ -188,7 +198,7 @@ export const ROUTES: Route[] = [
},
{
title: "Datasets",
- pathname: `/project/[projectId]/datasets`,
+ href: `/project/[projectId]/datasets`,
icon: Database,
productModule: "datasets",
projectRbacScopes: ["datasets:read"],
@@ -197,7 +207,7 @@ export const ROUTES: Route[] = [
},
{
title: "Experiments",
- pathname: `/project/[projectId]/experiments`,
+ href: `/project/[projectId]/experiments`,
icon: Beaker,
featureFlag: "experimentsV4Enabled",
group: RouteGroup.Evaluation,
@@ -207,7 +217,7 @@ export const ROUTES: Route[] = [
// Keep Action required first in the secondary nav so it is not sandwiched
// between regular items like Upgrade Plan and Settings.
title: "Update",
- pathname: "",
+ href: "",
section: RouteSection.Secondary,
show: ({ projectId, v4UpgradeUiAvailable }) =>
v4UpgradeUiAvailable && projectId !== undefined,
@@ -216,14 +226,14 @@ export const ROUTES: Route[] = [
{
title: "Cloud Status",
section: RouteSection.Secondary,
- pathname: "",
+ href: "",
show: ({ isLangfuseCloud, hasActiveCloudIncident }) =>
isLangfuseCloud && hasActiveCloudIncident,
menuNode: <CloudStatusMenu />,
},
{
title: "V4 Preview",
- pathname: "",
+ href: "",
section: RouteSection.Secondary,
featureFlag: "v4BetaToggleVisible",
// v4-upgrade users get this toggle inside the migration panel instead.
@@ -234,7 +244,7 @@ export const ROUTES: Route[] = [
{
title: "Upgrade Plan",
icon: Sparkle,
- pathname: "/project/[projectId]/settings/billing",
+ href: "/project/[projectId]/settings/billing",
section: RouteSection.Secondary,
entitlements: ["cloud-billing"],
organizationRbacScope: "langfuseCloudBilling:CRUD",
@@ -243,7 +253,7 @@ export const ROUTES: Route[] = [
{
title: "Upgrade Plan",
icon: Sparkle,
- pathname: "/organization/[organizationId]/settings/billing",
+ href: "/organization/[organizationId]/settings/billing",
section: RouteSection.Secondary,
entitlements: ["cloud-billing"],
organizationRbacScope: "langfuseCloudBilling:CRUD",
@@ -251,27 +261,27 @@ export const ROUTES: Route[] = [
},
{
title: "Settings",
- pathname: "/project/[projectId]/settings",
+ href: "/project/[projectId]/settings",
icon: Settings,
section: RouteSection.Secondary,
},
{
title: "Settings",
- pathname: "/organization/[organizationId]/settings",
+ href: "/organization/[organizationId]/settings",
icon: Settings,
section: RouteSection.Secondary,
},
{
title: "Book a call",
section: RouteSection.Secondary,
- pathname: "",
+ href: "",
menuNode: <BookACallButton />,
},
{
title: "Support",
icon: LifeBuoy,
section: RouteSection.Secondary,
- pathname: "", // Empty pathname since this is a dropdown
+ href: "", // Empty pathname since this is a dropdown
menuNode: <SupportButton />,
},
];
diff --git a/web/src/components/layouts/utilities/routes.ts b/web/src/components/layouts/utilities/routes.ts
index c4721dce66..3352c492fd 100644
--- a/web/src/components/layouts/utilities/routes.ts
+++ b/web/src/components/layouts/utilities/routes.ts
@@ -1,6 +1,6 @@
import { type Route } from "../routes";
-export type NavigationItem = Omit<Route, "children" | "items"> & {
+export type NavigationItem = Omit<Route, "children" | "items" | "isActive"> & {
url: string;
isActive: boolean;
items?: NavigationItem[];