🐛 Bug de calcul des prochaines etapes

pull/206/head
Mael 2018-04-05 17:08:04 +02:00 committed by Laurent Bossavit
parent 29c80b3c13
commit f66bf2cc3c
2 changed files with 48 additions and 34 deletions

View File

@ -26,22 +26,20 @@ import { Circle } from 'rc-progress'
targets: state.analysis ? state.analysis.targets : [],
flatRules: state.flatRules,
conversationStarted: state.conversationStarted,
missingVariablesByTarget: state.missingVariablesByTarget
missingVariablesByTarget: state.missingVariablesByTarget,
activeInput: state.activeTargetInput
}),
dispatch => ({
setFormValue: (field, name) =>
dispatch(change('conversation', field, name)),
startConversation: () => dispatch({ type: 'START_CONVERSATION' })
startConversation: () => dispatch({ type: 'START_CONVERSATION' }),
setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name })
})
)
export default class TargetSelection extends Component {
state = {
activeInput: null
}
render() {
let { targets, conversationStarted, colours } = this.props
this.firstEstimationComplete = this.state.activeInput && targets.length > 0
this.firstEstimationComplete = this.props.activeInput && targets.length > 0
return (
<div id="targetSelection">
<section
@ -86,7 +84,9 @@ export default class TargetSelection extends Component {
{
textColourOnWhite,
missingVariablesByTarget,
conversationStarted
conversationStarted,
activeInput,
setActiveInput
} = this.props
return (
@ -94,26 +94,27 @@ export default class TargetSelection extends Component {
<ul id="targets">
{popularTargets.map(s => (
<li key={s.name}>
{conversationStarted && (
<span className="progressCircle">
{do {
let mv = missingVariablesByTarget[s.dottedName],
number = mv && mv.missingVariables.length,
ratio = number / 16
ratio === 0 ? (
<i className="fa fa-check" aria-hidden="true" />
) : (
<Circle
percent={100 - ratio * 100}
strokeWidth="15"
strokeColor="#5de662"
trailColor="#bbbbbb"
trailWidth="5"
/>
)
}}
</span>
)}
{conversationStarted &&
activeInput !== s.dottedName && (
<span className="progressCircle">
{do {
let mv = missingVariablesByTarget[s.dottedName],
number = mv && mv.missingVariables.length,
ratio = number / 16
ratio === 0 ? (
<i className="fa fa-check" aria-hidden="true" />
) : (
<Circle
percent={100 - ratio * 100}
strokeWidth="15"
strokeColor="#5de662"
trailColor="#bbbbbb"
trailWidth="5"
/>
)
}}
</span>
)}
<span className="texts">
<span className="optionTitle">
<Link to={'/règle/' + s.dottedName}>{s.title || s.name}</Link>
@ -125,8 +126,8 @@ export default class TargetSelection extends Component {
s,
targets: this.props.targets,
firstEstimationComplete: this.firstEstimationComplete,
activeInput: this.state.activeInput,
setActiveInput: name => this.setState({ activeInput: name }),
activeInput,
setActiveInput,
setFormValue: this.props.setFormValue
}}
/>

View File

@ -1,4 +1,4 @@
import { head, pathOr, without, concat, path, length } from 'ramda'
import { head, pathOr, without, concat, path, length, reject } from 'ramda'
import { combineReducers } from 'redux'
import reduceReducers from 'reduce-reducers'
import { reducer as formReducer, formValueSelector } from 'redux-form'
@ -62,6 +62,10 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
if (path(['form', 'conversation', 'syncErrors'], state)) return state
let targetNames = reject(
name => state.activeTargetInput && state.activeTargetInput.includes(name)
)(state.targetNames)
let sim = {},
// Hard assumptions cannot be changed, they are used to specialise a simulator
// before the user sees the first question
@ -71,7 +75,7 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
rulesDefaults = collectDefaults(flatRules),
situationWithDefaults = assume(intermediateSituation, rulesDefaults)
let analysis = analyseMany(state.parsedRules, state.targetNames)(
let analysis = analyseMany(state.parsedRules, targetNames)(
situationWithDefaults(state)
)
@ -79,7 +83,7 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
return { ...state, analysis, situationGate: situationWithDefaults(state) }
}
let nextStepsAnalysis = analyseMany(state.parsedRules, state.targetNames)(
let nextStepsAnalysis = analyseMany(state.parsedRules, targetNames)(
intermediateSituation(state)
),
missingVariablesByTarget = collectMissingVariablesByTarget(
@ -173,6 +177,14 @@ function conversationStarted(state = false, { type }) {
return state
}
}
function activeTargetInput(state = null, { type, name }) {
switch (type) {
case 'SET_ACTIVE_TARGET_INPUT':
return name
default:
return state
}
}
export default initialRules =>
reduceReducers(
@ -203,7 +215,8 @@ export default initialRules =>
explainedVariable,
currentExample,
conversationStarted
conversationStarted,
activeTargetInput
}),
// cross-cutting concerns because here `state` is the whole state tree
reduceSteps(