Skip to content

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

fix(ui): exclude dynamic pages when switching between projects (#2928)

Marc Klingen408dd15d850c
diff --git a/web/src/components/layouts/header.tsx b/web/src/components/layouts/header.tsx
index 93a32066e1..9c5b5ea723 100644
--- a/web/src/components/layouts/header.tsx
+++ b/web/src/components/layouts/header.tsx
@@ -123,14 +123,37 @@ const BreadcrumbComponent = ({
scope: "projects:create",
});
+ /**
+ * Truncate the path before the first dynamic segment that is not allowlisted.
+ * e.g. /project/[projectId]/traces/[traceId] -> /project/[projectId]/traces
+ */
+ const truncatePathBeforeDynamicSegments = (path: string) => {
+ const allowlistedIds = ["[projectId]", "[organizationId]", "[page]"];
+ const segments = router.route.split("/");
+ const idSegments = segments.filter(
+ (segment) => segment.startsWith("[") && segment.endsWith("]"),
+ );
+ const stopSegment = idSegments.filter((id) => !allowlistedIds.includes(id));
+ if (stopSegment.length === 0) return path;
+ const stopIndex = segments.indexOf(stopSegment[0]);
+ const truncatedPath = path.split("/").slice(0, stopIndex).join("/");
+ return truncatedPath;
+ };
+
const getProjectPath = (projectId: string) =>
router.query.projectId
- ? router.asPath.replace(router.query.projectId as string, projectId)
+ ? truncatePathBeforeDynamicSegments(router.asPath).replace(
+ router.query.projectId as string,
+ projectId,
+ )
: `/project/${projectId}`;
const getOrgPath = (orgId: string) =>
router.query.organizationId
- ? router.asPath.replace(router.query.organizationId as string, orgId)
+ ? truncatePathBeforeDynamicSegments(router.asPath).replace(
+ router.query.organizationId as string,
+ orgId,
+ )
: `/organization/${orgId}`;
return (