import React, { Component } from 'react'
import ReactDOM from 'react-dom'
// import {findRuleByName} from '../engine/rules.js'
import './Rule.css'
import JSONTree from 'react-json-tree'
import R from 'ramda'
import PageTypeIcon from './PageTypeIcon'
import {connect} from 'react-redux'
import mockSituation from '../engine/mockSituation.yaml'
import {START_CONVERSATION} from '../actions'
import classNames from 'classnames'
import destinataires from '../../règles/destinataires/destinataires.yaml'
import references from '../../règles/références/références.yaml'
import {capitalise0} from '../utils'
import knownMecanisms from '../engine/known-mecanisms.yaml'
import marked from '../engine/marked'
// situationGate function useful for testing :
let testingSituationGate = v => // eslint-disable-line no-unused-vars
R.path(v.split('.'))(mockSituation)
@connect(
state => ({
// situationGate: name => formValueSelector('conversation')(state, name),
analysedSituation: state.analysedSituation,
form: state.form
}),
dispatch => ({
startConversation: () => dispatch({type: START_CONVERSATION}),
})
)
export default class Rule extends Component {
componentDidMount() {
// C'est ici que la génération du formulaire, et donc la traversée des variables commence
this.props.startConversation()
}
render() {
let {
params: {name},
analysedSituation,
form
} = this.props,
objectives = R.path(['formule', 'explanation', 'explanation'])(analysedSituation)
if (!objectives) return null
let rule = objectives.find(R.pathEq(['explanation', 'name'], name)).explanation
if (!rule) {
this.props.router.push('/404')
return null
}
let
situationExists = !R.isEmpty(form)
let destinataire = R.path(['attributs', 'destinataire'])(rule),
destinataireData = destinataires[destinataire]
return (
)
}
}
// On ajoute à la section la possibilité d'ouvrir à droite un panneau d'explication des termes.
// Il suffit à la section d'appeler une fonction fournie en lui donnant du JSX
// Ne pas oublier de réduire la largeur de la section pour laisser de la place au dictionnaire.
let AttachDictionary = dictionary => Decorated =>
class extends React.Component {
state = {
term: null,
explanation: null
}
componentDidMount() {
let decoratedNode = ReactDOM.findDOMNode(this.decorated)
decoratedNode.addEventListener('click', e => {
let term = e.target.dataset['termDefinition'],
explanation = R.path([term, 'description'], dictionary)
this.setState({explanation, term})
})
}
renderExplanationMarkdown(explanation, term) {
return marked(`### Mécanisme: ${term}\n\n${explanation}`)
}
render(){
let {explanation, term} = this.state
return (