diff --git a/__tests__/components/ConditionalRedirect.test.jsx b/__tests__/components/ConditionalRedirect.test.jsx deleted file mode 100644 index c437ae6971..0000000000 --- a/__tests__/components/ConditionalRedirect.test.jsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import { - Route, - Redirect -} from 'react-router-dom'; -import { shallow } from 'enzyme'; -import ConditionalRedirect from '../../src/components/ConditionalRedirect'; - -describe('', () => { - test('renders Redirect when shouldRedirect is passed truthy func', () => { - const truthyFunc = () => true; - const shouldHaveRedirectChild = shallow( - truthyFunc()} - /> - ); - const redirectChild = shouldHaveRedirectChild.find(Redirect); - expect(redirectChild.length).toBe(1); - const routeChild = shouldHaveRedirectChild.find(Route); - expect(routeChild.length).toBe(0); - }); - - test('renders Route when shouldRedirect is passed falsy func', () => { - const falsyFunc = () => false; - const shouldHaveRouteChild = shallow( - falsyFunc()} - /> - ); - const routeChild = shouldHaveRouteChild.find(Route); - expect(routeChild.length).toBe(1); - const redirectChild = shouldHaveRouteChild.find(Redirect); - expect(redirectChild.length).toBe(0); - }); -}); diff --git a/src/App.jsx b/src/App.jsx index 0fd573d650..c03ecbcb06 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -5,7 +5,8 @@ import { HashRouter as Router, Redirect, Switch, - withRouter + withRouter, + Route, } from 'react-router-dom'; import { BackgroundImage, @@ -28,12 +29,10 @@ import { API_LOGOUT, API_CONFIG } from './endpoints'; import ja from '../build/locales/ja/messages'; import en from '../build/locales/en/messages'; - import Login from './pages/Login'; import HelpDropdown from './components/HelpDropdown'; import LogoutButton from './components/LogoutButton'; import TowerLogo from './components/TowerLogo'; -import ConditionalRedirect from './components/ConditionalRedirect'; import NavExpandableGroup from './components/NavExpandableGroup'; const catalogs = { en, ja }; @@ -61,6 +60,7 @@ class App extends React.Component { constructor(props) { super(props); + // initialize with a closed navbar if window size is small const isNavOpen = typeof window !== 'undefined' && window.innerWidth >= parseInt(breakpointMd.value, 10); @@ -95,10 +95,9 @@ class App extends React.Component { } render () { - const { isNavOpen } = this.state; - const { logo, loginInfo, history, routeConfig = [] } = this.props; + const { config, isNavOpen } = this.state; // extract a flattened array of all routes from the provided route config - const allRoutes = routeConfig.reduce((flattened, { routes }) => flattened.concat(routes), []); + const { logo, loginInfo, routeGroups = [] } = this.props; return ( @@ -108,82 +107,80 @@ class App extends React.Component { > {({ i18n }) => ( - - - + api.isAuthenticated () ? ( + - api.isAuthenticated()} - redirectPath="/" - path="/login" - component={() => } - /> - - } - toolbar={( - - - - - - - this.onDevLogout()} /> - - - - )} - showNavToggle - onNavToggle={this.onNavToggle} - /> - )} - sidebar={( - - - { routeConfig.map(({ groupId, routes, title }) => ( - ({ - path: route.path, - component: route.component, - title: i18n._(route.title) - }))} - /> - ))} - - - )} - /> - )} - > - !api.isAuthenticated()} - redirectPath="/login" - exact path="/" - component={() => ()} - /> - { allRoutes.map(({ component, path }) => ( - !api.isAuthenticated()} - component={component} - /> - ))} - - + } /> + } /> + ( + + + this.onNavToggle()} + logo={( + + )} + toolbar={( + + + + + + + this.onDevLogout()} + /> + + + + )} + /> + )} + sidebar={( + + + { + routeGroups.map(params => ) + } + + + )} + /> + )} + > + { + // + // Extract a flattened array of all route params from the provided route groups + // and use it to create the route components. + // + // [{ routes }, { routes }] -> [route, route, route] -> () + // + routeGroups + .reduce((allRoutes, { routes }) => allRoutes.concat(routes), []) + .map(({ component: Component, path }) => ( + } /> + )) + } + + + )} /> - + ) : ( + + } /> + + + ) )} diff --git a/src/components/ConditionalRedirect.jsx b/src/components/ConditionalRedirect.jsx deleted file mode 100644 index 7a2112326e..0000000000 --- a/src/components/ConditionalRedirect.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import { - Route, - Redirect -} from 'react-router-dom'; - -const ConditionalRedirect = ({ - component: Component, - shouldRedirect, - redirectPath, - location, - ...props -}) => (shouldRedirect() ? ( - -) : ( - ()} /> -)); - -export default ConditionalRedirect;