2019-03-19 17:50:16 +00:00
|
|
|
import { goBackToSimulation } from 'Actions/actions'
|
|
|
|
import { ScrollToTop } from 'Components/utils/Scroll'
|
2020-03-30 17:14:03 +00:00
|
|
|
import { decodeRuleName } from 'Engine/ruleUtils'
|
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-11-10 15:57:44 +00:00
|
|
|
import { connect, useSelector } from 'react-redux'
|
2020-04-05 21:19:02 +00:00
|
|
|
import { Redirect, useParams } from 'react-router-dom'
|
2020-04-05 21:27:31 +00:00
|
|
|
import { DottedName } from 'Rules'
|
2019-11-10 15:57:44 +00:00
|
|
|
import {
|
|
|
|
noUserInputSelector,
|
2020-03-26 15:03:19 +00:00
|
|
|
parsedRulesSelector,
|
2019-11-10 15:57:44 +00:00
|
|
|
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
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
export default function RulePage() {
|
2020-03-26 15:03:19 +00:00
|
|
|
const parsedRules = useSelector(parsedRulesSelector)
|
2019-11-10 15:57:44 +00:00
|
|
|
const brancheName = useSelector(situationBranchNameSelector)
|
|
|
|
const valuesToShow = !useSelector(noUserInputSelector)
|
2020-04-05 21:19:02 +00:00
|
|
|
const { name } = useParams()
|
|
|
|
const decodedRuleName = decodeRuleName(name)
|
2018-06-12 13:52:41 +00:00
|
|
|
|
2019-11-10 15:57:44 +00:00
|
|
|
const renderRule = (dottedName: DottedName) => {
|
2019-09-11 08:06:26 +00:00
|
|
|
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
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
if (!parsedRules.hasOwnProperty(decodedRuleName))
|
|
|
|
return <Redirect to="/404" />
|
2018-11-14 15:51:37 +00:00
|
|
|
|
2019-12-13 16:22:18 +00:00
|
|
|
return renderRule(decodedRuleName as DottedName)
|
2019-11-10 15:57:44 +00:00
|
|
|
}
|
2018-11-14 15:51:37 +00:00
|
|
|
|
2019-11-10 15:57:44 +00:00
|
|
|
const BackToSimulation = connect(null, { goBackToSimulation })(
|
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-11-10 15:57:44 +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
|
|
|
)
|