From 6859ec4b148abd15a9aa13acd53bdf4a297e20bf Mon Sep 17 00:00:00 2001 From: Mael Date: Mon, 19 Nov 2018 16:55:36 +0000 Subject: [PATCH] =?UTF-8?q?On=20cache=20les=20suggestions=20quand=20la=20p?= =?UTF-8?q?=C3=A9riode=20est=20l'ann=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/Controls.js | 2 +- source/components/TargetSelection.js | 1 + source/components/conversation/Input.js | 1 + source/components/conversation/InputSuggestions.js | 13 +++++++++++-- source/engine/generateQuestions.js | 3 ++- source/engine/rules.js | 2 +- source/règles/base.yaml | 2 +- test/rules.test.js | 8 ++++---- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/source/components/Controls.js b/source/components/Controls.js index 964c206d7..b01c1da33 100644 --- a/source/components/Controls.js +++ b/source/components/Controls.js @@ -29,7 +29,7 @@ function Controls({
  • + style={{ background: colours.lighterColour }}> {emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
    {message && createMarkdownDiv(message)} diff --git a/source/components/TargetSelection.js b/source/components/TargetSelection.js index f2d21b338..c1fe8dec4 100644 --- a/source/components/TargetSelection.js +++ b/source/components/TargetSelection.js @@ -124,6 +124,7 @@ export default compose( onFirstClick={value => this.props.setFormValue(target.dottedName, '' + value) } + rulePeriod={target.période} colouredBackground={true} /> )} diff --git a/source/components/conversation/Input.js b/source/components/conversation/Input.js index 07a3220f0..e8ba7ee11 100644 --- a/source/components/conversation/Input.js +++ b/source/components/conversation/Input.js @@ -65,6 +65,7 @@ export default compose( suggestions={this.props.suggestions} onFirstClick={value => this.props.setFormValue('' + value)} onSecondClick={() => this.props.submit('suggestion')} + rulePeriod={this.props.rulePeriod} /> {inputError && {error}} diff --git a/source/components/conversation/InputSuggestions.js b/source/components/conversation/InputSuggestions.js index 774f1259d..68a2c9bee 100644 --- a/source/components/conversation/InputSuggestions.js +++ b/source/components/conversation/InputSuggestions.js @@ -3,10 +3,15 @@ import { compose, toPairs } from 'ramda' import React, { Component } from 'react' import { withI18n } from 'react-i18next' import './InputSuggestions.css' +import { connect } from 'react-redux' +import { formValueSelector } from 'redux-form' export default compose( withColours, - withI18n() + withI18n(), + connect(state => ({ + period: formValueSelector('conversation')(state, 'période') + })) )( class InputSuggestions extends Component { state = { suggestion: null } @@ -17,10 +22,14 @@ export default compose( onFirstClick, colouredBackground, colours, - t + t, + rulePeriod, + period } = this.props if (!suggestions) return null + //TODO all suggestions are defined for a monthly simulation + if (rulePeriod === 'flexible' && period !== 'mois') return null return (
    suggestions: diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index 30eceb254..095cd2114 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -151,7 +151,8 @@ export let getInputComponent = rules => dottedName => { {...{ ...commonProps, valueType: formValueTypes[rule.format], - suggestions: rule.suggestions + suggestions: rule.suggestions, + rulePeriod: rule.période }} /> ) diff --git a/source/engine/rules.js b/source/engine/rules.js index 9414ab775..9d9491119 100644 --- a/source/engine/rules.js +++ b/source/engine/rules.js @@ -106,7 +106,7 @@ export let decodeRuleName = name => name.replace(/--/g, ' . ').replace(/-/g, ' ') /* Les variables peuvent être exprimées dans la formule d'une règle relativement à son propre espace de nom, pour une plus grande lisibilité. Cette fonction résoud cette ambiguité. -*/ + */ export let disambiguateRuleReference = ( allRules, { ns, name }, diff --git a/source/règles/base.yaml b/source/règles/base.yaml index efbf30ffd..ea38451b7 100644 --- a/source/règles/base.yaml +++ b/source/règles/base.yaml @@ -2131,7 +2131,7 @@ alors: en alsace moselle - sinon: en france contrôles: - - si: forfait complémentaire santé [mois] < 15 + - si: forfait complémentaire santé [mensuel] < 15 niveau: avertissement message: Vérifiez bien qu'une complémentaire santé si peu chère couvre le panier de soin minimal défini dans la loi. diff --git a/test/rules.test.js b/test/rules.test.js index a0de950e2..8f840e088 100644 --- a/test/rules.test.js +++ b/test/rules.test.js @@ -63,16 +63,16 @@ describe('rule checks', function() { ) expect(rulesNeedingDefault).to.be.empty }) - it('rules with a period should have defaults with a period', function() { + it('rules with a period should not have a flexible period', function() { let problems = rules.filter( - ({ defaultValue, dottedName, période }) => période && defaultValue + ({ defaultValue, période }) => période === 'flexible' && defaultValue ) problems.map(({ dottedName }) => console.log( - 'La valeur par défaut de ', + 'La valeur règle ', dottedName, - ' devrait avoir une période' + " a une période flexible et une valeur par défaut. C'est un problème, car on ne sait pas pour quelle période ce défaut est défini. " ) ) expect(problems).to.be.empty