saleor-dashboard/src/components/SideBar/utils.ts
Dominik Żegleń 33d680639b
Add new side menu navigation (#819)
Update snapshots

Fix savebar

Fix cypress

Update messages

Fix cypress
2020-11-18 16:11:15 +01:00

24 lines
722 B
TypeScript

import { orderDraftListUrl, orderListUrl } from "@saleor/orders/urls";
import { matchPath } from "react-router";
import { IMenuItem } from "../AppLayout/menuStructure";
export function isMenuActive(location: string, menuItem: IMenuItem) {
if (menuItem.children) {
return menuItem.children.reduce(
(acc, subMenuItem) => acc || isMenuActive(location, subMenuItem),
false
);
}
const activeUrl = location.split("?")[0];
const menuItemUrl = menuItem.url.split("?")[0];
return activeUrl === orderDraftListUrl().split("?")[0] &&
menuItemUrl === orderListUrl().split("?")[0]
? false
: !!matchPath(activeUrl, {
exact: menuItemUrl === "/",
path: menuItemUrl
});
}