Commit 9a97ac39 authored by Florian Pagnoux's avatar Florian Pagnoux
Browse files

Use new order metadata to sort nodes

parent 4e31cfbf
......@@ -2,6 +2,8 @@ import map from 'lodash.map'
import range from 'lodash.range'
import size from 'lodash.size'
import isString from 'lodash.isstring'
import sortBy from 'lodash.sortby'
import flow from 'lodash.flow'
import { FormattedDate, IntlProvider, addLocaleData, FormattedNumber} from 'react-intl'
import fr from 'react-intl/locale-data/fr'
......@@ -64,7 +66,11 @@ function buildColumn(parameter) {
if (parameter.subparams) {
return {
Header: parameter.description || parameter.id,
columns: map(parameter.subparams, buildColumn)
columns: flow([
x => map(x, (subParam, name) => Object.assign({}, subParam, {name})),
x => sortBy(x, subParam => parameter?.metadata?.order.indexOf(subParam.name)),
x => map(x, buildColumn)
])(parameter.subparams)
}
}
}
......
......@@ -9,7 +9,7 @@ import sortBy from 'lodash.sortby';
function renderSubParams(item, key, path) {
const subParams = isArray(item.subparams) ? item.subparams : flow([
x => map(x, (subParam, name) => Object.assign({}, subParam, {name})),
x => sortBy(x, subParam => subParam?.metadata?.rank || subParam?.table?.metadata.rank)
x => sortBy(x, subParam => item?.metadata?.order.indexOf(subParam.name))
])(item.subparams)
return map(subParams, subParam => {
......@@ -39,7 +39,7 @@ const Section = (props) => {
const path = props.router.asPath.endsWith('/') ? props.router.asPath : props.router.asPath + '/'
const subParams = flow([
x => map(x, (subParam, name) => Object.assign({}, subParam, {name})),
x => sortBy(x, subParam => subParam.metadata && subParam.metadata.rank)
x => sortBy(x, subParam => section?.metadata?.order.indexOf(subParam.name))
])(section.subparams)
return <Layout>
......
title: Retraite
subsection: retraites
depth: 1
subparams:
- subsection: retraites.secteur_prive
depth: 1
- subsection: retraites.secteur_public
- subsection: retraites.independants
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