Implémentation du message et de la barre d'avancement

pull/138/head
mama 2017-11-27 15:03:36 +01:00
parent e56e992056
commit 54291e036d
6 changed files with 81 additions and 52 deletions

View File

@ -81,6 +81,13 @@
#fin {
#sim .tip {
font-style: italic;
margin-bottom: 2em;
}
#sim .tip p {
margin: 0;
}
#sim .tip progress {
margin-left: 1em;
}

View File

@ -24,6 +24,8 @@ import Results from 'Components/Results'
themeColours: state.themeColours,
situationGate: state.situationGate,
targetNames: state.targetNames,
done: state.done,
nextSteps: state.nextSteps,
inputInversions: formValueSelector('conversation')(state, 'inversions')
}),
dispatch => ({
@ -107,6 +109,8 @@ export default class extends Component {
),
foldedSteps
),
done: this.props.done,
nextSteps: this.props.nextSteps,
textColourOnWhite: themeColours.textColourOnWhite
}}
/>

View File

@ -2,7 +2,7 @@ import React, { Component } from 'react'
import R from 'ramda'
import Aide from '../Aide'
import Satisfaction from '../Satisfaction'
import {reduxForm} from 'redux-form'
import { reduxForm } from 'redux-form'
import Scroll from 'react-scroll'
@reduxForm({
@ -11,36 +11,57 @@ import Scroll from 'react-scroll'
})
export default class Conversation extends Component {
render() {
let {foldedSteps, currentQuestion, reinitalise, textColourOnWhite} = this.props
let {
foldedSteps,
currentQuestion,
reinitalise,
textColourOnWhite,
done,
nextSteps
} = this.props
Scroll.animateScroll.scrollToBottom()
return (
<div id="conversation">
<div id="questions-answers">
{ !R.isEmpty(foldedSteps) &&
{!R.isEmpty(foldedSteps) && (
<div id="foldedSteps">
<div className="header" >
<h2><i className="fa fa-mouse-pointer" aria-hidden="true"></i>Vos réponses</h2>
<button onClick={reinitalise} style={{color: textColourOnWhite}}>
<i className="fa fa-trash" aria-hidden="true"></i>
<div className="header">
<h2>
<i className="fa fa-mouse-pointer" aria-hidden="true" />Vos
réponses
</h2>
<button
onClick={reinitalise}
style={{ color: textColourOnWhite }}
>
<i className="fa fa-trash" aria-hidden="true" />
Tout effacer
</button>
</div>
{foldedSteps}
</div>
}
{!currentQuestion &&
<Conclusion affiner={!R.isEmpty({})}/>}
{ !R.isEmpty({}) &&
<div id="foldedSteps">
<div className="header" >
<h3>Affiner votre situation</h3>
</div>
{}
)}
{done && (
<div className="tip">
{nextSteps.length != 0 && (
<p>Votre première estimation est disponible !</p>
)}
{nextSteps.length != 0 && (
<p>
Il vous reste environ {nextSteps.length}{' '}
{nextSteps.length === 1 ? 'questions' : 'question'} pour
affiner le calcul
<progress
value={foldedSteps.length}
max={foldedSteps.length + nextSteps.length}
/>
</p>
)}
</div>
}
)}
<div id="currentQuestion">
{ currentQuestion || <Satisfaction simu={this.props.simu}/>}
{currentQuestion || <Satisfaction simu={this.props.simu} />}
</div>
</div>
<Aide />
@ -48,12 +69,3 @@ export default class Conversation extends Component {
)
}
}
let Conclusion = ({ affiner }) => (
<div id="fin">
<p>
Vous pouvez maintenant modifier vos réponses{" "}
{affiner && "ou affiner votre situation"} : vos résultats ci-dessous seront mis à jour.
</p>
</div>
)

View File

@ -40,7 +40,7 @@ export let collectMissingVariables = targets =>
// R.reduce( (memo, [mv, dependencyOf]) => ({...memo, [mv]: [...(memo[mv] || []), dependencyOf] }), {})
)(targets)
export let nextSteps = (situationGate, flatRules, analysis) => {
export let getNextSteps = (situationGate, flatRules, analysis) => {
let impact = ([variable, objectives]) => R.length(objectives)
let missingVariables = collectMissingVariables(analysis.targets),

View File

@ -1,4 +1,4 @@
import R from 'ramda'
import R, {head} from 'ramda'
import { combineReducers } from 'redux'
import reduceReducers from 'reduce-reducers'
import { reducer as formReducer, formValueSelector } from 'redux-form'
@ -10,7 +10,7 @@ import {
nameLeaf,
formatInputs
} from 'Engine/rules'
import { nextSteps } from 'Engine/generateQuestions'
import { getNextSteps } from 'Engine/generateQuestions'
import computeThemeColours from 'Components/themeColours'
import {
STEP_ACTION,
@ -30,6 +30,16 @@ let assume = (evaluator, assumptions) => state => name => {
return userInput != null ? userInput : assumptions[name]
}
let nextWithoutDefaults = (state, flatRules, analysis, targetNames, intermediateSituation) => {
let
reanalysis = analyse(analysis.parsedRules, targetNames)(
intermediateSituation(state)
),
nextSteps = getNextSteps(intermediateSituation(state), flatRules, reanalysis)
return {currentQuestion: head(nextSteps), nextSteps}
}
export let reduceSteps = (tracker, flatRules, answerSource) => (
state,
action
@ -52,22 +62,10 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
let
parsedRules = R.path(['analysis', 'parsedRules'], state),
analysis = analyse(parsedRules || flatRules, targetNames)(situationWithDefaults(state)),
next = nextSteps(situationWithDefaults(state), flatRules, analysis),
nextWithDefaults = getNextSteps(situationWithDefaults(state), flatRules, analysis),
assumptionsMade = !R.isEmpty(rulesDefaults),
done = next.length == 0,
currentQuestion =
done && assumptionsMade
? // The simulation is "over" - except we can now fill in extra questions
// where the answers were previously given default reasonable assumptions
do {
let
reanalysis = analyse(analysis.parsedRules, targetNames)(
intermediateSituation(state)
),
next = nextSteps(intermediateSituation(state), flatRules, reanalysis)
R.head(next)
}
: R.head(next)
done = nextWithDefaults.length == 0
let newState = {
...state,
@ -75,7 +73,13 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
analysis,
situationGate: situationWithDefaults(state),
explainedVariable: null,
currentQuestion
done,
... (done && assumptionsMade
?
// The simulation is "over" - except we can now fill in extra questions
// where the answers were previously given default reasonable assumptions
nextWithoutDefaults(state, flatRules, analysis, targetNames, intermediateSituation)
: {currentQuestion: head(nextWithDefaults), nextSteps: nextWithDefaults})
}
if (action.type == START_CONVERSATION) {
@ -142,13 +146,15 @@ export default reduceReducers(
false means the user is reconsidering its previous input */
foldedSteps: (steps = []) => steps,
currentQuestion: (state = null) => state,
nextSteps: (state = []) => state,
analysis: (state = null) => state,
targetNames: (state = null) => state,
situationGate: (state = name => null) => state,
refine: (state = false) => state,
done: (state = null) => state,
themeColours,

View File

@ -213,7 +213,7 @@ describe('nextSteps', function() {
{nom: "ko", espace: "top . sum . evt"}],
rules = rawRules.map(enrichRule),
analysis = analyse(rules,"sum")(stateSelector),
result = nextSteps(stateSelector, rules, analysis)
result = getNextSteps(stateSelector, rules, analysis)
expect(result).to.have.lengthOf(1)
expect(result[0]).to.equal("top . sum . evt")
@ -223,7 +223,7 @@ describe('nextSteps', function() {
let rules = realRules.map(enrichRule),
analysis = analyse(rules,"surcoût CDD")(stateSelector),
missing = collectMissingVariables(analysis.targets),
result = nextSteps(stateSelector, rules, analysis)
result = getNextSteps(stateSelector, rules, analysis)
// expect(objectives).to.have.lengthOf(4)
@ -254,7 +254,7 @@ describe('nextSteps', function() {
let rules = realRules.map(enrichRule),
analysis = analyse(rules,"salaire")(stateSelector),
missing = collectMissingVariables(analysis.targets),
result = nextSteps(stateSelector, rules, analysis)
result = getNextSteps(stateSelector, rules, analysis)
expect(result[0]).to.equal("contrat salarié . salaire de base")
expect(result[1]).to.equal("contrat salarié . temps partiel")
@ -266,7 +266,7 @@ describe('nextSteps', function() {
let rules = realRules.map(enrichRule),
analysis = analyse(rules,"salaire net")(stateSelector),
missing = collectMissingVariables(analysis.targets),
result = nextSteps(stateSelector, rules, analysis)
result = getNextSteps(stateSelector, rules, analysis)
expect(result).to.include("contrat salarié . CDD . motif")
});