2019-03-19 17:50:16 +00:00
|
|
|
import { goBackToSimulation } from 'Actions/actions'
|
|
|
|
import { ScrollToTop } from 'Components/utils/Scroll'
|
2019-10-17 17:03:25 +00:00
|
|
|
import { decodeRuleName, findRuleByDottedName } 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-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-10-17 17:03:25 +00:00
|
|
|
import { flatRulesSelector, noUserInputSelector, situationBranchNameSelector } from 'Selectors/analyseSelectors'
|
2019-03-19 17:50:16 +00:00
|
|
|
import Rule from './rule/Rule'
|
|
|
|
import './RulePage.css'
|
|
|
|
import SearchButton from './SearchButton'
|
2018-04-26 12:24:47 +00:00
|
|
|
|
2019-10-17 17:03:25 +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 }) {
|
2019-10-17 17:03:25 +00:00
|
|
|
let name = match ?.params ?.name,
|
2019-09-11 08:06:26 +00:00
|
|
|
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 (
|
2019-10-02 16:46:05 +00:00
|
|
|
<button
|
2019-10-17 17:03:25 +00:00
|
|
|
className="ui__ simple small push-left button"
|
2019-10-02 16:46:05 +00:00
|
|
|
onClick={goBackToSimulation}>
|
2019-10-17 17:03:25 +00:00
|
|
|
← <Trans i18nKey="back">Reprendre la simulation</Trans>
|
2019-09-11 08:06:26 +00:00
|
|
|
</button>
|
|
|
|
)
|
2018-04-27 09:04:45 +00:00
|
|
|
}
|
2018-11-14 15:51:37 +00:00
|
|
|
)
|