MAJ lors de la simulation ssi nouvelle saisie

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.
pull/693/head
Maxime Quandalle 2019-09-24 15:08:07 +02:00
parent 76d2101d87
commit fdb8ddc203
No known key found for this signature in database
GPG Key ID: 428641C03D29CA10
3 changed files with 16 additions and 16 deletions

View File

@ -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}

View File

@ -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
})
}
}

View File

@ -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 || {}