From f53d1d9062b605c0208d246d11a22e4e5124b14b Mon Sep 17 00:00:00 2001 From: mama Date: Tue, 5 Dec 2017 17:48:12 +0100 Subject: [PATCH] :bug: Affichage des bonnes colonnes dans la grille MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le bouton déplier réaffichait la mauvaise colonne --- source/components/ResultsGrid.js | 372 ++++++++++++++++--------------- 1 file changed, 191 insertions(+), 181 deletions(-) diff --git a/source/components/ResultsGrid.js b/source/components/ResultsGrid.js index d84c6783a..4607bda6e 100644 --- a/source/components/ResultsGrid.js +++ b/source/components/ResultsGrid.js @@ -1,216 +1,226 @@ -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 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' -import './ResultsGrid.css' +import { capitalise0 } from "../utils" +import { nameLeaf } from "Engine/rules" +import "./ResultsGrid.css" // Filtered variables and rules can't be filtered in a uniform way, for now -let paidBy = R.pathEq(['explanation', 'cotisation', 'dû par']) +let paidBy = R.pathEq(["explanation", "cotisation", "dû par"]) -let filteredBy = R.pathEq(['cotisation', 'dû par']) +let filteredBy = R.pathEq(["cotisation", "dû par"]) -export let byName = R.groupBy(R.prop('dottedName')) +export let byName = R.groupBy(R.prop("dottedName")) export let cell = (branch, payer, analysis) => { - let row = byBranch(analysis)[branch], - items = R.filter( - item => paidBy(payer)(item) || filteredBy(payer)(item), - row - ), - values = R.map(R.prop('nodeValue'), items) + let row = byBranch(analysis)[branch], + items = R.filter( + item => paidBy(payer)(item) || filteredBy(payer)(item), + row + ), + values = R.map(R.prop("nodeValue"), items) - return R.sum(values) + return R.sum(values) } export let subCell = (row, name, payer) => { - let cells = row[name], - items = R.filter( - item => paidBy(payer)(item) || filteredBy(payer)(item), - cells - ), - values = R.map(R.prop('nodeValue'), items) + let cells = row[name], + items = R.filter( + item => paidBy(payer)(item) || filteredBy(payer)(item), + cells + ), + values = R.map(R.prop("nodeValue"), items) - return R.sum(values) + return R.sum(values) } export let byBranch = analysis => { - let sal = analysis.dict['contrat salarié . cotisations salariales'] - let pat = analysis.dict['contrat salarié . cotisations patronales'] + let sal = analysis.dict["contrat salarié . cotisations salariales"] + let pat = analysis.dict["contrat salarié . cotisations patronales"] - let l1 = sal ? sal.explanation.formule.explanation.explanation : [], - l2 = pat ? pat.explanation.formule.explanation.explanation : [], - explanations = R.concat(l1, l2), - byBranch = R.groupBy( - R.pathOr('autre', ['explanation', 'cotisation', 'branche']), - explanations - ) + let l1 = sal ? sal.explanation.formule.explanation.explanation : [], + l2 = pat ? pat.explanation.formule.explanation.explanation : [], + explanations = R.concat(l1, l2), + byBranch = R.groupBy( + R.pathOr("autre", ["explanation", "cotisation", "branche"]), + explanations + ) - return byBranch + return byBranch } @withRouter @connect(state => ({ - analysis: state.analysis, - targetNames: state.targetNames, - situationGate: state.situationGate, - inversions: formValueSelector('conversation')(state, 'inversions'), - done: state.done + analysis: state.analysis, + targetNames: state.targetNames, + situationGate: state.situationGate, + inversions: formValueSelector("conversation")(state, "inversions"), + done: state.done })) export default class ResultsGrid extends Component { - render() { - let { analysis, situationGate, targetNames, inversions, done } = this.props + render() { + let { analysis, situationGate, targetNames, inversions, done } = this.props - if (!done) return null + if (!done) return null - if (!analysis) return null + if (!analysis) return null - let extract = x => (x && x.nodeValue) || 0, - fromSituation = name => situationGate(name), - fromEval = name => R.find(R.propEq('dottedName', name), analysis.targets), - fromDict = name => analysis.dict[name], - get = name => - extract(fromSituation(name) || fromEval(name) || fromDict(name)) - let results = byBranch(analysis), - brut = get('contrat salarié . salaire brut'), - net = get('contrat salarié . salaire net'), - total = get('contrat salarié . salaire total') + let extract = x => (x && x.nodeValue) || 0, + fromSituation = name => situationGate(name), + fromEval = name => R.find(R.propEq("dottedName", name), analysis.targets), + fromDict = name => analysis.dict[name], + get = name => + extract(fromSituation(name) || fromEval(name) || fromDict(name)) + let results = byBranch(analysis), + brut = get("contrat salarié . salaire brut"), + 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']) - ) + let inversion = R.path( + ["contrat salarié ", " salaire de base"], + inversions + ), + relevantSalaries = new Set( + targetNames + .concat(inversion ? [nameLeaf(inversion)] : []) + .concat(["salaire de base"]) + ) - return ( -
- - - - - - - - {R.keys(results).map(branch => { - let props = { branch, values: results[branch], analysis } - return ( - - ) - })} - - - - } - {relevantSalaries.has('salaire total') && [ - , - - ]} - - -
- - {humanFigure(2)(brut)}{' '} - Salaire brut -
- {relevantSalaries.has('salaire net') && <> - - = - - {humanFigure(2)(net)}{' '} - Salaire net - - = - - {humanFigure(2)(total)}{' '} - Salaire total -
-
- ) - } + return ( +
+ + + + + + + + {R.keys(results).map(branch => { + let props = { branch, values: results[branch], analysis } + return ( + + ) + })} + + + + + )} + {relevantSalaries.has("salaire total") && [ + , + + ]} + + +
+ + {humanFigure(2)(brut)}{" "} + Salaire brut +
+ {relevantSalaries.has("salaire net") && ( + <> + + = + + {humanFigure(2)(net)}{" "} + Salaire net + + = + + {humanFigure(2)(total)}{" "} + Salaire total +
+
+ ) + } } class Row extends Component { - state = { - folded: true - } - render() { - let { branch, values, analysis, relevantSalaries } = this.props, - detail = byName(values) + state = { + folded: true + } + render() { + let { branch, values, analysis, relevantSalaries } = this.props, + detail = byName(values) - let title = name => { - let node = R.head(detail[name]) - return node.title || capitalise0(node.name) - } + let title = name => { + let node = R.head(detail[name]) + return node.title || capitalise0(node.name) + } - 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 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)(subCell(detail, subCellName, 'salarié'))} - - + - - {humanFigure(2)(subCell(detail, subCellName, 'employeur'))} - - - )) + let detailRows = this.state.folded + ? [] + : R.keys(detail).map(subCellName => ( + +  {title(subCellName)} + {relevantSalaries.has('salaire net') && <> + - + + {humanFigure(2)(subCell(detail, subCellName, "salarié"))} + + + } + {relevantSalaries.has('salaire total') && <> + + + + {humanFigure(2)(subCell(detail, subCellName, "employeur"))} + + + } + + )) - // returns an array of - return R.concat([aggregateRow], detailRows) - } + // returns an array of + return R.concat([aggregateRow], detailRows) + } }