2018-08-06 22:16:36 +02:00
|
|
|
|
import React from 'react';
|
|
|
|
|
import { Link, Route, Switch } from 'react-router-dom';
|
|
|
|
|
|
|
|
|
|
import { routes, getRoute } from './routes';
|
|
|
|
|
|
2021-01-07 13:36:13 +01:00
|
|
|
|
import styles from '../styles.module.scss';
|
2018-08-06 22:16:36 +02:00
|
|
|
|
|
|
|
|
|
const renderDoubleBread = (currentTitle, parentRoute) => {
|
|
|
|
|
document.title = `${currentTitle} - ${parentRoute.title} - Unleash`;
|
|
|
|
|
return (
|
|
|
|
|
<span>
|
2021-03-30 15:14:02 +02:00
|
|
|
|
<Link className={styles.headerTitleLink} to={parentRoute.path}>
|
2018-08-06 22:16:36 +02:00
|
|
|
|
{parentRoute.title}
|
|
|
|
|
</Link>
|
2021-03-30 15:14:02 +02:00
|
|
|
|
<span>
|
2018-08-06 22:16:36 +02:00
|
|
|
|
<span> › </span>
|
2021-03-30 15:14:02 +02:00
|
|
|
|
<span className={styles.headerTitleLink}>{currentTitle}</span>
|
2018-08-06 22:16:36 +02:00
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderBread = route => {
|
|
|
|
|
document.title = `${route.title} - Unleash`;
|
|
|
|
|
return (
|
2021-03-30 15:14:02 +02:00
|
|
|
|
<span>
|
|
|
|
|
<span className={styles.headerTitleLink}>{route.title}</span>
|
2018-08-06 22:16:36 +02:00
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderRoute = (params, route) => {
|
|
|
|
|
if (!route) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-05-04 09:59:42 +02:00
|
|
|
|
const title = route.title.startsWith(':')
|
|
|
|
|
? params[route.title.substring(1)]
|
|
|
|
|
: route.title;
|
|
|
|
|
return route.parent
|
|
|
|
|
? renderDoubleBread(title, getRoute(route.parent))
|
|
|
|
|
: renderBread(route);
|
2018-08-06 22:16:36 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Render the breadcrumb.
|
|
|
|
|
|
|
|
|
|
We only support two levels.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
- Features
|
|
|
|
|
- Features > Create
|
|
|
|
|
- Features > SomeToggle
|
|
|
|
|
*/
|
|
|
|
|
const Breadcrumb = () => (
|
|
|
|
|
<Switch>
|
|
|
|
|
{routes.map(route => (
|
|
|
|
|
<Route
|
|
|
|
|
key={route.path}
|
|
|
|
|
path={route.path}
|
2021-05-04 09:59:42 +02:00
|
|
|
|
render={({ match: { params } } = this.props) =>
|
|
|
|
|
renderRoute(params, route)
|
|
|
|
|
}
|
2018-08-06 22:16:36 +02:00
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Switch>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default Breadcrumb;
|