Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
area: webapp
type: fix
---

Retain sidebar active highlight when navigating to nested detail pages like tasks and runs
7 changes: 7 additions & 0 deletions apps/webapp/app/components/navigation/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,10 @@ export function SideMenu({
to={v3EnvironmentPath(organization, project, environment)}
data-action="tasks"
isCollapsed={isCollapsed}
matchPrefix={[
`${v3EnvironmentPath(organization, project, environment)}/tasks`,
`${v3EnvironmentPath(organization, project, environment)}/agents`,
]}
yieldActiveToFavorite
/>
<SideMenuItem
Expand All @@ -960,6 +964,7 @@ export function SideMenu({
to={v3RunsPath(organization, project, environment)}
data-action="runs"
isCollapsed={isCollapsed}
matchPrefix
yieldActiveToFavorite
/>
<SideMenuItem
Expand All @@ -970,6 +975,7 @@ export function SideMenu({
to={v3SessionsPath(organization, project, environment)}
data-action="sessions"
isCollapsed={isCollapsed}
matchPrefix
yieldActiveToFavorite
/>
{(isManagedCloud ||
Expand All @@ -985,6 +991,7 @@ export function SideMenu({
data-action="webhooks"
badge={<BetaBadge />}
isCollapsed={isCollapsed}
matchPrefix
yieldActiveToFavorite
/>
)}
Expand Down
36 changes: 34 additions & 2 deletions apps/webapp/app/components/navigation/SideMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,38 @@ export function SideMenuLabel({
);
}

function matchesPrefixPath(pathName: string, prefix: string): boolean {
const normalizedPrefix = prefix.replace(/\/+$/, "");
return pathName === normalizedPrefix || pathName.startsWith(`${normalizedPrefix}/`);
}

export function isRouteActive({
pathName,
to,
matchPrefix,
}: {
pathName: string;
to: string;
matchPrefix?: boolean | string | string[];
}): boolean {
if (pathName === to) return true;
if (!matchPrefix) return false;

if (typeof matchPrefix === "boolean") {
return matchesPrefixPath(pathName, to);
}

if (typeof matchPrefix === "string") {
return matchesPrefixPath(pathName, matchPrefix);
}

if (Array.isArray(matchPrefix)) {
return matchPrefix.some((prefix) => matchesPrefixPath(pathName, prefix));
}

return false;
}

export function SideMenuItem({
icon,
activeIconColor,
Expand Down Expand Up @@ -100,7 +132,7 @@ export function SideMenuItem({
indented?: boolean;
/** Overrides the default pathname === to active check (e.g. favorites match on full URL). */
isActive?: boolean;
matchPrefix?: boolean;
matchPrefix?: boolean | string | string[];
/**
* In menus that render the Favorites section (the main project menu), an active favorite owns
* the highlight, so the plain item yields its active state to it. Menus without a favorites
Expand All @@ -116,7 +148,7 @@ export function SideMenuItem({
const activeFavoriteId = useActiveFavoriteId();
const isActive =
isActiveOverride ??
((pathName === to || (matchPrefix && pathName.startsWith(`${to}/`))) &&
(isRouteActive({ pathName, to, matchPrefix }) &&
(!yieldActiveToFavorite || activeFavoriteId === undefined));

const isIndented = indented && !isCollapsed;
Expand Down
13 changes: 12 additions & 1 deletion apps/webapp/app/components/navigation/sideMenuSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type SideMenuItemConfig = {
activeIconColor: string;
inactiveIconColor?: string;
to: string;
matchPrefix?: boolean;
matchPrefix?: boolean | string | string[];
dataAction?: string;
badge?: ReactNode;
trailingIconClassName?: string;
Expand Down Expand Up @@ -122,6 +122,7 @@ export function buildSideMenuSections({
activeIconColor: "text-aiPrompts",
to: v3PromptsPath(organization, project, environment),
dataAction: "prompts",
matchPrefix: true,
},
{
id: "models",
Expand All @@ -130,6 +131,7 @@ export function buildSideMenuSections({
activeIconColor: "text-models",
to: v3ModelsPath(organization, project, environment),
dataAction: "models",
matchPrefix: true,
},
],
});
Expand Down Expand Up @@ -179,6 +181,7 @@ export function buildSideMenuSections({
activeIconColor: "text-errors",
to: v3ErrorsPath(organization, project, environment),
dataAction: "errors",
matchPrefix: true,
} satisfies SideMenuItemConfig,
]
: []),
Expand All @@ -199,6 +202,7 @@ export function buildSideMenuSections({
activeIconColor: "text-queues",
to: concurrencyPath(organization, project, environment),
dataAction: "queues",
matchPrefix: true,
} satisfies SideMenuItemConfig,
{
id: "dashboards",
Expand All @@ -207,6 +211,7 @@ export function buildSideMenuSections({
activeIconColor: "text-metrics",
to: v3DashboardsLandingPath(organization, project, environment),
dataAction: "dashboards-landing",
matchPrefix: true,
action: dashboards?.action,
after: dashboards?.after,
} satisfies SideMenuItemConfig,
Expand All @@ -227,6 +232,7 @@ export function buildSideMenuSections({
activeIconColor: "text-deployments",
to: v3DeploymentsPath(organization, project, environment),
dataAction: "deployments",
matchPrefix: true,
},
{
id: "preview-branches",
Expand Down Expand Up @@ -258,6 +264,7 @@ export function buildSideMenuSections({
activeIconColor: "text-text-bright",
to: v3ApiKeysPath(organization, project, environment),
dataAction: "api keys",
matchPrefix: true,
},
{
id: "environment-variables",
Expand All @@ -266,6 +273,7 @@ export function buildSideMenuSections({
activeIconColor: "text-environmentVariables",
to: v3EnvironmentVariablesPath(organization, project, environment),
dataAction: "environment variables",
matchPrefix: true,
},
...(featureFlags.trustedDeploysEnabled
? [
Expand Down Expand Up @@ -306,6 +314,7 @@ export function buildSideMenuSections({
activeIconColor: "text-sky-500",
to: v3WaitpointTokensPath(organization, project, environment),
dataAction: "waitpoint-tokens",
matchPrefix: true,
},
{
id: "batches",
Expand All @@ -314,6 +323,7 @@ export function buildSideMenuSections({
activeIconColor: "text-batches",
to: v3BatchesPath(organization, project, environment),
dataAction: "batches",
matchPrefix: true,
},
{
id: "bulk-actions",
Expand All @@ -322,6 +332,7 @@ export function buildSideMenuSections({
activeIconColor: "text-text-bright",
to: v3BulkActionsPath(organization, project, environment),
dataAction: "bulk actions",
matchPrefix: true,
},
...(alertsInObservability ? [] : [alertsItem]),
...(isManagedCloud
Expand Down
Loading