diff --git a/source/components/Route404.js b/source/components/Route404.js
index 266728b76..f27c97107 100644
--- a/source/components/Route404.js
+++ b/source/components/Route404.js
@@ -1,14 +1,24 @@
import React from 'react'
-import {Link} from 'react-router-dom'
+import { Link } from 'react-router-dom'
-export default () =>
-
-
- On peut facilement se perdre dans la législation...
-
-
- {/* TODO: credits for the image to add: https://thenounproject.com/term/treasure-map/96666/ */}
-
- Revenir en lieu sûr
-
-
+export default () => (
+
+
On peut facilement se perdre dans la législation...
+
+ {/* TODO: credits for the image to add: https://thenounproject.com/term/treasure-map/96666/ */}
+
+
Revenir en lieu sûr
+
+
+)
diff --git a/source/components/Simulateur.js b/source/components/Simulateur.js
index 709bb3419..5bb0afa94 100644
--- a/source/components/Simulateur.js
+++ b/source/components/Simulateur.js
@@ -3,7 +3,7 @@ import React, { Component } from 'react'
import Helmet from 'react-helmet'
import { reset, change, formValueSelector } from 'redux-form'
import { connect } from 'react-redux'
-import { withRouter } from 'react-router-dom'
+import { withRouter, Redirect } from 'react-router-dom'
import { START_CONVERSATION } from '../actions'
import { rules, findRuleByName, decodeRuleName } from 'Engine/rules'
@@ -47,22 +47,21 @@ export default class extends Component {
targetNames = encodedTargets.split('+').map(decodeRuleName)
this.targetNames = targetNames
- this.targetRules = targetNames.map(name => findRuleByName(rules, name))
+ this.targetRules = R.reject(R.isNil)(
+ targetNames.map(name => findRuleByName(rules, name))
+ )
this.targetRules.map(({ dottedName }) => resetFormField(dottedName))
- // C'est ici que la génération du formulaire, et donc la traversée des variables commence
- // if (!existingConversation)
- //TODO
+
if (
- this.props.foldedSteps.length === 0 ||
- !R.equals(targetNames, pastTargetNames)
+ this.targetRules.length > 0 &&
+ (this.props.foldedSteps.length === 0 ||
+ !R.equals(targetNames, pastTargetNames))
)
this.props.startConversation(targetNames)
}
render() {
- //TODO
- // if (!this.targets.formule && !R.path(['simulateur', 'objectifs'], this.rule))
- // return
+ if (this.targetRules.length == 0) return
let {
foldedSteps,
diff --git a/source/components/rule/Rule.js b/source/components/rule/Rule.js
index 88132dc62..00e15e74f 100644
--- a/source/components/rule/Rule.js
+++ b/source/components/rule/Rule.js
@@ -1,17 +1,23 @@
-import React, { Component } from "react"
-import { connect } from "react-redux"
-import R from "ramda"
-import "./Rule.css"
-import { rules, decodeRuleName, nameLeaf } from "Engine/rules.js"
-import { analyse } from "Engine/traverse"
-import { START_CONVERSATION } from "../../actions"
-import possiblesDestinataires from "Règles/ressources/destinataires/destinataires.yaml"
-import { capitalise0 } from "../../utils"
-import References from "./References"
-import Algorithm from "./Algorithm"
-import Examples from "./Examples"
-import Helmet from "react-helmet"
-import {createMarkdownDiv} from 'Engine/marked'
+import React, { Component } from 'react'
+import { connect } from 'react-redux'
+import { Redirect } from 'react-router'
+import R from 'ramda'
+import './Rule.css'
+import {
+ rules,
+ decodeRuleName,
+ nameLeaf,
+ findRuleByName
+} from 'Engine/rules.js'
+import { analyse } from 'Engine/traverse'
+import { START_CONVERSATION } from '../../actions'
+import possiblesDestinataires from 'Règles/ressources/destinataires/destinataires.yaml'
+import { capitalise0 } from '../../utils'
+import References from './References'
+import Algorithm from './Algorithm'
+import Examples from './Examples'
+import Helmet from 'react-helmet'
+import { createMarkdownDiv } from 'Engine/marked'
@connect(
state => ({
@@ -29,16 +35,17 @@ export default class Rule extends Component {
showValues: true
}
componentWillReceiveProps(nextProps) {
- let get = R.path(["match", "params", "name"])
+ let get = R.path(['match', 'params', 'name'])
if (get(nextProps) !== get(this.props)) {
this.setRule(get(nextProps))
this.setState({ example: null, showValues: true })
}
}
setRule(name) {
- this.rule = analyse(rules, nameLeaf(decodeRuleName(name)))(
- this.props.situationGate
- ).targets[0]
+ let ruleName = nameLeaf(decodeRuleName(name)),
+ rule = findRuleByName(rules, ruleName)
+ if (!rule) return null
+ this.rule = analyse(rules, rule.name)(this.props.situationGate).targets[0]
}
componentWillMount() {
let { match: { params: { name } } } = this.props
@@ -46,17 +53,14 @@ export default class Rule extends Component {
this.setRule(name)
}
render() {
- // if (!rule) {
- // this.props.router.push('/404')
- // return null
- // }
+ if (!this.rule) return
let conversationStarted = !R.isEmpty(this.props.form),
situationExists = conversationStarted || this.state.example != null
let { type, name, title, description, question } = this.rule,
situationOrExampleRule =
- R.path(["example", "rule"])(this.state) || this.rule
+ R.path(['example', 'rule'])(this.state) || this.rule
return (