Skip to content

Commit

Permalink
ISPN-11786 Fix menu nav selected
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed May 6, 2020
1 parent 601691c commit c3cb25d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
41 changes: 32 additions & 9 deletions src/app/AppLayout/AppLayout.tsx
@@ -1,9 +1,6 @@
import * as React from 'react';
import { useState } from 'react';
import {useState} from 'react';
import {
Alert,
AlertActionCloseButton,
AlertGroup,
Brand,
Nav,
NavItem,
Expand All @@ -15,10 +12,10 @@ import {
SkipToContent
} from '@patternfly/react-core';
import icon from '!!url-loader!@app/assets/images/brand.svg';
import { NavLink } from 'react-router-dom';
import { routes } from '@app/routes';
import { APIAlertProvider } from '@app/providers/APIAlertProvider';
import { ActionResponseAlert } from '@app/Common/ActionResponseAlert';
import {NavLink} from 'react-router-dom';
import {routes} from '@app/routes';
import {APIAlertProvider} from '@app/providers/APIAlertProvider';
import {ActionResponseAlert} from '@app/Common/ActionResponseAlert';

interface IAppLayout {
children: React.ReactNode;
Expand Down Expand Up @@ -81,7 +78,21 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({
key={`${route.label}-${idx}`}
id={`${route.label}-${idx}`}
>
<NavLink exact to={route.path} activeClassName="pf-m-current">
<NavLink exact to={route.path} activeClassName="pf-m-current" isActive={(match, location) => {
if (match) {
return true;
}
let isSubRoute = false;
if(route.subRoutes != null) {
for (let i = 0; i < route.subRoutes.length; i++) {
if (location.pathname.includes(route.subRoutes[i])) {
isSubRoute = true;
break;
}
}
}
return isSubRoute;
}}>
{route.label}
</NavLink>
</NavItem>
Expand All @@ -91,6 +102,18 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({
</Nav>
);

const isActive = (match, location) => {
console.log("mierda");
console.log(location);
if (!match) {
return false;
}

// only consider an event active if its event id is an odd number
const eventID = parseInt(match.params.eventID);
return !isNaN(eventID) && eventID % 2 === 1;
};

const Sidebar = (
<PageSidebar
theme="dark"
Expand Down
4 changes: 3 additions & 1 deletion src/app/routes.tsx
Expand Up @@ -97,6 +97,7 @@ export interface IAppRoute {
title: string;
isAsync?: boolean;
menu?: boolean;
subRoutes?: string[];
}

const routes: IAppRoute[] = [
Expand All @@ -114,7 +115,8 @@ const routes: IAppRoute[] = [
label: 'Data Container',
path: '/',
title: 'Data Container',
menu: true
menu: true,
subRoutes:['container', 'cache']
},
{
component: GlobalStats,
Expand Down

0 comments on commit c3cb25d

Please sign in to comment.