Skip to content

Commit

Permalink
add sidenav highlight support for children of features (#51569)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudream authored Jan 29, 2025
1 parent 524a10b commit 744b023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion web/packages/teleport/src/Login/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export type State = ReturnType<typeof useLogin> & {
* moveToFront returns a copy of an array with the element that matches the condition to the front of it.
*/
function moveToFront<T>(arr: T[], condition: (item: T) => boolean): T[] {
console.log(arr);
const copy = [...arr];
const index = copy.findIndex(condition);

Expand Down
9 changes: 8 additions & 1 deletion web/packages/teleport/src/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function getNavSubsectionForRoute(
features: TeleportFeature[],
route: history.Location<unknown> | Location
): NavigationSubsection {
const feature = features
let feature = features
.filter(feature => Boolean(feature.route))
.find(feature =>
matchPath(route.pathname, {
Expand All @@ -197,6 +197,13 @@ function getNavSubsectionForRoute(
})
);

// If this is a child feature, use its parent as the subsection instead.
// We do this because children of features don't appear as subsections in the sidenav, but we want to highlight
// their parent's subsection as active.
if (feature?.parent) {
feature = features.find(f => f instanceof feature.parent);
}

if (
!feature ||
(!feature.category && !feature.topMenuItem && !feature.navigationItem)
Expand Down

0 comments on commit 744b023

Please sign in to comment.