2019-05-20 15:01:47 +00:00
|
|
|
|
import { hideControl, setCurrentQuestion } from 'Actions/actions'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import { makeJsx } from 'Engine/evaluation'
|
|
|
|
|
import { createMarkdownDiv } from 'Engine/marked'
|
|
|
|
|
import { compose } from 'ramda'
|
2018-06-29 16:14:00 +00:00
|
|
|
|
import React from 'react'
|
2018-09-11 14:14:46 +00:00
|
|
|
|
import emoji from 'react-easy-emoji'
|
2019-04-10 13:41:56 +00:00
|
|
|
|
import { withTranslation } from 'react-i18next'
|
2018-09-11 14:14:46 +00:00
|
|
|
|
import { connect } from 'react-redux'
|
2019-05-20 15:01:47 +00:00
|
|
|
|
import { analysisWithDefaultsSelector } from 'Selectors/analyseSelectors'
|
2019-04-03 09:16:09 +00:00
|
|
|
|
import animate from 'Ui/animate'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import './Controls.css'
|
2018-10-02 14:52:27 +00:00
|
|
|
|
import withColours from './utils/withColours'
|
2018-09-12 17:12:59 +00:00
|
|
|
|
|
|
|
|
|
function Controls({
|
|
|
|
|
controls,
|
2019-05-20 15:01:47 +00:00
|
|
|
|
setCurrentQuestion,
|
2018-10-02 16:14:01 +00:00
|
|
|
|
hideControl,
|
2018-10-02 14:52:27 +00:00
|
|
|
|
foldedSteps,
|
2018-11-16 14:26:17 +00:00
|
|
|
|
hiddenControls,
|
2019-04-10 13:41:56 +00:00
|
|
|
|
t,
|
2019-04-09 15:50:36 +00:00
|
|
|
|
inversionFail
|
2018-09-12 17:12:59 +00:00
|
|
|
|
}) {
|
2019-04-09 15:50:36 +00:00
|
|
|
|
let messages = [
|
|
|
|
|
...controls,
|
|
|
|
|
...(inversionFail
|
|
|
|
|
? [
|
|
|
|
|
{
|
2019-04-10 13:41:56 +00:00
|
|
|
|
message: t([
|
2019-04-10 16:18:32 +00:00
|
|
|
|
'simulateurs.inversionFail',
|
|
|
|
|
'Le montant saisi est trop faible ou aboutit à une situation impossible, essayez en un autre'
|
2019-04-10 13:41:56 +00:00
|
|
|
|
]),
|
2019-04-09 15:50:36 +00:00
|
|
|
|
level: 'avertissement'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
: [])
|
|
|
|
|
]
|
|
|
|
|
if (!messages?.length) return null
|
2019-04-10 13:41:56 +00:00
|
|
|
|
|
2018-09-11 14:14:46 +00:00
|
|
|
|
return (
|
2018-09-11 15:33:11 +00:00
|
|
|
|
<div id="controlsBlock">
|
2019-04-03 09:16:09 +00:00
|
|
|
|
<ul style={{ margin: 0, padding: 0 }}>
|
2019-04-09 15:50:36 +00:00
|
|
|
|
{messages.map(({ level, test, message, solution, evaluated }) =>
|
2018-11-15 13:38:13 +00:00
|
|
|
|
hiddenControls.includes(test) ? null : (
|
2019-04-17 09:13:35 +00:00
|
|
|
|
<animate.fromTop>
|
|
|
|
|
<li key={test}>
|
|
|
|
|
<div className="control">
|
|
|
|
|
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
|
|
|
|
|
<div className="controlText ui__ card">
|
|
|
|
|
{message ? (
|
|
|
|
|
createMarkdownDiv(message)
|
|
|
|
|
) : (
|
|
|
|
|
<span id="controlExplanation">{makeJsx(evaluated)}</span>
|
|
|
|
|
)}
|
2019-03-25 17:03:25 +00:00
|
|
|
|
|
2019-04-17 09:13:35 +00:00
|
|
|
|
{solution && !foldedSteps.includes(solution.cible) && (
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
key={solution.cible}
|
|
|
|
|
className="ui__ link-button"
|
2019-05-20 15:01:47 +00:00
|
|
|
|
onClick={() => setCurrentQuestion(solution.cible)}>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
{solution.texte}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
className="hide"
|
|
|
|
|
aria-label="close"
|
|
|
|
|
onClick={() => hideControl(test)}>
|
|
|
|
|
×
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2019-04-03 09:16:09 +00:00
|
|
|
|
</div>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
</li>
|
|
|
|
|
</animate.fromTop>
|
2018-11-15 13:38:13 +00:00
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</ul>
|
2018-09-11 14:14:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
2018-11-09 11:36:29 +00:00
|
|
|
|
export default compose(
|
|
|
|
|
connect(
|
|
|
|
|
(state, props) => ({
|
|
|
|
|
foldedSteps: state.conversationSteps.foldedSteps,
|
2019-05-20 15:01:47 +00:00
|
|
|
|
controls: analysisWithDefaultsSelector(state).controls,
|
|
|
|
|
inversionFail: analysisWithDefaultsSelector(state).cache.inversionFail,
|
2018-11-09 11:36:29 +00:00
|
|
|
|
key: props.language,
|
|
|
|
|
hiddenControls: state.hiddenControls
|
|
|
|
|
}),
|
2019-05-20 15:01:47 +00:00
|
|
|
|
{
|
|
|
|
|
setCurrentQuestion,
|
|
|
|
|
hideControl
|
|
|
|
|
}
|
2018-11-09 11:36:29 +00:00
|
|
|
|
),
|
|
|
|
|
withColours,
|
2019-04-10 13:41:56 +00:00
|
|
|
|
withTranslation()
|
2018-11-09 11:36:29 +00:00
|
|
|
|
)(Controls)
|