2018-07-12 08:09:41 +00:00
|
|
|
import { setExample } from 'Actions/actions'
|
2018-08-06 12:14:06 +00:00
|
|
|
import { ScrollToTop } from 'Components/utils/Scroll'
|
2018-06-19 11:51:00 +00:00
|
|
|
import { encodeRuleName } from 'Engine/rules'
|
2018-02-12 14:53:07 +00:00
|
|
|
import {
|
|
|
|
decodeRuleName,
|
2018-06-19 11:51:00 +00:00
|
|
|
findRuleByDottedName,
|
|
|
|
findRulesByName
|
2018-02-12 14:53:07 +00:00
|
|
|
} from 'Engine/rules.js'
|
2018-06-19 11:51:00 +00:00
|
|
|
import { compose, head, path } from 'ramda'
|
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { Trans, translate } from 'react-i18next'
|
|
|
|
import { connect } from 'react-redux'
|
2018-07-02 14:04:34 +00:00
|
|
|
import { withRouter } from 'react-router'
|
2018-01-03 15:54:19 +00:00
|
|
|
import { Link, Redirect } from 'react-router-dom'
|
2018-09-04 14:23:05 +00:00
|
|
|
import {
|
|
|
|
flatRulesSelector,
|
|
|
|
noUserInputSelector
|
|
|
|
} from 'Selectors/analyseSelectors'
|
2018-06-19 11:51:00 +00:00
|
|
|
import Namespace from './rule/Namespace'
|
|
|
|
import Rule from './rule/Rule'
|
2018-07-23 16:07:07 +00:00
|
|
|
import './RulePage.css'
|
2018-06-19 11:51:00 +00:00
|
|
|
import SearchButton from './SearchButton'
|
2018-06-12 13:52:41 +00:00
|
|
|
@connect(state => ({
|
|
|
|
themeColours: state.themeColours,
|
|
|
|
valuesToShow: !noUserInputSelector(state),
|
|
|
|
flatRules: flatRulesSelector(state)
|
|
|
|
}))
|
2018-03-29 12:57:44 +00:00
|
|
|
@translate()
|
2018-09-21 15:28:28 +00:00
|
|
|
class RulePage extends Component {
|
2018-06-12 13:52:41 +00:00
|
|
|
render() {
|
|
|
|
let { flatRules } = this.props,
|
|
|
|
name = path(['match', 'params', 'name'], this.props),
|
2018-02-12 14:53:07 +00:00
|
|
|
decodedRuleName = decodeRuleName(name)
|
2018-04-26 12:24:47 +00:00
|
|
|
|
2018-02-12 14:53:07 +00:00
|
|
|
if (decodedRuleName.includes(' . ')) {
|
2018-06-12 13:52:41 +00:00
|
|
|
if (!findRuleByDottedName(flatRules, decodedRuleName))
|
|
|
|
return <Redirect to="/404" />
|
|
|
|
|
|
|
|
return this.renderRule(decodedRuleName)
|
2018-02-12 14:53:07 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 13:52:41 +00:00
|
|
|
let rules = findRulesByName(flatRules, decodedRuleName)
|
|
|
|
if (!rules.length) return <Redirect to="/404" />
|
2018-06-19 16:01:49 +00:00
|
|
|
if (rules.length > 1)
|
|
|
|
return <DisambiguateRuleQuery rules={rules} flatRules={flatRules} />
|
2018-04-26 12:24:47 +00:00
|
|
|
let dottedName = head(rules).dottedName
|
2018-06-12 13:52:41 +00:00
|
|
|
return this.renderRule(dottedName)
|
2017-12-07 14:19:51 +00:00
|
|
|
}
|
2018-06-12 13:52:41 +00:00
|
|
|
renderRule(dottedName) {
|
2018-01-03 15:54:19 +00:00
|
|
|
return (
|
2018-09-21 15:28:28 +00:00
|
|
|
<div id="RulePage">
|
2018-08-06 12:14:06 +00:00
|
|
|
<ScrollToTop />
|
2018-09-26 14:52:10 +00:00
|
|
|
<div className="rule-page__header ui__ container">
|
2018-08-13 15:15:29 +00:00
|
|
|
<BackToSimulation
|
|
|
|
visible={this.props.valuesToShow}
|
|
|
|
colour={this.props.themeColours.colour}
|
|
|
|
/>
|
2018-07-31 12:52:49 +00:00
|
|
|
<SearchButton
|
|
|
|
className="rule-page__search"
|
|
|
|
rulePageBasePath="../règle"
|
|
|
|
/>
|
2018-06-19 11:51:00 +00:00
|
|
|
</div>
|
2018-06-12 13:52:41 +00:00
|
|
|
<Rule dottedName={dottedName} />
|
2018-03-19 18:18:58 +00:00
|
|
|
</div>
|
2018-01-03 15:54:19 +00:00
|
|
|
)
|
2017-12-07 14:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-07 19:00:36 +00:00
|
|
|
|
2018-06-19 11:51:00 +00:00
|
|
|
@connect(
|
|
|
|
null,
|
|
|
|
dispatch => ({
|
|
|
|
setExample: compose(
|
|
|
|
dispatch,
|
|
|
|
setExample
|
|
|
|
)
|
|
|
|
})
|
|
|
|
)
|
2018-07-02 14:04:34 +00:00
|
|
|
@withRouter
|
2018-07-31 13:32:41 +00:00
|
|
|
@translate() // Triggers rerender when the language changes
|
2018-04-27 09:04:45 +00:00
|
|
|
class BackToSimulation extends Component {
|
|
|
|
render() {
|
2018-08-13 15:15:29 +00:00
|
|
|
let { colour, setExample, visible } = this.props
|
2018-04-27 09:04:45 +00:00
|
|
|
return (
|
2018-07-25 14:07:53 +00:00
|
|
|
<Link
|
2018-04-27 09:04:45 +00:00
|
|
|
id="toSimulation"
|
2018-10-04 13:20:57 +00:00
|
|
|
to="../simulation"
|
2018-07-02 14:04:34 +00:00
|
|
|
onClick={() => {
|
|
|
|
setExample(null)
|
|
|
|
}}
|
2018-08-13 15:15:29 +00:00
|
|
|
style={{ color: colour, visibility: visible ? 'visible' : 'hidden' }}>
|
2018-08-07 13:57:42 +00:00
|
|
|
<i className="fa fa-arrow-left" aria-hidden="true" />
|
|
|
|
<Trans i18nKey="back">Reprendre la simulation</Trans>
|
2018-07-25 14:07:53 +00:00
|
|
|
</Link>
|
2018-04-27 09:04:45 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 14:53:07 +00:00
|
|
|
|
2018-06-19 16:01:49 +00:00
|
|
|
let DisambiguateRuleQuery = ({ rules, flatRules }) => (
|
2018-02-12 14:53:07 +00:00
|
|
|
<div className="centeredMessage">
|
|
|
|
<p>
|
2018-04-06 10:50:11 +00:00
|
|
|
<Trans i18nKey="ambiguous">
|
|
|
|
Plusieurs règles de la base ont ce nom. Laquelle voulez-vous afficher ?
|
|
|
|
</Trans>
|
2018-02-12 14:53:07 +00:00
|
|
|
</p>
|
|
|
|
<ul>
|
|
|
|
{rules.map(({ dottedName, ns, title }) => (
|
|
|
|
<li key={dottedName}>
|
2018-06-19 16:01:49 +00:00
|
|
|
<Namespace ns={ns} flatRules={flatRules} />
|
2018-07-25 14:07:53 +00:00
|
|
|
<Link to={'../règle/' + encodeRuleName(dottedName)}>{title}</Link>
|
2018-02-12 14:53:07 +00:00
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)
|
2018-09-21 15:28:28 +00:00
|
|
|
|
|
|
|
export default RulePage
|