2019-03-19 18:50:16 +01:00
|
|
|
import { goBackToSimulation } from 'Actions/actions'
|
|
|
|
import { ScrollToTop } from 'Components/utils/Scroll'
|
2020-03-30 19:14:03 +02:00
|
|
|
import { decodeRuleName } from 'Engine/ruleUtils'
|
2020-04-02 18:54:41 +02:00
|
|
|
import React, { useContext } from 'react'
|
2019-09-11 10:06:51 +02:00
|
|
|
import { Trans } from 'react-i18next'
|
2019-11-10 16:57:44 +01:00
|
|
|
import { connect, useSelector } from 'react-redux'
|
2020-04-05 23:19:02 +02:00
|
|
|
import { Redirect, useParams } from 'react-router-dom'
|
2020-04-05 23:27:31 +02:00
|
|
|
import { DottedName } from 'Rules'
|
2020-04-02 18:54:41 +02:00
|
|
|
|
|
|
|
import Rule from './Documentation/Rule'
|
2019-03-19 18:50:16 +01:00
|
|
|
import './RulePage.css'
|
|
|
|
import SearchButton from './SearchButton'
|
2020-04-02 18:54:41 +02:00
|
|
|
import { EngineContext } from './utils/EngineContext'
|
|
|
|
import { firstStepCompletedSelector } from 'Selectors/simulationSelectors'
|
2018-04-26 14:24:47 +02:00
|
|
|
|
2020-04-05 23:19:02 +02:00
|
|
|
export default function RulePage() {
|
2020-04-02 18:54:41 +02:00
|
|
|
const parsedRules = useContext(EngineContext).getParsedRules()
|
|
|
|
const valuesToShow = useSelector(firstStepCompletedSelector)
|
2020-04-05 23:19:02 +02:00
|
|
|
const { name } = useParams()
|
2020-04-12 23:30:58 +02:00
|
|
|
const decodedRuleName = decodeRuleName(name ?? '')
|
2018-06-12 15:52:41 +02:00
|
|
|
|
2019-11-10 16:57:44 +01:00
|
|
|
const renderRule = (dottedName: DottedName) => {
|
2019-09-11 10:06:26 +02:00
|
|
|
return (
|
|
|
|
<div id="RulePage">
|
2020-04-02 18:54:41 +02:00
|
|
|
<ScrollToTop key={dottedName} />
|
2019-09-11 10:06:26 +02:00
|
|
|
<div className="rule-page__header">
|
|
|
|
{valuesToShow ? <BackToSimulation /> : <span />}
|
|
|
|
<SearchButton />
|
|
|
|
</div>
|
|
|
|
<Rule dottedName={dottedName} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-02-12 15:53:07 +01:00
|
|
|
|
2020-04-05 23:19:02 +02:00
|
|
|
if (!parsedRules.hasOwnProperty(decodedRuleName))
|
|
|
|
return <Redirect to="/404" />
|
2018-11-14 16:51:37 +01:00
|
|
|
|
2019-12-13 17:22:18 +01:00
|
|
|
return renderRule(decodedRuleName as DottedName)
|
2019-11-10 16:57:44 +01:00
|
|
|
}
|
2018-11-14 16:51:37 +01:00
|
|
|
|
2019-11-10 16:57:44 +01:00
|
|
|
const BackToSimulation = connect(null, { goBackToSimulation })(
|
2018-11-14 16:51:37 +01:00
|
|
|
// Triggers rerender when the language changes
|
2019-09-11 10:06:26 +02:00
|
|
|
function BackToSimulation({ goBackToSimulation }) {
|
|
|
|
return (
|
2019-10-02 18:46:05 +02:00
|
|
|
<button
|
2019-10-17 19:03:25 +02:00
|
|
|
className="ui__ simple small push-left button"
|
2019-11-10 16:57:44 +01:00
|
|
|
onClick={goBackToSimulation}
|
|
|
|
>
|
2019-10-17 19:03:25 +02:00
|
|
|
← <Trans i18nKey="back">Reprendre la simulation</Trans>
|
2019-09-11 10:06:26 +02:00
|
|
|
</button>
|
|
|
|
)
|
2018-04-27 11:04:45 +02:00
|
|
|
}
|
2018-11-14 16:51:37 +01:00
|
|
|
)
|