Commit 72091dfd authored by Florian Pagnoux's avatar Florian Pagnoux
Browse files

Introduce breadcrum

parent ad8455e5
......@@ -2,10 +2,24 @@ import {withRouter} from 'next/router'
import ParameterTable from "../components/ParameterTable"
import Layout from '../components/Layout'
import {basename} from '../config'
const BreadCrum = ({links}) => (
<p><a href={basename + '/'}>Barèmes IPP</a>{links.map(({path, title}, index) => {
if (! title) {
return
}
if (! path) {
return <span key={index}> >> {title}</span>
}
return <span key={index}> >> <a href={`${basename}/${path}`}>{title}</a></span>
})}</p>
)
const TablePage = (props) => {
const parameter = props.router.query
const {parameter, parents} = props.router.query
return <Layout fullWidth={ true }>
<BreadCrum links={parents}/>
<h1 className="box"><span>{parameter.description}</span></h1>
<ParameterTable parameter={parameter}/>
</Layout>
......
......@@ -5,6 +5,7 @@ const yaml = require('js-yaml');
const map = require('lodash.map')
const flatten = require('lodash.flatten')
const fromPairs = require('lodash.frompairs')
const get = require('lodash.get')
const resolver = require('./resolver')
......@@ -25,27 +26,40 @@ async function loadParametersTree() {
async function loadRoutes() {
const parametersTree = await loadParametersTree()
const routes = map(parametersTree, ((content, fileName) => extractRoutes(content, `/${fileName}`)))
const routes = map(parametersTree, extractRoutes)
return flatten(routes)
}
function extractRoutes(desc, path) {
function addLeadingSlash(string) {
return string.startsWith('/') ? string : `/${string}`
}
function extractRoutes(desc, path, parametersTree, parents = []) {
const isPage = ! parents.length
if (desc.table) {
return [{
route: path,
route: addLeadingSlash(path),
page: '/table',
query: desc.table,
query: {parameter: desc.table, parents}
}]
}
if (desc.subparams) {
const sectionRoute = {
route: path,
route: addLeadingSlash(path),
page: '/section',
query: desc
}
return [sectionRoute].concat(flatten(map(desc.subparams, (child, key) => {
return extractRoutes(child, `${path}/${key}`)
})))
const subRoutes = flatten(map(desc.subparams, (child, key) => {
return extractRoutes(
child,
`${path}/${key}`,
parametersTree,
parents.concat(
[{path: isPage && path, title: desc.title || desc.description}]
)
)
}))
return isPage ? [sectionRoute].concat(subRoutes) : subRoutes
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment