From 7cd16368dd017c0781fe95c61788cade3b296d6a Mon Sep 17 00:00:00 2001 From: mama Date: Fri, 1 Dec 2017 16:41:16 +0100 Subject: [PATCH] Le tableau niveau 2 affiche ses colonnes dynamiquement --- source/components/ResultsGrid.js | 149 +++++++++++++++++++------------ 1 file changed, 91 insertions(+), 58 deletions(-) diff --git a/source/components/ResultsGrid.js b/source/components/ResultsGrid.js index a4f578251..df370c386 100644 --- a/source/components/ResultsGrid.js +++ b/source/components/ResultsGrid.js @@ -2,12 +2,13 @@ import R from 'ramda' import React, { Component } from 'react' import { connect } from 'react-redux' import { withRouter } from 'react-router' - +import { formValueSelector } from 'redux-form' import './Results.css' import '../engine/mecanismViews/Somme.css' import { humanFigure } from './rule/RuleValueVignette' import { capitalise0 } from '../utils' +import { nameLeaf } from 'Engine/rules' // Filtered variables and rules can't be filtered in a uniform way, for now let paidBy = which => R.pathEq(['explanation', 'cotisation', 'dû par'], which) @@ -56,11 +57,12 @@ export let byBranch = analysis => { @connect(state => ({ analysis: state.analysis, targetNames: state.targetNames, - situationGate: state.situationGate + situationGate: state.situationGate, + inversions: formValueSelector('conversation')(state, 'inversions') })) export default class ResultsGrid extends Component { render() { - let { analysis, situationGate } = this.props + let { analysis, situationGate, targetNames, inversions } = this.props if (!analysis) return null @@ -75,13 +77,27 @@ export default class ResultsGrid extends Component { net = get('contrat salarié . salaire net'), total = get('contrat salarié . salaire total') + let inversion = R.path( + ['contrat salarié ', ' salaire de base'], + inversions + ), + relevantSalaries = new Set( + targetNames + .concat(inversion ? [nameLeaf(inversion)] : []) + .concat(['salaire de base']) + ) + return (
@@ -90,20 +106,34 @@ export default class ResultsGrid extends Component { {R.keys(results).map(branch => { let props = { branch, values: results[branch], analysis } - return + return ( + + ) })} - - - - + , + + ]} + {relevantSalaries.has('salaire total') && [ + , + + ]}
- + {humanFigure(2)(brut)}{' '} Salaire brut
- = - {humanFigure(2)(net)}{' '} - Salaire net - = - {humanFigure(2)(total)}{' '} - Salaire total - + {relevantSalaries.has('salaire net') && [ + + = + + {humanFigure(2)(net)}{' '} + Salaire net + + = + + {humanFigure(2)(total)}{' '} + Salaire total +
@@ -117,7 +147,7 @@ class Row extends Component { folded: true } render() { - let { branch, values, analysis } = this.props, + let { branch, values, analysis, relevantSalaries } = this.props, detail = byName(values) let title = name => { @@ -125,55 +155,58 @@ class Row extends Component { return node.title || capitalise0(node.name) } - let aggregateRow = () => { - return this.state.folded ? ( - this.setState({ folded: !this.state.folded })}> - - {capitalise0(branch)}  - déplier > - - + let aggregateRow = ( + this.setState({ folded: !this.state.folded })} + > + + {capitalise0(branch)}  + {this.state.folded ? 'déplier >' : 'replier'} + + + {this.state.folded ? ( + [ + relevantSalaries.has('salaire net') && [ + + - + , + + {humanFigure(2)(cell(branch, 'salarié', analysis))} + + ], + relevantSalaries.has('salaire total') && [ + + + + , + + {humanFigure(2)(cell(branch, 'employeur', analysis))} + + ] + ] + ) : ( + + )} + + ) + + let detailRows = this.state.folded + ? [] + : R.keys(detail).map(subCellName => ( + +  {title(subCellName)} - - {humanFigure(2)(cell(branch, 'salarié', analysis))} + {humanFigure(2)(subCell(detail, subCellName, 'salarié'))} + - {humanFigure(2)(cell(branch, 'employeur', analysis))} + {humanFigure(2)(subCell(detail, subCellName, 'employeur'))} - ) : ( - // unfolded - this.setState({ folded: !this.state.folded })}> - - {capitalise0(branch)}  - replier - - - - - ) - } - - let detailRows = () => { - return this.state.folded - ? [] - : R.keys(detail).map(subCellName => ( - -  {title(subCellName)} - - - - {humanFigure(2)(subCell(detail, subCellName, 'salarié'))} - - + - - {humanFigure(2)(subCell(detail, subCellName, 'employeur'))} - - - )) - } + )) // returns an array of - return R.concat([aggregateRow()], detailRows()) + return R.concat([aggregateRow], detailRows) } }