From dfbdcc093ac09170c2bac9fa209ccd3b1eb318c3 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Mon, 5 Dec 2016 17:04:00 +0100 Subject: [PATCH] generate header based on routes --- frontend/src/component/app.jsx | 46 +++++++++++++++++++++++++++++++++- frontend/src/index.jsx | 35 ++++++++++++++++++-------- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/frontend/src/component/app.jsx b/frontend/src/component/app.jsx index da7081e7c9..8dc7818601 100644 --- a/frontend/src/component/app.jsx +++ b/frontend/src/component/app.jsx @@ -3,12 +3,28 @@ import { Layout, Drawer, Header, Navigation, Content, Footer, FooterSection, FooterDropDownSection, FooterLinkList, Grid, Cell, } from 'react-mdl'; +import { Link } from 'react-router'; import style from './styles.scss'; import ErrorContainer from './error/error-container'; import UserContainer from './user/user-container'; import ShowUserContainer from './user/show-user-container'; +const base = { + name: 'Unleash', + link: '/', +}; + +function replace (input, params) { + if (!params) { + return input; + } + Object.keys(params).forEach(key => { + input = input.replace(`:${key}`, params[key]); + }); + return input; +} + export default class App extends Component { constructor (props) { super(props); @@ -32,6 +48,34 @@ export default class App extends Component { return lastRoute ? lastRoute.pageTitle : ''; } + getTitleWithLinks () { + const { routes, params } = this.props; + const unique = {}; + let result = [base].concat(routes.splice(1).map((routeEntry) => ({ + name: replace(routeEntry.pageTitle, params), + link: replace(routeEntry.link || routeEntry.path, params), + }))).filter(entry => { + if (!unique[entry.link]) { + unique[entry.link] = true; + return true; + } + return false; + }); + + if (result.length > 2) { + result = result.splice(1); + } + return ( + + {result.map((entry, index) => ( + + {entry.name} + {(index + 1) < result.length ? ' / ' : null} + ))} + + ); + } + onOverlayClick = () => this.setState({ drawerActive: false }); render () { @@ -46,7 +90,7 @@ export default class App extends Component {
-
Unleash Admin / {this.getCurrentSection()}}> +
Github diff --git a/frontend/src/index.jsx b/frontend/src/index.jsx index 376f432bca..1d5591655e 100644 --- a/frontend/src/index.jsx +++ b/frontend/src/index.jsx @@ -29,22 +29,37 @@ const unleashStore = createStore( ) ); +// "pageTitle" and "link" attributes are for internal usage only + ReactDOM.render( - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + + + +