2019-06-05 14:57:08 +00:00
|
|
|
|
import { goToQuestion, hideControl } from 'Actions/actions'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import { makeJsx } from 'Engine/evaluation'
|
|
|
|
|
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-09-11 08:06:51 +00:00
|
|
|
|
import { useTranslation } 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'
|
2019-07-09 13:35:09 +00:00
|
|
|
|
import { Markdown } from './utils/markdown'
|
2018-09-12 17:12:59 +00:00
|
|
|
|
|
|
|
|
|
function Controls({
|
|
|
|
|
controls,
|
2019-06-05 14:57:08 +00:00
|
|
|
|
goToQuestion,
|
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-09 15:50:36 +00:00
|
|
|
|
inversionFail
|
2018-09-12 17:12:59 +00:00
|
|
|
|
}) {
|
2019-09-11 08:06:51 +00:00
|
|
|
|
const { t } = useTranslation()
|
2019-05-20 16:04:39 +00:00
|
|
|
|
if (!controls) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2019-04-09 15:50:36 +00:00
|
|
|
|
let messages = [
|
|
|
|
|
...controls,
|
|
|
|
|
...(inversionFail
|
|
|
|
|
? [
|
2019-12-16 14:13:22 +00:00
|
|
|
|
{
|
|
|
|
|
message: t([
|
|
|
|
|
'simulateurs.inversionFail',
|
|
|
|
|
'Le montant saisi est trop faible ou aboutit à une situation impossible, essayez en un autre'
|
|
|
|
|
]),
|
|
|
|
|
level: 'avertissement'
|
|
|
|
|
}
|
|
|
|
|
]
|
2019-04-09 15:50:36 +00:00
|
|
|
|
: [])
|
|
|
|
|
]
|
2019-12-16 14:13:22 +00:00
|
|
|
|
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-12-16 14:13:22 +00:00
|
|
|
|
<animate.fromTop key={message}>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
<li key={test}>
|
|
|
|
|
<div className="control">
|
|
|
|
|
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
|
|
|
|
|
<div className="controlText ui__ card">
|
|
|
|
|
{message ? (
|
2019-07-09 13:35:09 +00:00
|
|
|
|
<Markdown source={message} />
|
2019-04-17 09:13:35 +00:00
|
|
|
|
) : (
|
2019-12-16 14:13:22 +00:00
|
|
|
|
<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-12-16 14:13:22 +00:00
|
|
|
|
onClick={() => goToQuestion(solution.cible)}
|
|
|
|
|
>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
{solution.texte}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
className="hide"
|
|
|
|
|
aria-label="close"
|
2019-12-16 14:13:22 +00:00
|
|
|
|
onClick={() => hideControl(test)}
|
|
|
|
|
>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
×
|
|
|
|
|
</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) => ({
|
2020-01-07 13:41:37 +00:00
|
|
|
|
foldedSteps: state.simulation?.foldedSteps,
|
2019-12-16 14:13:22 +00:00
|
|
|
|
controls: analysisWithDefaultsSelector(state)?.controls,
|
|
|
|
|
inversionFail: analysisWithDefaultsSelector(state)?.cache._meta
|
|
|
|
|
.inversionFail,
|
2018-11-09 11:36:29 +00:00
|
|
|
|
key: props.language,
|
2019-07-02 15:07:19 +00:00
|
|
|
|
hiddenControls: state.simulation.hiddenControls
|
2018-11-09 11:36:29 +00:00
|
|
|
|
}),
|
2019-05-20 15:01:47 +00:00
|
|
|
|
{
|
2019-06-05 14:57:08 +00:00
|
|
|
|
goToQuestion,
|
2019-05-20 15:01:47 +00:00
|
|
|
|
hideControl
|
|
|
|
|
}
|
2019-09-11 16:17:07 +00:00
|
|
|
|
)
|
2018-11-09 11:36:29 +00:00
|
|
|
|
)(Controls)
|