2019-03-19 17:50:16 +00:00
|
|
|
import { goBackToSimulation } from 'Actions/actions'
|
|
|
|
import { ScrollToTop } from 'Components/utils/Scroll'
|
|
|
|
import {
|
|
|
|
decodeRuleName,
|
2019-10-16 10:18:07 +00:00
|
|
|
findRuleByDottedName
|
2019-03-19 17:50:16 +00:00
|
|
|
} from 'Engine/rules.js'
|
2019-10-16 10:18:07 +00:00
|
|
|
import { compose } from 'ramda'
|
2019-09-11 08:06:26 +00:00
|
|
|
import React from 'react'
|
2019-03-19 17:50:16 +00:00
|
|
|
import emoji from 'react-easy-emoji'
|
2019-09-11 08:06:51 +00:00
|
|
|
import { Trans } from 'react-i18next'
|
2019-03-19 17:50:16 +00:00
|
|
|
import { connect } from 'react-redux'
|
2019-10-16 10:18:07 +00:00
|
|
|
import { Redirect } from 'react-router-dom'
|
2019-03-19 17:50:16 +00:00
|
|
|
import {
|
|
|
|
flatRulesSelector,
|
|
|
|
noUserInputSelector,
|
|
|
|
situationBranchNameSelector
|
|
|
|
} from 'Selectors/analyseSelectors'
|
|
|
|
import Rule from './rule/Rule'
|
|
|
|
import './RulePage.css'
|
|
|
|
import SearchButton from './SearchButton'
|
2018-04-26 12:24:47 +00:00
|
|
|
|
2018-11-14 15:51:37 +00:00
|
|
|
export default compose(
|
|
|
|
connect(state => ({
|
|
|
|
valuesToShow: !noUserInputSelector(state),
|
2019-01-13 20:19:00 +00:00
|
|
|
flatRules: flatRulesSelector(state),
|
|
|
|
brancheName: situationBranchNameSelector(state)
|
2019-09-11 08:06:51 +00:00
|
|
|
}))
|
2019-09-11 08:06:26 +00:00
|
|
|
)(function RulePage({ flatRules, match, valuesToShow, brancheName }) {
|
|
|
|
let name = match?.params?.name,
|
|
|
|
decodedRuleName = decodeRuleName(name)
|
2018-06-12 13:52:41 +00:00
|
|
|
|
2019-09-11 08:06:26 +00:00
|
|
|
const renderRule = dottedName => {
|
|
|
|
return (
|
|
|
|
<div id="RulePage">
|
|
|
|
<ScrollToTop key={brancheName + dottedName} />
|
|
|
|
<div className="rule-page__header">
|
|
|
|
{valuesToShow ? <BackToSimulation /> : <span />}
|
|
|
|
{brancheName && <span id="situationBranch">{brancheName}</span>}
|
|
|
|
<SearchButton />
|
|
|
|
</div>
|
|
|
|
<Rule dottedName={dottedName} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-02-12 14:53:07 +00:00
|
|
|
|
2019-10-16 10:18:07 +00:00
|
|
|
if (!findRuleByDottedName(flatRules, decodedRuleName))
|
|
|
|
return <Redirect to="/404" />
|
2018-11-14 15:51:37 +00:00
|
|
|
|
2019-10-16 10:18:07 +00:00
|
|
|
return renderRule(decodedRuleName)
|
2019-09-11 08:06:26 +00:00
|
|
|
})
|
2018-11-14 15:51:37 +00:00
|
|
|
|
|
|
|
const BackToSimulation = compose(
|
|
|
|
connect(
|
|
|
|
null,
|
2019-01-11 10:46:02 +00:00
|
|
|
{ goBackToSimulation }
|
2019-09-11 08:06:51 +00:00
|
|
|
)
|
2018-11-14 15:51:37 +00:00
|
|
|
)(
|
|
|
|
// Triggers rerender when the language changes
|
2019-09-11 08:06:26 +00:00
|
|
|
function BackToSimulation({ goBackToSimulation }) {
|
|
|
|
return (
|
|
|
|
<button className="ui__ simple small button" onClick={goBackToSimulation}>
|
|
|
|
{emoji('⬅️')} <Trans i18nKey="back">Reprendre la simulation</Trans>
|
|
|
|
</button>
|
|
|
|
)
|
2018-04-27 09:04:45 +00:00
|
|
|
}
|
2018-11-14 15:51:37 +00:00
|
|
|
)
|