Commit 0f19e934 authored by Florian Pagnoux's avatar Florian Pagnoux
Browse files

Include metadata in view

parent 9a97ac39
......@@ -40,6 +40,11 @@ it('extractValues can extract dates from a parameter node', () => {
expect(data['prestations.minima_sociaux.rsa.forfait_logement.taux_2_personnes']).toEqual({"2009-06-01": {value: 0.16}})
});
it('extractValues can extract metadata from a parameter node', () => {
const data = extractValues(rsaForFaitLogement)
expect(data['date_parution_jo']).toEqual({"2009-06-01": "2009-05-01"})
});
it('extractValues can extract dates from a custom parameter node', () => {
const data = extractValues(rsaMajoration)
expect(data['prestations.minima_sociaux.rsa.majoration_rsa.taux_deuxieme_personne']).toEqual({"2009-06-01": {value: 0.5}})
......
......@@ -24,5 +24,10 @@
}
},
"description": "Forfait logement (en % du montant forfaitaire du RSA)",
"id": "prestations.minima_sociaux.rsa.forfait_logement"
"id": "prestations.minima_sociaux.rsa.forfait_logement",
"metadata": {
"date_parution_jo": {
"2009-06-01": "2009-05-01"
}
}
}
import map from 'lodash.map'
import filter from 'lodash.filter'
import range from 'lodash.range'
import size from 'lodash.size'
import isString from 'lodash.isstring'
......@@ -69,12 +70,31 @@ function buildColumn(parameter) {
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)
x => map(x, buildColumn),
x => x.concat(buildMetaDataColumns(parameter))
])(parameter.subparams)
}
}
}
function buildMetaDataColumns(parameter) {
const metadata = {
reference: {title: 'Références législatives', width: 1.8},
date_parution_jo: {title: 'Parution au JO', width: 0.7},
notes: {title: 'Notes', width: 2},
}
return flow([
x => filter(x, fieldName => parameter.metadata[fieldName]),
x => map(x, fieldName => ({
Header: metadata[fieldName].title,
accessor: item => item[fieldName],
id: fieldName,
width: metadata[fieldName].width
}))
])(Object.keys(metadata))
}
const ParameterTable = ({parameter}) => {
const data = extractData(parameter)
const dateColumn = {
......@@ -86,10 +106,13 @@ const ParameterTable = ({parameter}) => {
const columns = [dateColumn, buildColumn(parameter)]
return (
<IntlProvider locale="fr">
<Table
columns={columns}
data={data}
/>
<div>
<Table
columns={columns}
data={data}
/>
<p className="table-doc">{parameter.documentation}</p>
</div>
</IntlProvider>
)
}
......
......@@ -59,7 +59,7 @@ function renderHeader(columns, index) {
key={index2}
colSpan={column.colSpan}
rowSpan={column.rowSpan || 1}
style={{flex:`${column.colSpan * 100} 0 auto`, width:`${column.colSpan * 100}px`}}
style={{flex: `${column.width || 1} 0 auto`, 'width': `${(column.width || 1) * 100}px`}}
>
{column.Header}
</th>
......@@ -86,7 +86,11 @@ function renderData(data, dataColumns) {
return data.map((datum, index) => {
return <tr key={index}>
{dataColumns.map((column, index2) => {
return <td key={index2} style={{flex: '100 0 auto', width:'100px'}}>
return <td
key={index2}
colSpan={column.colSpan}
style={{flex: `${column.width || 1} 0 auto`, 'width': `100px`}}
>
<span>{renderDatum(datum, column)}</span>
</td>
})}
......
......@@ -2,7 +2,7 @@ import Layout from '../components/Layout'
import { withRouter } from 'next/router'
import map from 'lodash.map'
import isArray from 'lodash.isarray'
import contains from 'lodash.contains'
import includes from 'lodash.includes'
import flow from 'lodash.flow';
import sortBy from 'lodash.sortby';
......@@ -13,7 +13,7 @@ function renderSubParams(item, key, path) {
])(item.subparams)
return map(subParams, subParam => {
if (item.exclude && contains(item.exclude, subParam.name)) {
if (item.exclude && includes(item.exclude, subParam.name)) {
return
}
return renderItem(subParam, subParam.name, `${path}${key}/`)
......
/** Process a parameterNode so that the data it contains are easily exploitable by React-Table */
import map from 'lodash.map';
import mapValues from 'lodash.mapvalues';
import includes from 'lodash.includes'
import flatten from 'lodash.flatten';
import flow from 'lodash.flow';
import merge from 'lodash.merge';
import union from 'lodash.union';
import keys from 'lodash.keys'
import last from 'lodash.last'
import fromPairs from 'lodash.frompairs'
import isPlainObject from 'lodash.isplainobject'
import keys from 'lodash.keys'
import last from 'lodash.last'
import map from 'lodash.map';
import mapValues from 'lodash.mapvalues';
import merge from 'lodash.merge';
import pick from 'lodash.pick'
import pickBy from 'lodash.pickby'
import union from 'lodash.union';
const METADATA_FIELD_NAMES = ['date_parution_jo', 'reference', 'notes']
export default function extractData(parameterNode) {
......@@ -18,7 +23,7 @@ export default function extractData(parameterNode) {
return dates.reduce((data, date) => {
return data.concat([merge(
{},
last(data),
pickBy(last(data), (_, fieldName) => ! includes(METADATA_FIELD_NAMES, fieldName)),
{date},
fromPairs(
map(values, (paramValues, paramKey) => {
......@@ -83,8 +88,14 @@ export function extractValues(parameterNode) {
if (parameterNode.brackets) {
return extractValuesFromScale(parameterNode)
}
return flow([
const data = flow([
x => map(x, extractValues),
x => merge({}, ...x)
])(parameterNode.subparams || parameterNode) // parameterNode.subparams for nodes coming straight for the Web API, parameterNode for custom nodes
const metadata = flow([
x => pick(x, METADATA_FIELD_NAMES),
])(parameterNode.metadata)
return merge({}, data, metadata)
}
......@@ -29,3 +29,8 @@ tr:nth-child(odd) {
thead {
border-bottom: 2px solid rgba(0,0,0,0.2);
}
.table-doc {
white-space: pre-line;
margin-top: 1em;
}
......@@ -3863,103 +3863,18 @@ locate-path@^2.0.0:
p-locate "^2.0.0"
path-exists "^3.0.0"
lodash._basebind@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._basebind/-/lodash._basebind-2.4.1.tgz#e940b9ebdd27c327e0a8dab1b55916c5341e9575"
dependencies:
lodash._basecreate "~2.4.1"
lodash._setbinddata "~2.4.1"
lodash._slice "~2.4.1"
lodash.isobject "~2.4.1"
lodash._basecreate@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-2.4.1.tgz#f8e6f5b578a9e34e541179b56b8eeebf4a287e08"
dependencies:
lodash._isnative "~2.4.1"
lodash.isobject "~2.4.1"
lodash.noop "~2.4.1"
lodash._basecreatecallback@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._basecreatecallback/-/lodash._basecreatecallback-2.4.1.tgz#7d0b267649cb29e7a139d0103b7c11fae84e4851"
dependencies:
lodash._setbinddata "~2.4.1"
lodash.bind "~2.4.1"
lodash.identity "~2.4.1"
lodash.support "~2.4.1"
lodash._basecreatewrapper@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._basecreatewrapper/-/lodash._basecreatewrapper-2.4.1.tgz#4d31f2e7de7e134fbf2803762b8150b32519666f"
dependencies:
lodash._basecreate "~2.4.1"
lodash._setbinddata "~2.4.1"
lodash._slice "~2.4.1"
lodash.isobject "~2.4.1"
lodash._baseindexof@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-2.4.1.tgz#59db58412b40604ca4531abaf7a43cf1cc36bd59"
lodash._createwrapper@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._createwrapper/-/lodash._createwrapper-2.4.1.tgz#51d6957973da4ed556e37290d8c1a18c53de1607"
dependencies:
lodash._basebind "~2.4.1"
lodash._basecreatewrapper "~2.4.1"
lodash._slice "~2.4.1"
lodash.isfunction "~2.4.1"
lodash._isnative@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._isnative/-/lodash._isnative-2.4.1.tgz#3ea6404b784a7be836c7b57580e1cdf79b14832c"
lodash._objecttypes@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._objecttypes/-/lodash._objecttypes-2.4.1.tgz#7c0b7f69d98a1f76529f890b0cdb1b4dfec11c11"
lodash._setbinddata@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._setbinddata/-/lodash._setbinddata-2.4.1.tgz#f7c200cd1b92ef236b399eecf73c648d17aa94d2"
dependencies:
lodash._isnative "~2.4.1"
lodash.noop "~2.4.1"
lodash._shimkeys@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._shimkeys/-/lodash._shimkeys-2.4.1.tgz#6e9cc9666ff081f0b5a6c978b83e242e6949d203"
dependencies:
lodash._objecttypes "~2.4.1"
lodash._slice@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash._slice/-/lodash._slice-2.4.1.tgz#745cf41a53597b18f688898544405efa2b06d90f"
lodash.bind@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.bind/-/lodash.bind-2.4.1.tgz#5d19fa005c8c4d236faf4742c7b7a1fcabe29267"
dependencies:
lodash._createwrapper "~2.4.1"
lodash._slice "~2.4.1"
lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
lodash.contains@^2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/lodash.contains/-/lodash.contains-2.4.3.tgz#3017007f88458254c818f9aa2906420490d9682c"
dependencies:
lodash._baseindexof "~2.4.1"
lodash.forown "~2.4.1"
lodash.isarray "~2.4.1"
lodash.isstring "~2.4.1"
lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
lodash.filter@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.filter/-/lodash.filter-4.6.0.tgz#668b1d4981603ae1cc5a6fa760143e480b4c4ace"
lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
......@@ -3972,42 +3887,18 @@ lodash.flow@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/lodash.flow/-/lodash.flow-3.5.0.tgz#87bf40292b8cf83e4e8ce1a3ae4209e20071675a"
lodash.forown@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.forown/-/lodash.forown-2.4.1.tgz#78b41eafe1405fa966459ea4193fd502d084524b"
dependencies:
lodash._basecreatecallback "~2.4.1"
lodash._objecttypes "~2.4.1"
lodash.keys "~2.4.1"
lodash.frompairs@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz#bc4e5207fa2757c136e573614e9664506b2b1bd2"
lodash.identity@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.identity/-/lodash.identity-2.4.1.tgz#6694cffa65fef931f7c31ce86c74597cf560f4f1"
lodash.includes@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f"
lodash.isarray@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-4.0.0.tgz#2aca496b28c4ca6d726715313590c02e6ea34403"
lodash.isarray@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-2.4.1.tgz#b52a326c1f62f6d7da73a31d5401df6ef44f0fa1"
dependencies:
lodash._isnative "~2.4.1"
lodash.isfunction@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-2.4.1.tgz#2cfd575c73e498ab57e319b77fa02adef13a94d1"
lodash.isobject@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-2.4.1.tgz#5a2e47fe69953f1ee631a7eba1fe64d2d06558f5"
dependencies:
lodash._objecttypes "~2.4.1"
lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
......@@ -4016,10 +3907,6 @@ lodash.isstring@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
lodash.isstring@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-2.4.1.tgz#3a4a42ee344b5bc09aeaa87ef1dc3097789d0792"
lodash.keyby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.keyby/-/lodash.keyby-4.6.0.tgz#7f6a1abda93fd24e22728a4d361ed8bcba5a4354"
......@@ -4028,14 +3915,6 @@ lodash.keys@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205"
lodash.keys@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-2.4.1.tgz#48dea46df8ff7632b10d706b8acb26591e2b3727"
dependencies:
lodash._isnative "~2.4.1"
lodash._shimkeys "~2.4.1"
lodash.isobject "~2.4.1"
lodash.last@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash.last/-/lodash.last-3.0.0.tgz#242f663112dd4c6e63728c60a3c909d1bdadbd4c"
......@@ -4060,9 +3939,13 @@ lodash.merge@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
lodash.noop@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.noop/-/lodash.noop-2.4.1.tgz#4fb54f816652e5ae10e8f72f717a388c7326538a"
lodash.pick@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
lodash.pickby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"
lodash.range@^3.2.0:
version "3.2.0"
......@@ -4080,12 +3963,6 @@ lodash.sum@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/lodash.sum/-/lodash.sum-4.0.2.tgz#ad90e397965d803d4f1ff7aa5b2d0197f3b4637b"
lodash.support@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/lodash.support/-/lodash.support-2.4.1.tgz#320e0b67031673c28d7a2bb5d9e0331a45240515"
dependencies:
lodash._isnative "~2.4.1"
lodash.union@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88"
......
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