import React, { Component } from 'react' import { Trans, translate } from 'react-i18next' import { connect } from 'react-redux' import { head, path, compose } from 'ramda' import { decodeRuleName, findRulesByName, findRuleByDottedName } from 'Engine/rules.js' import { encodeRuleName } from 'Engine/rules' import { Link, Redirect } from 'react-router-dom' import { animateScroll } from 'react-scroll' import './RulePage.css' import SearchButton from './SearchButton' import Namespace from './rule/Namespace' import Rule from './rule/Rule' import { setExample } from '../actions' import { noUserInputSelector, flatRulesSelector } from 'Selectors/analyseSelectors' @connect(state => ({ themeColours: state.themeColours, valuesToShow: !noUserInputSelector(state), flatRules: flatRulesSelector(state) })) @translate() export default class RulePage extends Component { componentDidMount() { animateScroll.scrollToTop({ duration: 300 }) } render() { let { flatRules } = this.props, name = path(['match', 'params', 'name'], this.props), decodedRuleName = decodeRuleName(name) if (decodedRuleName.includes(' . ')) { if (!findRuleByDottedName(flatRules, decodedRuleName)) return return this.renderRule(decodedRuleName) } let rules = findRulesByName(flatRules, decodedRuleName) if (!rules.length) return if (rules.length > 1) return let dottedName = head(rules).dottedName return this.renderRule(dottedName) } renderRule(dottedName) { return (
{!this.props.noUserInputSelector && ( )}
) } } @connect(null, dispatch => ({ setExample: compose(dispatch, setExample) })) class BackToSimulation extends Component { render() { let { colour, setExample } = this.props return ( setExample(null)} id="toSimulation" to={'/'} style={{ background: colour }}>