2018-11-09 11:36:29 +00:00
|
|
|
|
import { hideControl, startConversation } from 'Actions/actions'
|
|
|
|
|
import withLanguage from 'Components/utils/withLanguage'
|
|
|
|
|
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'
|
|
|
|
|
import { connect } from 'react-redux'
|
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,
|
|
|
|
|
startConversation,
|
2018-10-02 16:14:01 +00:00
|
|
|
|
hideControl,
|
2018-10-02 14:52:27 +00:00
|
|
|
|
foldedSteps,
|
2018-10-02 16:14:01 +00:00
|
|
|
|
colours,
|
2018-11-16 14:26:17 +00:00
|
|
|
|
hiddenControls,
|
|
|
|
|
language
|
2018-09-12 17:12:59 +00:00
|
|
|
|
}) {
|
2018-11-15 13:38:13 +00:00
|
|
|
|
if (!controls?.length) return null
|
2018-11-16 14:26:17 +00:00
|
|
|
|
/* TODO controls are not translated yet, since our translation system doesn't handle nested yaml properties of base.yaml */
|
|
|
|
|
if (language === 'en') return null
|
2018-09-11 14:14:46 +00:00
|
|
|
|
return (
|
2018-09-11 15:33:11 +00:00
|
|
|
|
<div id="controlsBlock">
|
2018-11-15 13:38:13 +00:00
|
|
|
|
<ul>
|
|
|
|
|
{controls.map(({ level, test, message, solution, evaluated }) =>
|
|
|
|
|
hiddenControls.includes(test) ? null : (
|
|
|
|
|
<li
|
|
|
|
|
key={test}
|
|
|
|
|
className="control"
|
2018-11-19 16:55:36 +00:00
|
|
|
|
style={{ background: colours.lighterColour }}>
|
2018-11-15 13:38:13 +00:00
|
|
|
|
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
|
|
|
|
|
<div className="controlText">
|
|
|
|
|
{message && createMarkdownDiv(message)}
|
|
|
|
|
{!message && (
|
|
|
|
|
<span id="controlExplanation">{makeJsx(evaluated)}</span>
|
|
|
|
|
)}
|
|
|
|
|
{solution && !foldedSteps.includes(solution.cible) && (
|
|
|
|
|
<div id="solution">
|
|
|
|
|
{/*emoji('💡')*/}
|
2018-10-02 16:28:56 +00:00
|
|
|
|
<button
|
2018-11-15 13:38:13 +00:00
|
|
|
|
key={solution.cible}
|
|
|
|
|
className="ui__ link-button"
|
|
|
|
|
onClick={() => startConversation(solution.cible)}>
|
|
|
|
|
{solution.texte}
|
2018-10-02 16:28:56 +00:00
|
|
|
|
</button>
|
2018-11-15 13:38:13 +00:00
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
className="hide"
|
|
|
|
|
aria-label="close"
|
|
|
|
|
onClick={() => hideControl(test)}>
|
|
|
|
|
×
|
|
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</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,
|
|
|
|
|
key: props.language,
|
|
|
|
|
hiddenControls: state.hiddenControls
|
|
|
|
|
}),
|
|
|
|
|
dispatch => ({
|
|
|
|
|
startConversation: cible => dispatch(startConversation(cible)),
|
|
|
|
|
hideControl: id => dispatch(hideControl(id))
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
withColours,
|
|
|
|
|
withLanguage
|
|
|
|
|
)(Controls)
|