import React from 'react'; import NavItem from './NavItem'; import { withRouter } from 'next/router'; import { List } from '@material-ui/core'; import { navItems } from './navigationMap'; import { stringToTestId } from 'utils/helpers'; class NavigationMenu extends React.Component { mapNavigation(depth: number) { return ({ title, children, href, as }: any) => { const { asPath } = this.props.router; const hasChildren = children && children.length > 0; const open = hasChildren ? children.some((item: any) => item.href === asPath || item.as === asPath) : false; return ( {children && children.length > 0 && children.map(this.mapNavigation(depth + 1))} ); }; } render() { return {navItems.map(this.mapNavigation(0))}; } } export default withRouter(NavigationMenu);