From 06b98b6a8d993656d4d531517bccaeb6766150d9 Mon Sep 17 00:00:00 2001 From: Mael Date: Fri, 27 Jul 2018 18:50:11 +0200 Subject: [PATCH] =?UTF-8?q?:doc:=20Am=C3=A9lioration=20de=20la=20vue=20bar?= =?UTF-8?q?=C3=A8me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/mecanismViews/Barème.js | 18 +++++----- source/engine/treat.js | 47 +++++++++++---------------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/source/engine/mecanismViews/Barème.js b/source/engine/mecanismViews/Barème.js index 25a451d4b..35550c1fe 100644 --- a/source/engine/mecanismViews/Barème.js +++ b/source/engine/mecanismViews/Barème.js @@ -17,14 +17,16 @@ export default function Barème(nodeValue, explanation) { {makeJsx(explanation.assiette)} -
  • - - multiplicateur des tranches:{' '} - - - {makeJsx(explanation['multiplicateur des tranches'])} - -
  • + {explanation['multiplicateur des tranches'].nodeValue !== 1 && ( +
  • + + multiplicateur des tranches:{' '} + + + {makeJsx(explanation['multiplicateur des tranches'])} + +
  • + )} diff --git a/source/engine/treat.js b/source/engine/treat.js index 93c6f9b6b..709acf58d 100644 --- a/source/engine/treat.js +++ b/source/engine/treat.js @@ -90,14 +90,7 @@ export let treatString = (rules, rule) => rawNode => { // We don't need to handle category == 'value' because YAML then returns it as // numerical value, not a String: it goes to treatNumber - if (parseResult.category == 'percentage') { - return { - nodeValue: parseResult.nodeValue, - category: 'percentage', - // eslint-disable-next-line - jsx: () => {rawNode} - } - } + if (parseResult.category == 'percentage') return treatPercentage(parseResult) if ( parseResult.category == 'calcExpression' || @@ -154,17 +147,7 @@ export let treatString = (rules, rule) => rawNode => { jsx: nodeValue => {nodeValue} }) ], - [ - propEq('category', 'percentage'), - node => ({ - nodeValue: node.nodeValue, - category: 'percentage', - // eslint-disable-next-line - jsx: nodeValue => ( - {nodeValue * 100}% - ) - }) - ] + [propEq('category', 'percentage'), treatPercentage] ]) ), operator = parseResult.operator @@ -206,15 +189,23 @@ export let treatString = (rules, rule) => rawNode => { } } -export let treatNumber = rawNode => { - return { - text: '' + rawNode, - category: 'number', - nodeValue: rawNode, - type: 'numeric', - jsx: {rawNode} - } -} +export let treatPercentage = node => ({ + nodeValue: node.nodeValue, + category: 'percentage', + // eslint-disable-next-line + jsx: nodeValue => ( + {Math.round(nodeValue * 100)} % + ) +}) + +export let treatNumber = rawNode => ({ + text: '' + rawNode, + category: 'number', + nodeValue: rawNode, + type: 'numeric', + jsx: {rawNode} +}) + export let treatOther = rawNode => { throw new Error( 'Cette donnée : ' + rawNode + ' doit être un Number, String ou Object'