2018-06-12 10:21:36 +00:00
|
|
|
import classNames from 'classnames'
|
2018-05-25 09:47:43 +00:00
|
|
|
import InputSuggestions from 'Components/conversation/InputSuggestions'
|
2019-01-11 10:24:29 +00:00
|
|
|
import PeriodSwitch from 'Components/PeriodSwitch'
|
2018-07-31 17:26:04 +00:00
|
|
|
import withColours from 'Components/utils/withColours'
|
2018-07-12 08:09:41 +00:00
|
|
|
import withLanguage from 'Components/utils/withLanguage'
|
2019-01-11 10:46:02 +00:00
|
|
|
import withSitePaths from 'Components/utils/withSitePaths'
|
2018-07-23 16:07:07 +00:00
|
|
|
import { encodeRuleName, findRuleByDottedName } from 'Engine/rules'
|
2018-11-14 15:51:37 +00:00
|
|
|
import { compose, propEq } from 'ramda'
|
2017-11-15 09:49:55 +00:00
|
|
|
import React, { Component } from 'react'
|
2019-01-15 16:06:18 +00:00
|
|
|
import { translate } from 'react-i18next'
|
2018-02-28 16:45:13 +00:00
|
|
|
import { connect } from 'react-redux'
|
2018-07-25 14:07:53 +00:00
|
|
|
import { withRouter } from 'react-router'
|
2018-05-25 09:47:43 +00:00
|
|
|
import { Link } from 'react-router-dom'
|
2018-06-12 10:21:36 +00:00
|
|
|
import { change, Field, formValueSelector, reduxForm } from 'redux-form'
|
2018-06-18 12:53:07 +00:00
|
|
|
import {
|
|
|
|
analysisWithDefaultsSelector,
|
2018-07-03 16:28:45 +00:00
|
|
|
blockingInputControlsSelector,
|
2018-09-04 14:23:05 +00:00
|
|
|
flatRulesSelector,
|
2019-01-10 16:49:35 +00:00
|
|
|
noUserInputSelector
|
2018-06-18 12:53:07 +00:00
|
|
|
} from 'Selectors/analyseSelectors'
|
2019-01-14 17:53:18 +00:00
|
|
|
import AnimatedTargetValue from 'Ui/AnimatedTargetValue'
|
2018-05-25 09:47:43 +00:00
|
|
|
import CurrencyInput from './CurrencyInput/CurrencyInput'
|
2018-07-12 08:09:41 +00:00
|
|
|
import ProgressCircle from './ProgressCircle'
|
2018-06-12 10:21:36 +00:00
|
|
|
import './TargetSelection.css'
|
2019-01-17 14:34:44 +00:00
|
|
|
import QuickLinks from './QuickLinks'
|
2018-06-06 08:22:46 +00:00
|
|
|
|
2018-11-15 15:21:53 +00:00
|
|
|
export default compose(
|
2018-11-14 15:51:37 +00:00
|
|
|
translate(),
|
2019-01-10 16:49:35 +00:00
|
|
|
withColours,
|
2018-11-14 15:51:37 +00:00
|
|
|
reduxForm({
|
|
|
|
form: 'conversation',
|
|
|
|
destroyOnUnmount: false
|
2018-02-28 16:45:13 +00:00
|
|
|
}),
|
2018-11-14 15:51:37 +00:00
|
|
|
withRouter,
|
|
|
|
connect(
|
|
|
|
state => ({
|
|
|
|
getTargetValue: dottedName =>
|
|
|
|
formValueSelector('conversation')(state, dottedName),
|
|
|
|
analysis: analysisWithDefaultsSelector(state),
|
|
|
|
blockingInputControls: blockingInputControlsSelector(state),
|
|
|
|
flatRules: flatRulesSelector(state),
|
|
|
|
noUserInput: noUserInputSelector(state),
|
|
|
|
conversationStarted: state.conversationStarted,
|
2019-01-08 11:54:56 +00:00
|
|
|
activeInput: state.activeTargetInput,
|
2019-01-17 10:38:24 +00:00
|
|
|
objectifs: state.simulation?.config.objectifs || []
|
2018-11-14 15:51:37 +00:00
|
|
|
}),
|
|
|
|
dispatch => ({
|
|
|
|
setFormValue: (field, name) =>
|
|
|
|
dispatch(change('conversation', field, name)),
|
|
|
|
setActiveInput: name =>
|
|
|
|
dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name })
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)(
|
|
|
|
class TargetSelection extends Component {
|
|
|
|
render() {
|
2019-01-15 16:06:18 +00:00
|
|
|
let { colours } = this.props
|
2018-11-14 15:51:37 +00:00
|
|
|
return (
|
|
|
|
<div id="targetSelection">
|
2019-01-17 14:34:44 +00:00
|
|
|
<QuickLinks />
|
2019-01-11 10:24:29 +00:00
|
|
|
{/* <Controls {...{ controls }} /> */}
|
2018-11-14 15:51:37 +00:00
|
|
|
<section
|
|
|
|
id="targetsContainer"
|
|
|
|
style={{
|
|
|
|
color: colours.textColour,
|
|
|
|
background: `linear-gradient(
|
2018-07-31 17:26:04 +00:00
|
|
|
60deg,
|
|
|
|
${colours.darkColour} 0%,
|
|
|
|
${colours.colour} 100%
|
|
|
|
)`
|
2018-11-14 15:51:37 +00:00
|
|
|
}}>
|
|
|
|
{this.renderOutputList()}
|
|
|
|
</section>
|
2019-01-11 10:24:29 +00:00
|
|
|
<PeriodSwitch />
|
2018-11-14 15:51:37 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2017-11-15 09:49:55 +00:00
|
|
|
|
2018-11-14 15:51:37 +00:00
|
|
|
renderOutputList() {
|
2019-01-10 16:49:35 +00:00
|
|
|
let displayedTargets = this.props.objectifs.map(target =>
|
2018-11-14 15:51:37 +00:00
|
|
|
findRuleByDottedName(this.props.flatRules, target)
|
|
|
|
),
|
|
|
|
{
|
|
|
|
conversationStarted,
|
|
|
|
activeInput,
|
|
|
|
setActiveInput,
|
2019-01-08 20:18:04 +00:00
|
|
|
analysis,
|
2018-11-14 15:51:37 +00:00
|
|
|
noUserInput,
|
|
|
|
blockingInputControls,
|
2019-01-10 16:49:35 +00:00
|
|
|
match
|
2018-11-14 15:51:37 +00:00
|
|
|
} = this.props,
|
|
|
|
targets = analysis ? analysis.targets : []
|
2018-06-06 16:17:13 +00:00
|
|
|
|
2018-11-14 15:51:37 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ul id="targets">
|
|
|
|
{displayedTargets.map(target => (
|
|
|
|
<li key={target.name}>
|
|
|
|
<div className="main">
|
|
|
|
<Header
|
|
|
|
{...{
|
|
|
|
match,
|
|
|
|
target,
|
|
|
|
conversationStarted,
|
|
|
|
isActiveInput: activeInput === target.dottedName,
|
|
|
|
blockingInputControls
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<TargetInputOrValue
|
|
|
|
{...{
|
|
|
|
target,
|
|
|
|
targets,
|
|
|
|
activeInput,
|
|
|
|
setActiveInput,
|
|
|
|
setFormValue: this.props.setFormValue,
|
|
|
|
noUserInput,
|
|
|
|
blockingInputControls
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{activeInput === target.dottedName && !conversationStarted && (
|
2018-04-26 15:15:08 +00:00
|
|
|
<InputSuggestions
|
|
|
|
suggestions={target.suggestions}
|
|
|
|
onFirstClick={value =>
|
|
|
|
this.props.setFormValue(target.dottedName, '' + value)
|
|
|
|
}
|
2018-11-19 16:55:36 +00:00
|
|
|
rulePeriod={target.période}
|
2018-04-26 15:15:08 +00:00
|
|
|
colouredBackground={true}
|
|
|
|
/>
|
|
|
|
)}
|
2018-11-14 15:51:37 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2017-11-15 09:49:55 +00:00
|
|
|
}
|
2018-11-14 15:51:37 +00:00
|
|
|
)
|
2018-04-06 10:39:45 +00:00
|
|
|
|
2019-01-11 10:46:02 +00:00
|
|
|
let Header = withSitePaths(
|
|
|
|
({
|
|
|
|
target,
|
|
|
|
conversationStarted,
|
|
|
|
isActiveInput,
|
|
|
|
blockingInputControls,
|
|
|
|
sitePaths
|
|
|
|
}) => {
|
|
|
|
const ruleLink =
|
|
|
|
sitePaths.documentation.index + '/' + encodeRuleName(target.dottedName)
|
|
|
|
return (
|
|
|
|
<span className="header">
|
|
|
|
{conversationStarted && !blockingInputControls && (
|
|
|
|
<ProgressCircle target={target} isActiveInput={isActiveInput} />
|
|
|
|
)}
|
2018-04-09 12:19:48 +00:00
|
|
|
|
2019-01-11 10:46:02 +00:00
|
|
|
<span className="texts">
|
|
|
|
<span className="optionTitle">
|
|
|
|
<Link to={ruleLink}>{target.title || target.name}</Link>
|
|
|
|
</span>
|
|
|
|
{!conversationStarted && <p>{target['résumé']}</p>}
|
2018-04-25 13:45:29 +00:00
|
|
|
</span>
|
2018-04-06 10:39:45 +00:00
|
|
|
</span>
|
2019-01-11 10:46:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2018-04-06 10:39:45 +00:00
|
|
|
|
2018-07-31 17:26:04 +00:00
|
|
|
let CurrencyField = withColours(props => {
|
2018-04-27 13:51:31 +00:00
|
|
|
return (
|
|
|
|
<CurrencyInput
|
2018-07-31 17:26:04 +00:00
|
|
|
style={{
|
|
|
|
color: props.colours.textColour,
|
|
|
|
borderColor: props.colours.textColour
|
|
|
|
}}
|
2018-04-27 13:51:31 +00:00
|
|
|
className="targetInput"
|
|
|
|
autoFocus
|
|
|
|
{...props.input}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
)
|
2018-07-31 17:26:04 +00:00
|
|
|
})
|
2018-03-22 10:04:47 +00:00
|
|
|
|
2018-04-27 13:51:31 +00:00
|
|
|
let TargetInputOrValue = withLanguage(
|
2018-06-29 16:14:00 +00:00
|
|
|
({
|
|
|
|
target,
|
|
|
|
targets,
|
|
|
|
activeInput,
|
|
|
|
setActiveInput,
|
|
|
|
language,
|
|
|
|
noUserInput,
|
|
|
|
blockingInputControls
|
|
|
|
}) => (
|
2018-04-27 13:51:31 +00:00
|
|
|
<span className="targetInputOrValue">
|
|
|
|
{activeInput === target.dottedName ? (
|
|
|
|
<Field
|
|
|
|
name={target.dottedName}
|
|
|
|
component={CurrencyField}
|
|
|
|
language={language}
|
|
|
|
/>
|
|
|
|
) : (
|
2018-06-06 16:17:13 +00:00
|
|
|
<TargetValue
|
2018-06-29 16:14:00 +00:00
|
|
|
{...{
|
|
|
|
targets,
|
|
|
|
target,
|
|
|
|
activeInput,
|
|
|
|
setActiveInput,
|
|
|
|
noUserInput,
|
|
|
|
blockingInputControls
|
|
|
|
}}
|
2018-06-06 16:17:13 +00:00
|
|
|
/>
|
2018-04-27 13:51:31 +00:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
)
|
2018-11-14 15:51:37 +00:00
|
|
|
|
|
|
|
const TargetValue = connect(
|
2019-01-10 16:49:35 +00:00
|
|
|
null,
|
2018-08-29 16:38:14 +00:00
|
|
|
dispatch => ({
|
|
|
|
setFormValue: (field, name) => dispatch(change('conversation', field, name))
|
|
|
|
})
|
2018-11-14 15:51:37 +00:00
|
|
|
)(
|
|
|
|
class TargetValue extends Component {
|
|
|
|
render() {
|
2019-01-10 16:49:35 +00:00
|
|
|
let { targets, target, noUserInput, blockingInputControls } = this.props
|
|
|
|
|
2018-11-14 15:51:37 +00:00
|
|
|
let targetWithValue =
|
|
|
|
targets && targets.find(propEq('dottedName', target.dottedName)),
|
2019-01-10 16:49:35 +00:00
|
|
|
value = targetWithValue && targetWithValue.nodeValue
|
|
|
|
|
2018-11-14 15:51:37 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames({
|
|
|
|
editable: target.question,
|
|
|
|
attractClick:
|
|
|
|
target.question && (noUserInput || blockingInputControls)
|
|
|
|
})}
|
|
|
|
tabIndex="0"
|
|
|
|
onClick={this.showField(value)}
|
|
|
|
onFocus={this.showField(value)}>
|
|
|
|
<AnimatedTargetValue value={value} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
showField(value) {
|
2019-01-10 16:49:35 +00:00
|
|
|
let { target, setFormValue, activeInput, setActiveInput } = this.props
|
2018-11-14 15:51:37 +00:00
|
|
|
return () => {
|
|
|
|
if (!target.question) return
|
|
|
|
if (value != null)
|
|
|
|
setFormValue(target.dottedName, Math.floor(value) + '')
|
2018-07-05 15:33:49 +00:00
|
|
|
|
2019-01-10 16:49:35 +00:00
|
|
|
if (activeInput) setFormValue(activeInput, '')
|
2018-11-14 15:51:37 +00:00
|
|
|
setActiveInput(target.dottedName)
|
|
|
|
}
|
2018-07-05 15:33:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-14 15:51:37 +00:00
|
|
|
)
|