diff --git a/source/components/ProgressCircle/index.js b/source/components/ProgressCircle/index.js
new file mode 100644
index 000000000..4fca655d6
--- /dev/null
+++ b/source/components/ProgressCircle/index.js
@@ -0,0 +1,28 @@
+import React from 'react'
+import { Circle } from 'rc-progress'
+import { targetCompletionRatioSelector } from './selector'
+import { connect } from 'react-redux'
+
+let ProgressCircle = ({ ratio, isActiveInput }) => (
+
+ {ratio === 0 ? (
+
+ ) : (
+
+ )}
+
+)
+
+export default connect((state, props) => ({
+ ratio: targetCompletionRatioSelector(state, props)
+}))(ProgressCircle)
diff --git a/source/components/ProgressCircle/selector.js b/source/components/ProgressCircle/selector.js
new file mode 100644
index 000000000..20e642963
--- /dev/null
+++ b/source/components/ProgressCircle/selector.js
@@ -0,0 +1,11 @@
+import { isEmpty, values } from 'ramda'
+
+let computeRatio = (mvt, name) =>
+ !isEmpty(mvt) &&
+ values(mvt.current[name]).length / values(mvt.initial[name]).length
+
+export let targetCompletionRatioSelector = (state, props) => {
+ return props.isActiveInput
+ ? null
+ : computeRatio(state.missingVariablesByTarget, props.target.dottedName)
+}
diff --git a/source/components/TargetSelection.js b/source/components/TargetSelection.js
index 266e763d7..d9240c8a0 100644
--- a/source/components/TargetSelection.js
+++ b/source/components/TargetSelection.js
@@ -1,8 +1,8 @@
import React, { Component } from 'react'
import { Trans, translate } from 'react-i18next'
import formValueTypes from 'Components/conversation/formValueTypes'
-import { rules, findRuleByName } from 'Engine/rules'
-import { propEq, isEmpty, curry, values } from 'ramda'
+import { findRuleByName } from 'Engine/rules'
+import { propEq, curry } from 'ramda'
import './TargetSelection.css'
import BlueButton from './BlueButton'
import { Field, reduxForm, formValueSelector, change } from 'redux-form'
@@ -10,10 +10,10 @@ import { Link } from 'react-router-dom'
import { connect } from 'react-redux'
import { RuleValue } from './rule/RuleValueVignette'
import classNames from 'classnames'
+import ProgressCircle from './ProgressCircle/index'
import { buildValidationFunction } from './conversation/FormDecorator'
export let salaries = ['salaire total', 'salaire de base', 'salaire net']
export let popularTargetNames = [...salaries, 'aides employeur']
-import { Circle } from 'rc-progress'
@translate()
@reduxForm({
@@ -27,7 +27,6 @@ import { Circle } from 'rc-progress'
targets: state.analysis ? state.analysis.targets : [],
flatRules: state.flatRules,
conversationStarted: state.conversationStarted,
- missingVariablesByTarget: state.missingVariablesByTarget,
activeInput: state.activeTargetInput
}),
dispatch => ({
@@ -82,30 +81,24 @@ export default class TargetSelection extends Component {
let popularTargets = popularTargetNames.map(
curry(findRuleByName)(this.props.flatRules)
),
- {
- missingVariablesByTarget,
- conversationStarted,
- activeInput,
- setActiveInput
- } = this.props
+ { conversationStarted, activeInput, setActiveInput, targets } = this.props
return (
- {popularTargets.map(s => (
- -
+ {popularTargets.map(target => (
+
-
- !isEmpty(mvt) &&
- values(mvt.current[name]).length / values(mvt.initial[name]).length
-
-let ProgressCircle = ({ activeInput, s, missingVariablesByTarget }) => {
- let isActiveInput = activeInput === s.dottedName,
- ratio = isActiveInput
- ? null
- : computeRatio(missingVariablesByTarget, s.dottedName)
-
+let Header = ({ target, conversationStarted, isActiveInput }) => {
return (
-
- {ratio === 0 ? (
-
- ) : (
-
+
+ {conversationStarted && (
+
)}
+
+
+
+
+ {target.title || target.name}
+
+
+ {!conversationStarted &&
{target['résumé']}
}
+
)
}
-let Header = ({
- conversationStarted,
- s,
- missingVariablesByTarget,
- activeInput
-}) => (
-
- {conversationStarted && (
-
- )}
-
-
-
- {s.title || s.name}
-
- {!conversationStarted && {s['résumé']}
}
-
-
-)
-
let validate = buildValidationFunction(formValueTypes['euros'])
let InputComponent = ({ input, meta: { dirty, error } }) => (
@@ -179,24 +140,26 @@ let InputComponent = ({ input, meta: { dirty, error } }) => (
)
let TargetInputOrValue = ({
- s,
+ target,
targets,
firstEstimationComplete,
activeInput,
setActiveInput
}) => (
- {activeInput === s.dottedName ? (
+ {activeInput === target.dottedName ? (
) : (
-
+
+ )}
+ {(firstEstimationComplete || target.question) && (
+ €
)}
- {(firstEstimationComplete || s.question) && €}
)
@@ -208,25 +171,31 @@ let TargetInputOrValue = ({
)
class TargetValue extends Component {
render() {
- let { targets, s, setFormValue, activeInput, setActiveInput } = this.props,
- rule = targets.find(propEq('dottedName', s.dottedName)),
- value = rule && rule.nodeValue,
+ let {
+ targets,
+ target,
+ setFormValue,
+ activeInput,
+ setActiveInput
+ } = this.props,
+ targetWithValue = targets.find(propEq('dottedName', target.dottedName)),
+ value = targetWithValue && targetWithValue.nodeValue,
humanValue = value != null && value.toFixed(0)
return (
{
- if (!s.question) return
+ if (!target.question) return
if (value != null) {
- setFormValue(s.dottedName, humanValue + '')
+ setFormValue(target.dottedName, humanValue + '')
setFormValue(activeInput, '')
}
- setActiveInput(s.dottedName)
+ setActiveInput(target.dottedName)
}}>