Skip to content

Commit

Permalink
HPCC-32601 ECL Watch v9 fix disappearing subnavigation
Browse files Browse the repository at this point in the history
fixes an issue where the subnavigation would not display properly on
page load if a query-string existed in the url

Signed-off-by: Jeremy Clements <[email protected]>
  • Loading branch information
jeclrsg committed Sep 9, 2024
1 parent c8117d4 commit f8773e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions esp/src/src-react/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useConst } from "@fluentui/react-hooks";
import nlsHPCC from "src/nlsHPCC";
import { hasLogAccess } from "src/ESPLog";
import { containerized, bare_metal } from "src/BuildInfo";
import { navCategory } from "../util/history";
import { MainNav, routes } from "../routes";
import { useFavorite, useFavorites, useHistory } from "../hooks/favorite";
import { useSessionStore } from "../hooks/store";
Expand Down Expand Up @@ -98,7 +99,7 @@ routes.forEach((route: any) => {
});

function navSelectedKey(hashPath) {
const rootPath = navIdx(`/${hashPath?.split("/")[1]}`);
const rootPath = navIdx(`/${navCategory(hashPath)?.split("/")[1]}`);
if (rootPath?.length) {
return rootPath[0];
}
Expand Down Expand Up @@ -214,8 +215,8 @@ for (const key in subMenuItems) {
}

function subNavSelectedKey(hashPath) {
const hashCategory = hashPath.split("/").slice(0, 3).join("/");
return subNavIdx(hashCategory).length ? hashCategory : null;
const category = navCategory(hashPath);
return subNavIdx(category).length ? category : null;
}

interface SubNavigationProps {
Expand Down
8 changes: 8 additions & 0 deletions esp/src/src-react/util/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ export function updateState(key: string, val?: string | string[] | number | bool
}
globalHistory.replaceState(state, "");
}

export function navCategory(hash: string): string {
let category = hash.split("/").slice(0, 2).join("/");
if (category.indexOf("?") > -1) {
category = category.substring(0, category.indexOf("?"));
}
return category;
}

0 comments on commit f8773e4

Please sign in to comment.