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'
|
2020-04-23 07:30:03 +00:00
|
|
|
import React, { useContext } 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'
|
2020-04-23 07:30:03 +00:00
|
|
|
|
|
|
|
import Rule from './Documentation/Rule'
|
2019-03-19 17:50:16 +00:00
|
|
|
import './RulePage.css'
|
|
|
|
import SearchButton from './SearchButton'
|
2020-04-23 07:30:03 +00:00
|
|
|
import { EngineContext } from './utils/EngineContext'
|
|
|
|
import { firstStepCompletedSelector } from 'Selectors/simulationSelectors'
|
2018-04-26 12:24:47 +00:00
|
|
|
|
2020-04-05 21:19:02 +00:00
|
|
|
export default function RulePage() {
|
2020-04-23 07:30:03 +00:00
|
|
|
const parsedRules = useContext(EngineContext).getParsedRules()
|
|
|
|
const valuesToShow = useSelector(firstStepCompletedSelector)
|
2020-04-05 21:19:02 +00:00
|
|
|
const { name } = useParams()
|
2020-04-12 21:30:58 +00:00
|
|
|
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">
|
2020-04-23 07:30:03 +00:00
|
|
|
<ScrollToTop key={dottedName} />
|
2019-09-11 08:06:26 +00:00
|
|
|
<div className="rule-page__header">
|
|
|
|
{valuesToShow ? <BackToSimulation /> : <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
|
|
|
)
|