diff --git a/source/engine/evaluation.js b/source/engine/evaluation.js index b15556d14..03d3771c5 100644 --- a/source/engine/evaluation.js +++ b/source/engine/evaluation.js @@ -79,6 +79,13 @@ export let evaluateArrayWithFilter = (evaluationFilter, reducer, start) => ( return rewriteNode(node, nodeValue, explanation, missingVariables) } +export let defaultNode = nodeValue => ({ + nodeValue, + // eslint-disable-next-line + jsx: nodeValue => {nodeValue}, + isDefault: true +}) + export let parseObject = (recurse, objectShape, value) => { let recurseOne = key => defaultValue => { if (!value[key] && !defaultValue) diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index ab844fb80..d4383c6d3 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -48,7 +48,8 @@ import { collectNodeMissing, mergeAllMissing, mergeMissing, - bonus + bonus, + defaultNode } from './evaluation' import { findRuleByName, @@ -68,12 +69,6 @@ import { trancheValue } from './mecanisms/barème' import buildSelectionView from './mecanismViews/Selection' import uniroot from './uniroot' -let constantNode = constant => ({ - nodeValue: constant, - // eslint-disable-next-line - jsx: nodeValue => {nodeValue} -}) - let decompose = (recurse, k, v) => { let subProps = dissoc('composantes')(v), explanation = v.composantes.map(c => ({ @@ -583,8 +578,8 @@ export let mecanismSum = (recurse, k, v) => { export let mecanismReduction = (recurse, k, v) => { let objectShape = { assiette: false, - abattement: constantNode(0), - franchise: constantNode(0), + abattement: defaultNode(0), + franchise: defaultNode(0) } let effect = ({ assiette, abattement, franchise, décote }) => { @@ -650,9 +645,9 @@ export let mecanismProduct = (recurse, k, v) => { let objectShape = { assiette: false, - taux: constantNode(1), - facteur: constantNode(1), - plafond: constantNode(Infinity) + taux: defaultNode(1), + facteur: defaultNode(1), + plafond: defaultNode(Infinity) } let effect = ({ assiette, taux, facteur, plafond }) => { let mult = (base, rate, facteur, plafond) => @@ -684,7 +679,7 @@ export let mecanismProduct = (recurse, k, v) => { {makeJsx(explanation.assiette)} - {explanation.taux.explanation && ( + {!explanation.taux.isDefault && (