2017-12-07 14:19:51 +00:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import Rule from 'Components/rule/Rule'
|
|
|
|
import { analyse } from 'Engine/traverse'
|
|
|
|
import { head, path } from 'ramda'
|
|
|
|
import { decodeRuleName, nameLeaf, findRuleByName } from 'Engine/rules.js'
|
2017-12-07 19:00:36 +00:00
|
|
|
import {encodeRuleName} from 'Engine/rules'
|
|
|
|
import {pipe, pluck, join, map} from 'ramda'
|
2017-12-08 14:12:41 +00:00
|
|
|
import { Link, Redirect} from 'react-router-dom'
|
2017-12-07 19:00:36 +00:00
|
|
|
import {animateScroll} from 'react-scroll'
|
|
|
|
import './PageRule.css'
|
2017-12-07 14:19:51 +00:00
|
|
|
|
|
|
|
@connect(state => ({
|
|
|
|
situationGate: state.situationGate,
|
2017-12-07 19:00:36 +00:00
|
|
|
parsedRules: state.parsedRules,
|
|
|
|
analysis: state.analysis
|
2017-12-07 14:19:51 +00:00
|
|
|
}))
|
|
|
|
export default class RulePage extends Component {
|
|
|
|
nameFromParams = path(['match', 'params', 'name'])
|
|
|
|
componentWillMount() {
|
|
|
|
this.setRule(this.nameFromParams(this.props))
|
|
|
|
}
|
2017-12-07 19:00:36 +00:00
|
|
|
componentDidMount(){
|
|
|
|
animateScroll.scrollToTop({duration: 300})
|
|
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (this.nameFromParams(nextProps) !== this.nameFromParams(this.props)) {
|
|
|
|
this.setRule(this.nameFromParams(nextProps))
|
|
|
|
}
|
|
|
|
}
|
2017-12-07 14:19:51 +00:00
|
|
|
setRule(name) {
|
|
|
|
let ruleName = nameLeaf(decodeRuleName(name)),
|
|
|
|
rule = findRuleByName(this.props.parsedRules, ruleName)
|
|
|
|
if (!rule) return null
|
|
|
|
this.rule = head(
|
|
|
|
analyse(this.props.parsedRules, rule.name)(this.props.situationGate)
|
|
|
|
.targets
|
|
|
|
)
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
if (!this.rule) return <Redirect to="/404" />
|
|
|
|
|
2017-12-07 19:00:36 +00:00
|
|
|
let targets = path(['analysis', 'targets'], this.props)
|
|
|
|
|
|
|
|
return (<>
|
|
|
|
{targets && <BackToSimulation targets={targets}/> }
|
|
|
|
<Rule rule={this.rule} />
|
|
|
|
</>)
|
2017-12-07 14:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 19:00:36 +00:00
|
|
|
|
|
|
|
let BackToSimulation = ({targets}) =>
|
|
|
|
<Link id="toSimulation" to={'/simu/' + pipe(pluck('name'), map(encodeRuleName), join('+'))(targets)}>
|
|
|
|
<i className="fa fa-arrow-circle-left" aria-hidden="true"></i>Reprendre la simulation
|
|
|
|
</Link>
|