From fdb8ddc203a0043bff5c17bc72147a384cc208b9 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Tue, 24 Sep 2019 15:08:07 +0200 Subject: [PATCH] MAJ lors de la simulation ssi nouvelle saisie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auparavant nous mettions à jour la "situation" de la simulation, dès le changement de focus des champs "objectifs", bien que le changement de focus dans l'interface ne change rien aux calculs. Nous attendons maintenant que l'utilisateur fasse une nouvelle saisie. --- source/components/TargetSelection.js | 6 ------ source/reducers/rootReducer.js | 19 ++++++++++++++----- source/selectors/analyseSelectors.js | 7 ++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/components/TargetSelection.js b/source/components/TargetSelection.js index 5d5074a81..faca0497b 100644 --- a/source/components/TargetSelection.js +++ b/source/components/TargetSelection.js @@ -252,12 +252,6 @@ let TargetInputOrValue = ({ target, isActiveInput, isSmallTarget }) => { type: 'SET_ACTIVE_TARGET_INPUT', name: target.dottedName }) - // TODO: This shouldn't be necessary: we don't need to recalculate the situation - // when the user just focus another field. Removing this line is almost working - // however there is a weird bug in the selection of the next question. - if (value) { - dispatch(updateSituation(target.dottedName, value)) - } }} {...(isActiveInput ? { autoFocus: true } : {})} language={i18n.language} diff --git a/source/reducers/rootReducer.js b/source/reducers/rootReducer.js index de2612ee3..c6ec826f1 100644 --- a/source/reducers/rootReducer.js +++ b/source/reducers/rootReducer.js @@ -18,6 +18,7 @@ import i18n from '../i18n' import inFranceAppReducer from './inFranceAppReducer' import storageReducer from './storageReducer' import { findRuleByDottedName } from 'Engine/rules' +import { targetNamesSelector } from 'Selectors/analyseSelectors' import type { Action } from 'Types/ActionsTypes' function explainedVariable(state = null, { type, variableName = null }) { @@ -100,9 +101,16 @@ function conversationSteps( return state } -function updateSituation(situation, { fieldName, value, config }) { - const removePreviousTarget = config.objectifs.includes(fieldName) - ? omit(config.objectifs) +function updateSituation(situation, { fieldName, value, config, rules }) { + const goals = targetNamesSelector({ simulation: { config } }).filter( + dottedName => { + const target = rules.find(r => r.dottedName === dottedName) + const isSmallTarget = !target.question || !target.formule + return !isSmallTarget + } + ) + const removePreviousTarget = goals.includes(fieldName) + ? omit(goals) : identity return { ...removePreviousTarget(situation), [fieldName]: value } } @@ -154,7 +162,8 @@ function simulation(state = null, action, rules) { situation: updateSituation(state.situation, { fieldName: action.fieldName, value: action.value, - config: state.config + config: state.config, + rules }) } case 'UPDATE_PERIOD': @@ -162,7 +171,7 @@ function simulation(state = null, action, rules) { ...state, situation: updatePeriod(state.situation, { toPeriod: action.toPeriod, - rules: rules + rules }) } } diff --git a/source/selectors/analyseSelectors.js b/source/selectors/analyseSelectors.js index df197b4ee..39f97d4a8 100644 --- a/source/selectors/analyseSelectors.js +++ b/source/selectors/analyseSelectors.js @@ -116,11 +116,8 @@ export let firstStepCompletedSelector = createSelector( ) let validatedStepsSelector = createSelector( - [ - state => state.conversationSteps.foldedSteps, - state => state.activeTargetInput - ], - (foldedSteps, target) => [...foldedSteps, target] + [state => state.conversationSteps.foldedSteps, targetNamesSelector], + (foldedSteps, targetNames) => [...foldedSteps, ...targetNames] ) let branchesSelector = state => state.simulation?.config.branches let configSituationSelector = state => state.simulation?.config.situation || {}