From 7b1564c56978375c050e0593870a7c16c0d0bf69 Mon Sep 17 00:00:00 2001 From: Jose Sousa Date: Wed, 25 Nov 2020 10:52:51 +0000 Subject: [PATCH] fix: redirect to third level --- new-lamassu-admin/src/App.js | 17 +++----- new-lamassu-admin/src/routing/routes.js | 52 ++++++++++++------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/new-lamassu-admin/src/App.js b/new-lamassu-admin/src/App.js index fe50fead..66e2ba1a 100644 --- a/new-lamassu-admin/src/App.js +++ b/new-lamassu-admin/src/App.js @@ -20,13 +20,7 @@ import TitleSection from 'src/components/layout/TitleSection' import ApolloProvider from 'src/utils/apollo' import Header from './components/layout/Header' -import { - getTitle, - tree, - hasSidebar, - Routes, - getSidebarData -} from './routing/routes' +import { tree, hasSidebar, Routes, getParent } from './routing/routes' import global from './styling/global' import theme from './styling/theme' import { backgroundColor, mainWidth } from './styling/variables' @@ -84,9 +78,8 @@ const Main = () => { const route = location.pathname - const title = getTitle(route) const sidebar = hasSidebar(route) - const sidebarData = sidebar ? getSidebarData(route) : [] + const parent = sidebar ? getParent(route) : {} const is404 = location.pathname === '/404' @@ -102,14 +95,14 @@ const Main = () => {
{!is404 && wizardTested &&
}
- {title && !is404 && wizardTested && ( - + {sidebar && !is404 && wizardTested && ( + )} {sidebar && !is404 && wizardTested && ( it.label} onClick={onClick} diff --git a/new-lamassu-admin/src/routing/routes.js b/new-lamassu-admin/src/routing/routes.js index b7918eb7..de280ba2 100644 --- a/new-lamassu-admin/src/routing/routes.js +++ b/new-lamassu-admin/src/routing/routes.js @@ -128,32 +128,32 @@ const tree = [ key: namespaces.OPERATOR_INFO, label: 'Operator Info', route: '/settings/operator-info', + title: 'Operator Information', + get component() { + return () => + }, children: [ { key: 'contact-info', label: 'Contact information', - title: 'Operator information', route: '/settings/operator-info/contact-info', component: ContactInfo }, { key: 'receipt-printing', label: 'Receipt', - title: 'Operator information', route: '/settings/operator-info/receipt-printing', component: ReceiptPrinting }, { key: 'coin-atm-radar', label: 'Coin ATM Radar', - title: 'Operator information', route: '/settings/operator-info/coin-atm-radar', component: CoinAtmRadar }, { key: 'terms-conditions', label: 'Terms & Conditions', - title: 'Operator information', route: '/settings/operator-info/terms-conditions', component: TermsConditions } @@ -214,31 +214,32 @@ const tree = [ const map = R.map(R.when(R.has('children'), R.prop('children'))) const mappedRoutes = R.compose(R.flatten, map)(tree) -const parentRoutes = R.filter(R.has('children'))(tree).concat( - R.filter(R.has('children'))(mappedRoutes) +const parentRoutes = R.filter(R.has('children'))(mappedRoutes).concat( + R.filter(R.has('children'))(tree) ) const leafRoutes = R.compose(R.flatten, map)(mappedRoutes) -const thirdLevelRoutes = R.compose( - R.flatten, - R.map(R.prop('children')), - R.filter(R.has('children')) -)(mappedRoutes) + const flattened = R.concat(leafRoutes, parentRoutes) -const getTitle = route => - R.prop('title', R.find(R.propEq('route', route))(flattened)) - -const hasSidebar = route => R.any(r => r.route === route, thirdLevelRoutes) - -const getSidebarData = route => { - const parentRoute = R.dropLast( - 1, - R.dropLastWhile(x => x !== '/', route) +const hasSidebar = route => + R.any(r => r.route === route)( + R.compose( + R.flatten, + R.map(R.prop('children')), + R.filter(R.has('children')) + )(mappedRoutes) ) - const parent = R.find(R.propEq('route', parentRoute))(flattened) - return parent?.children -} +const getParent = route => + R.find( + R.propEq( + 'route', + R.dropLast( + 1, + R.dropLastWhile(x => x !== '/', route) + ) + ) + )(flattened) const Routes = () => { const history = useHistory() @@ -256,9 +257,6 @@ const Routes = () => { - - - {flattened.map(({ route, component: Page, key }) => ( @@ -273,4 +271,4 @@ const Routes = () => { ) } -export { getTitle, tree, getSidebarData, hasSidebar, Routes } +export { tree, getParent, hasSidebar, Routes }