diff --git a/source/components/Aide.js b/source/components/Aide.js
index 005884f38..5f6b75de3 100644
--- a/source/components/Aide.js
+++ b/source/components/Aide.js
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import marked from 'Engine/marked'
-import { rules, findRuleByDottedName } from 'Engine/rules'
+import { findRuleByDottedName } from 'Engine/rules'
import { EXPLAIN_VARIABLE } from '../actions'
import References from './rule/References'
@@ -11,7 +11,8 @@ import './Aide.css'
@connect(
state => ({
explained: state.explainedVariable,
- themeColours: state.themeColours
+ themeColours: state.themeColours,
+ flatRules: state.flatRules
}),
dispatch => ({
stopExplaining: () => dispatch({ type: EXPLAIN_VARIABLE })
@@ -22,11 +23,11 @@ export default class Aide extends Component {
return marked(`### ${term} \n\n${explanation}`)
}
render() {
- let { explained, stopExplaining, themeColours } = this.props
+ let { flatRules, explained, stopExplaining, themeColours } = this.props
if (!explained) return
- let rule = findRuleByDottedName(rules, explained),
+ let rule = findRuleByDottedName(flatRules, explained),
text = rule.description,
refs = rule.références
diff --git a/source/components/ResultsGrid.js b/source/components/ResultsGrid.js
index 60e72f945..037de03d3 100644
--- a/source/components/ResultsGrid.js
+++ b/source/components/ResultsGrid.js
@@ -28,7 +28,7 @@ import './Results.css'
import '../engine/mecanismViews/Somme.css'
import { capitalise0, humanFigure } from '../utils'
-import { nameLeaf, encodeRuleName, rules, findRuleByDottedName } from 'Engine/rules'
+import { nameLeaf, encodeRuleName, findRuleByDottedName } from 'Engine/rules'
// Filtered variables and rules can't be filtered in a uniform way, for now
let paidBy = payer => item =>
@@ -76,12 +76,14 @@ export let byBranch = analysis => {
targetNames: state.targetNames,
situationGate: state.situationGate,
inversions: formValueSelector('conversation')(state, 'inversions'),
- done: state.done
+ done: state.done,
+ flatRules: state.flatRules
}))
@translate()
export default class ResultsGrid extends Component {
render() {
- let { analysis, situationGate, targetNames, inversions, done } = this.props
+ let { analysis, situationGate, targetNames, inversions, done, flatRules } = this.props,
+ rules = flatRules
if (!done) return null
@@ -126,6 +128,7 @@ export default class ResultsGrid extends Component {
branch,
values,
analysis,
+ rules,
relevantSalaries
}
return
@@ -173,7 +176,7 @@ class Row extends Component {
folded: true
}
render() {
- let { branch, values, analysis, relevantSalaries } = this.props,
+ let { rules, branch, values, analysis, relevantSalaries } = this.props,
detail = byName(values),
ruleData = mapObjIndexed((v,k,o) => findRuleByDottedName(rules,k), detail),
{ i18n } = this.context
diff --git a/source/components/conversation/Explicable.js b/source/components/conversation/Explicable.js
index 88922dc6f..450f5ecfa 100644
--- a/source/components/conversation/Explicable.js
+++ b/source/components/conversation/Explicable.js
@@ -3,14 +3,15 @@ import classNames from 'classnames'
import './Explicable.css'
import { connect } from 'react-redux'
import { EXPLAIN_VARIABLE } from '../../actions'
-import { rules, findRuleByDottedName } from 'Engine/rules'
+import { findRuleByDottedName } from 'Engine/rules'
import ReactPiwik from '../Tracker'
@connect(
state => ({
explained: state.explainedVariable,
- textColourOnWhite: state.themeColours.textColourOnWhite
+ textColourOnWhite: state.themeColours.textColourOnWhite,
+ flatRules: state.flatRules
}),
dispatch => ({
explain: variableName => dispatch({ type: EXPLAIN_VARIABLE, variableName })
@@ -18,12 +19,12 @@ import ReactPiwik from '../Tracker'
)
export default class Explicable extends React.Component {
render() {
- let { dottedName, explain, explained, textColourOnWhite } = this.props
+ let { flatRules, dottedName, explain, explained, textColourOnWhite } = this.props
// Rien à expliquer ici, ce n'est pas une règle
if (dottedName == null) return this.props.children
- let rule = findRuleByDottedName(rules, dottedName)
+ let rule = findRuleByDottedName(flatRules, dottedName)
if (rule.description == null) return this.props.children
diff --git a/source/components/pages/RulesList.js b/source/components/pages/RulesList.js
index dce3a5a08..0b0c642ff 100644
--- a/source/components/pages/RulesList.js
+++ b/source/components/pages/RulesList.js
@@ -1,5 +1,6 @@
import React, { Component } from 'react'
-import { rules, encodeRuleName } from 'Engine/rules.js'
+import { connect } from 'react-redux'
+import { encodeRuleName } from 'Engine/rules.js'
import { Link } from 'react-router-dom'
import './RulesList.css'
import './Pages.css'
@@ -11,12 +12,18 @@ import { Redirect } from 'react-router-dom'
import Highlighter from 'react-highlight-words'
import { pick } from 'ramda'
+@connect(
+ state => ({
+ flatRules: state.flatRules
+ })
+)
export default class RulesList extends Component {
render() {
+ let { flatRules } = this.props;
return (
Explorez notre base de règles
-
+
)
}
diff --git a/source/reducers.js b/source/reducers.js
index 9458e21be..aeae1d1b8 100644
--- a/source/reducers.js
+++ b/source/reducers.js
@@ -60,8 +60,11 @@ export let reduceSteps = (tracker, flatRules, answerSource) => (
state,
action
) => {
+ state.flatRules = flatRules
// Optimization - don't parse on each analysis
- if (!state.parsedRules) state.parsedRules = parseAll(flatRules)
+ if (!state.parsedRules) {
+ state.parsedRules = parseAll(flatRules)
+ }
if (
![START_CONVERSATION, STEP_ACTION, 'USER_INPUT_UPDATE'].includes(
@@ -201,6 +204,7 @@ export default reduceReducers(
nextSteps: (state = []) => state,
parsedRules: (state = null) => state,
+ flatRules: (state = null) => state,
analysis: (state = null) => state,
targetNames: (state = null) => state,