diff --git a/src/App.jsx b/src/App.jsx index 53cc835047..38465599d8 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -28,8 +28,7 @@ import HelpDropdown from './components/HelpDropdown'; import LogoutButton from './components/LogoutButton'; import TowerLogo from './components/TowerLogo'; import ConditionalRedirect from './components/ConditionalRedirect'; -import NavExpandable from './components/NavExpandable'; -import NavItem from './components/NavItem'; +import NavExpandableGroup from './components/NavExpandableGroup'; import Applications from './pages/Applications'; import Credentials from './pages/Credentials'; @@ -149,164 +148,58 @@ class App extends React.Component { {({ i18n }) => ( )} diff --git a/src/components/NavExpandable.jsx b/src/components/NavExpandable.jsx deleted file mode 100644 index b6cf0c7f0e..0000000000 --- a/src/components/NavExpandable.jsx +++ /dev/null @@ -1,44 +0,0 @@ -import React, { Component } from 'react'; -import { - withRouter -} from 'react-router-dom'; -import { - NavExpandable, - NavItem, -} from '@patternfly/react-core'; - -class NavExpandableWrapper extends Component { - constructor (props) { - super(props); - // introspect to get any child 'NavItem' components - const { children } = this.props; - const navItems = children.filter(({ type }) => type.componentType === NavItem.displayName); - - // Extract a list of 'to' params from the nav items and store it for later. This will create - // an array of the url paths associated with any child NavItem components. - this.navItemPaths = navItems.map(item => item.props.to.replace('/#', '')); - } - - isActiveGroup = () => { - const { history } = this.props; - - return this.navItemPaths.some(path => history.location.pathname.includes(path)); - }; - - render () { - const { children, staticContext, ...rest } = this.props; - const isActive = this.isActiveGroup(); - - return ( - - { children } - - ); - } -} - -export default withRouter(NavExpandableWrapper); diff --git a/src/components/NavExpandableGroup.jsx b/src/components/NavExpandableGroup.jsx new file mode 100644 index 0000000000..70cdbf5adb --- /dev/null +++ b/src/components/NavExpandableGroup.jsx @@ -0,0 +1,53 @@ +import React, { Component } from 'react'; +import { + withRouter +} from 'react-router-dom'; +import { + NavExpandable, + NavItem, +} from '@patternfly/react-core'; + +class NavExpandableGroup extends Component { + constructor (props) { + super(props); + const { routes } = this.props; + // Extract a list of paths from the route params and store them for later. This creates + // an array of url paths associated with any NavItem component rendered by this component. + this.navItemPaths = routes.map(({ path }) => path); + } + + isActiveGroup = () => this.navItemPaths.some(this.isActivePath); + + isActivePath = (path) => { + const { history } = this.props; + + return history.location.pathname.includes(path); + }; + + render () { + const { routes, groupId, staticContext, ...rest } = this.props; + const isActive = this.isActiveGroup(); + + return ( + + {routes.map(({ path, title }) => ( + + {title} + + ))} + + ); + } +} + +export default withRouter(NavExpandableGroup); diff --git a/src/components/NavItem.jsx b/src/components/NavItem.jsx deleted file mode 100644 index 5610b09b4c..0000000000 --- a/src/components/NavItem.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; -import { withRouter } from 'react-router-dom'; -import { NavItem } from '@patternfly/react-core'; - -export default withRouter(({ history, to, staticContext, ...props }) => ( - -));