Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed the single submenus as per issue:OGC-17 #1354

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions frontend/cypress/pages/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ class HomePage {
goToPathologyDashboard() {
this.openNavigationMenu();
cy.get("#menu_pathology_dropdown").click();
cy.get("#menu_pathologydashboard_nav").click();
cy.get("#menu_pathologydashboard_nav").click({force:true});
return new DashBoardPage();
}

goToImmunoChemistryDashboard() {
this.openNavigationMenu();
cy.get("#menu_immunochem_dropdown").click();
cy.get("#menu_immunochemdashboard_nav").click();
cy.get("#menu_immunochemdashboard_nav").click({force:true});
return new DashBoardPage();
}
}
Expand Down
129 changes: 80 additions & 49 deletions frontend/src/components/layout/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,44 @@ function OEHeader(props) {
setSearchBar(!searchBar);
};
const generateMenuItems = (menuItem, index, level, path) => {
if (menuItem.menu.isActive) {
if (level === 0 && menuItem.childMenus.length > 0) {
if (!menuItem.menu.isActive) {
return <React.Fragment key={path}></React.Fragment>;
}

const activeChildMenus = menuItem.childMenus.filter(
(child) => child.menu.isActive,
);

if (level === 0) {
// For top level items with exactly one active child, render direct link
if (activeChildMenus.length === 1) {
const singleChildMenu = activeChildMenus[0];
return (
<span
key={path}
id={menuItem.menu.elementId}
style={{ position: "relative", zIndex: 10 }}
>
<span
id={menuItem.menu.elementId + "_dropdown"}
style={{ position: "relative", zIndex: 5 }}
>
<SideNavMenuItem
id={menuItem.menu.elementId + "dashboard_nav"}
href={singleChildMenu.menu.actionURL}
target={singleChildMenu.menu.openInNewWindow ? "_blank" : ""}
className="top-level-menu-item"
style={{ position: "relative", zIndex: 15 }}
>
{renderSideNavMenuItemLabel(menuItem, level)}
</SideNavMenuItem>
</span>
</span>
);
}

// Multiple active children - show dropdown
if (menuItem.childMenus.length > 0) {
return (
<span id={menuItem.menu.elementId} key={path}>
<span
Expand All @@ -202,9 +238,6 @@ function OEHeader(props) {
})}
key={"menu_" + index + "_" + level}
defaultExpanded={menuItem.expanded}
// onClick={(e) => { // not supported yet, but if it becomes so we can simplify the functionality here by having this here and not have a span around it
// setMenuItemExpanded(e, menuItem, path);
// }}
>
<span
onClick={(e) => {
Expand All @@ -225,7 +258,7 @@ function OEHeader(props) {
</span>
</span>
);
} else if (level === 0) {
} else {
return (
<span key={path} id={menuItem.menu.elementId}>
<SideNavMenuItem
Expand All @@ -238,53 +271,51 @@ function OEHeader(props) {
</SideNavMenuItem>
</span>
);
} else {
return (
<span id={menuItem.menu.elementId} key={path}>
<SideNavMenuItem
className="reduced-padding-nav-menu-item"
href={menuItem.menu.actionURL}
target={menuItem.menu.openInNewWindow ? "_blank" : ""}
style={{ width: "100%" }}
rel="noreferrer"
>
<span style={{ display: "flex", width: "100%" }}>
{!menuItem.menu.actionURL &&
!hasActiveChildMenu(menuItem) &&
console.warn("menu entry has no action url and no child")}
{!hasActiveChildMenu(menuItem) &&
renderSingleNavButton(menuItem, index, level, path)}
{!menuItem.menu.actionURL &&
hasActiveChildMenu(menuItem) &&
renderSingleDropdownButton(menuItem, index, level, path)}
{menuItem.menu.actionURL &&
hasActiveChildMenu(menuItem) &&
renderDualNavDropdownButton(menuItem, index, level, path)}
</span>
</SideNavMenuItem>
{menuItem.childMenus.map((childMenuItem, index) => {
return (
<span
key={path + ".childMenus[" + index + "].span"}
style={{ display: menuItem.expanded ? "" : "none" }}
>
{generateMenuItems(
childMenuItem,
index,
level + 1,
path + ".childMenus[" + index + "]",
)}
</span>
);
})}
</span>
);
}
} else {
return <React.Fragment key={path}></React.Fragment>;
return (
<span id={menuItem.menu.elementId} key={path}>
<SideNavMenuItem
className="reduced-padding-nav-menu-item"
href={menuItem.menu.actionURL}
target={menuItem.menu.openInNewWindow ? "_blank" : ""}
style={{ width: "100%" }}
rel="noreferrer"
>
<span style={{ display: "flex", width: "100%" }}>
{!menuItem.menu.actionURL &&
!hasActiveChildMenu(menuItem) &&
console.warn("menu entry has no action url and no child")}
{!hasActiveChildMenu(menuItem) &&
renderSingleNavButton(menuItem, index, level, path)}
{!menuItem.menu.actionURL &&
hasActiveChildMenu(menuItem) &&
renderSingleDropdownButton(menuItem, index, level, path)}
{menuItem.menu.actionURL &&
hasActiveChildMenu(menuItem) &&
renderDualNavDropdownButton(menuItem, index, level, path)}
</span>
</SideNavMenuItem>
{menuItem.childMenus.map((childMenuItem, index) => {
return (
<span
key={path + ".childMenus[" + index + "].span"}
style={{ display: menuItem.expanded ? "" : "none" }}
>
{generateMenuItems(
childMenuItem,
index,
level + 1,
path + ".childMenus[" + index + "]",
)}
</span>
);
})}
</span>
);
}
};

const hasActiveChildMenu = (menuItem) => {
if (menuItem.menu.elementId === "menu_reports_routine") {
console.log("reports");
Expand Down
Loading