👽 Ne passer les règles que via le state

pull/188/head
Laurent Bossavit 2018-03-29 10:55:42 +02:00 committed by Mael
parent 19c7c8f918
commit b5b663c0dd
5 changed files with 31 additions and 15 deletions

View File

@ -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 <section id="helpWrapper" />
let rule = findRuleByDottedName(rules, explained),
let rule = findRuleByDottedName(flatRules, explained),
text = rule.description,
refs = rule.références

View File

@ -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 <Row {...props} />
@ -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

View File

@ -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

View File

@ -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 (
<div id="RulesList" className="page">
<h1>Explorez notre base de règles</h1>
<SearchBar showDefaultList={true} rules={rules} />
<SearchBar showDefaultList={true} rules={flatRules} />
</div>
)
}

View File

@ -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,