diff --git a/source/Provider.js b/source/Provider.js index f2096bdb6..161f353bd 100644 --- a/source/Provider.js +++ b/source/Provider.js @@ -1,4 +1,5 @@ import SetCSSColour from 'Components/utils/SetCssColour' +import { SitePathProvider } from 'Components/utils/withSitePaths' import { TrackerProvider } from 'Components/utils/withTracker' import createHistory from 'history/createBrowserHistory' import i18next from 'i18next' @@ -66,12 +67,14 @@ export default class Layout extends PureComponent { // If IE < 11 display nothing - - - - <>{this.props.children} - - + + + + + <>{this.props.children} + + + ) diff --git a/source/actions/actions.js b/source/actions/actions.js index ac0deb0a4..75ab621a6 100644 --- a/source/actions/actions.js +++ b/source/actions/actions.js @@ -51,6 +51,17 @@ export function setExample(name, situation, dottedName) { return { type: 'SET_EXAMPLE', name, situation, dottedName } } +export const goBackToSimulation = () => ( + dispatch: any => void, + _: any, + history: RouterHistory +): void => { + while (history.location.pathname.includes('documentation')) { + history.goBack() + } + dispatch({ type: 'SET_EXAMPLE', name: null }) +} + export function loadPreviousSimulation(): LoadPreviousSimulationAction { return { type: 'LOAD_PREVIOUS_SIMULATION' diff --git a/source/components/ComparativeTargets.js b/source/components/ComparativeTargets.js index a7237ac6e..d7d5e8791 100644 --- a/source/components/ComparativeTargets.js +++ b/source/components/ComparativeTargets.js @@ -1,6 +1,7 @@ import PeriodSwitch from 'Components/PeriodSwitch' import withColours from 'Components/utils/withColours' -import { findRuleByDottedName } from 'Engine/rules' +import withSitePaths from 'Components/utils/withSitePaths' +import { encodeRuleName, findRuleByDottedName } from 'Engine/rules' import { compose } from 'ramda' import React from 'react' import emoji from 'react-easy-emoji' @@ -26,7 +27,8 @@ export default compose( setSituationBranch: id => dispatch({ type: 'SET_SITUATION_BRANCH', id }) }) ), - withColours + withColours, + withSitePaths )( class ComparativeTargets extends React.Component { render() { @@ -35,6 +37,7 @@ export default compose( analyses, target, setSituationBranch, + sitePaths, simulationBranches } = this.props if (!simulationBranches) { @@ -44,7 +47,6 @@ export default compose( // This is not elegant let getRatioPrélèvements = analysis => analysis.targets.find(t => t.dottedName === 'ratio de prélèvements') - return (

{target.title}

@@ -87,7 +89,11 @@ export default compose( setSituationBranch(i)} className="explanation"> {emoji('📖')} @@ -99,7 +105,11 @@ export default compose( de{' '} + to={ + sitePaths.documentation.index + + '/' + + encodeRuleName(ratioPrélèvements.dottedName) + }> prélèvements diff --git a/source/components/RuleLink.js b/source/components/RuleLink.js index dc87a2e60..5879429b4 100644 --- a/source/components/RuleLink.js +++ b/source/components/RuleLink.js @@ -1,21 +1,26 @@ /* @flow */ import withColours from 'Components/utils/withColours' +import withSitePaths from 'Components/utils/withSitePaths' import { compose } from 'ramda' import React from 'react' -import { withRouter } from 'react-router' import { Link } from 'react-router-dom' -import { capitalise0, normalizeBasePath } from '../utils' +import { capitalise0 } from '../utils' import './RuleLink.css' import type { Règle } from 'Types/RegleTypes' -import type { Match } from 'react-router' + type Props = Règle & { - match: Match, + sitePaths: Object, style: CSSStyleDeclaration, colours: { colour: string } } -const RuleLink = ({ lien, nom, colours: { colour }, match, style }: Props) => { - const newPath = - normalizeBasePath(match.path).replace(/simulation\/$/, '') + lien +const RuleLink = ({ + lien, + nom, + colours: { colour }, + style, + sitePaths +}: Props) => { + const newPath = sitePaths.documentation.index + '/' + lien return ( { } export default compose( - withRouter, + withSitePaths, withColours )(RuleLink) diff --git a/source/components/RulePage.js b/source/components/RulePage.js index a1c392463..865ae61db 100644 --- a/source/components/RulePage.js +++ b/source/components/RulePage.js @@ -1,4 +1,4 @@ -import { setExample } from 'Actions/actions' +import { goBackToSimulation } from 'Actions/actions' import { ScrollToTop } from 'Components/utils/Scroll' import { encodeRuleName } from 'Engine/rules' import { @@ -25,9 +25,9 @@ export default compose( connect(state => ({ themeColours: state.themeColours, valuesToShow: !noUserInputSelector(state), - flatRules: flatRulesSelector(state), - situationBranch: - state.simulationConfig?.branches[state.situationBranch]?.nom + flatRules: flatRulesSelector(state) + // situationBranch: + // state.simulationConfig?.branches[state.situationBranch]?.nom })), withNamespaces() )( @@ -57,7 +57,7 @@ export default compose( let { situationBranch } = this.props return (
- +
{situationBranch} )} - +
@@ -81,12 +78,7 @@ export default compose( const BackToSimulation = compose( connect( null, - dispatch => ({ - setExample: compose( - dispatch, - setExample - ) - }) + { goBackToSimulation } ), withRouter, withNamespaces() @@ -94,18 +86,20 @@ const BackToSimulation = compose( // Triggers rerender when the language changes class BackToSimulation extends Component { render() { - let { colour, setExample, visible } = this.props + let { goBackToSimulation, visible } = this.props return ( - { - setExample(null) - }} - style={{ color: colour, visibility: visible ? 'visible' : 'hidden' }}> -