From d959fa099b3aa606da687dc4927411e1f1d0ad3d Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Thu, 26 Apr 2018 12:28:48 +0200 Subject: [PATCH] =?UTF-8?q?:gear:=20Calcule=20les=20mv=20pour=20les=204=20?= =?UTF-8?q?objectifs=20pour=20coh=C3=A9rence=20lors=20du=20changement=20d'?= =?UTF-8?q?objectif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/components/ProgressCircle/selector.js | 12 +++++++--- source/reducers/reduceSteps.js | 25 ++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/source/components/ProgressCircle/selector.js b/source/components/ProgressCircle/selector.js index 20e642963..ec432ff18 100644 --- a/source/components/ProgressCircle/selector.js +++ b/source/components/ProgressCircle/selector.js @@ -1,8 +1,14 @@ import { isEmpty, values } from 'ramda' -let computeRatio = (mvt, name) => - !isEmpty(mvt) && - values(mvt.current[name]).length / values(mvt.initial[name]).length +let computeRatio = (mvt, name) => { + let initialNextSteps = values(mvt.initial[name] || []).length, + currentNextSteps = values(mvt.current[name] || []).length + + return !isEmpty(mvt) && + initialNextSteps > 0 + ? currentNextSteps / initialNextSteps + : 1 +} export let targetCompletionRatioSelector = (state, props) => { return props.isActiveInput diff --git a/source/reducers/reduceSteps.js b/source/reducers/reduceSteps.js index 52387a8a8..c8c38f320 100644 --- a/source/reducers/reduceSteps.js +++ b/source/reducers/reduceSteps.js @@ -8,6 +8,7 @@ import { import { analyseMany, parseAll } from 'Engine/traverse' export default (tracker, flatRules, answerSource) => (state, action) => { + console.log(action) state.flatRules = flatRules // Optimization - don't parse on each analysis if (!state.parsedRules) { @@ -36,21 +37,14 @@ export default (tracker, flatRules, answerSource) => (state, action) => { ) return state - if ( - path(['form', 'conversation', 'syncErrors'], state) || - (state.activeTargetInput && !answerSource(state)(state.activeTargetInput)) - ) + if (path(['form', 'conversation', 'syncErrors'], state)) return state - let targetNames = reject( - name => state.activeTargetInput && state.activeTargetInput.includes(name) - )(state.targetNames) - // Most rules have default values let rulesDefaults = collectDefaults(flatRules), situationWithDefaults = assume(answerSource, rulesDefaults) - let analysis = analyseMany(state.parsedRules, targetNames)( + let analysis = analyseMany(state.parsedRules, state.targetNames)( situationWithDefaults(state) ) @@ -58,7 +52,7 @@ export default (tracker, flatRules, answerSource) => (state, action) => { return { ...state, analysis, situationGate: situationWithDefaults(state) } } - let nextStepsAnalysis = analyseMany(state.parsedRules, targetNames)( + let nextStepsAnalysis = analyseMany(state.parsedRules, state.targetNames)( answerSource(state) ), missingVariablesByTarget = collectMissingVariablesByTarget( @@ -80,14 +74,19 @@ export default (tracker, flatRules, answerSource) => (state, action) => { : state.foldedSteps } - if (['START_CONVERSATION', 'SET_ACTIVE_TARGET_INPUT'].includes(action.type)) + // Les nextSteps initiaux ne dépendent que des règles et pourraient être précalculés + // TODO: sortir ce calcul du state pour éviter cette "astuce" avec stillBlank + if (['START_CONVERSATION', 'SET_ACTIVE_TARGET_INPUT'].includes(action.type)) { + // Le premier clic pour sélectionner un input actif permet d'initialiser missingVariablesByTarget + let stillBlank = state.activeTargetInput && !answerSource(state)(state.activeTargetInput) return { - ...newState, + ...(stillBlank ? state : newState), missingVariablesByTarget: { - initial: missingVariablesByTarget, + initial: state.missingVariablesByTarget.initial ? state.missingVariablesByTarget.initial : missingVariablesByTarget, current: missingVariablesByTarget } } + } if (action.type == 'STEP_ACTION' && action.name == 'fold') { tracker.push([