diff --git a/source/actions.js b/source/actions.js index 9e187b9ed..955de7b21 100644 --- a/source/actions.js +++ b/source/actions.js @@ -6,6 +6,10 @@ export function stepAction(name, step, source) { return { type: STEP_ACTION, name, step, source } } +export function setExample(name, situation) { + return { type: 'SET_EXAMPLE', situation, name } +} + export const START_CONVERSATION = 'START_CONVERSATION' // Reset the form diff --git a/source/components/rule/Algorithm.js b/source/components/rule/Algorithm.js index f972cab22..8e33a42a3 100644 --- a/source/components/rule/Algorithm.js +++ b/source/components/rule/Algorithm.js @@ -6,6 +6,9 @@ import knownMecanisms from 'Engine/known-mecanisms.yaml' import { makeJsx } from 'Engine/evaluation' import './Algorithm.css' import { humanFigure } from '../../utils' +import { head } from 'ramda' +import { analyse } from 'Engine/traverse' +import { exampleSituationGateWithDefaults } from './Examples' let RuleWithoutFormula = () => (

@@ -16,14 +19,21 @@ let RuleWithoutFormula = () => ( @AttachDictionary(knownMecanisms) export default class Algorithm extends React.Component { - state = { - showValues: true - } render() { - let { rule, showValues } = this.props, + let { rule: displayedRule, showValues, currentExample, rules } = this.props, ruleWithoutFormula = - !rule['formule'] || - path(['formule', 'explanation', 'une possibilité'], rule) + !displayedRule['formule'] || + path(['formule', 'explanation', 'une possibilité'], displayedRule) + + let rule = currentExample + ? head( + analyse(rules, displayedRule.dottedName)( + exampleSituationGateWithDefaults(currentExample.situation, rules) + ).targets + ) + : displayedRule + + console.log('didcomp') return (

diff --git a/source/components/rule/Examples.js b/source/components/rule/Examples.js index a956e10bc..6404be7ce 100644 --- a/source/components/rule/Examples.js +++ b/source/components/rule/Examples.js @@ -1,11 +1,15 @@ import React, { Component } from 'react' -import { evolve, path, isEmpty } from 'ramda' +import { evolve, path, isEmpty, compose } from 'ramda' import classNames from 'classnames' import { connect } from 'react-redux' import { disambiguateExampleSituation, collectDefaults } from 'Engine/rules.js' import { analyse } from 'Engine/traverse' import './Examples.css' import { assume } from '../../reducers' +import { setExample } from '../../actions' + +export let exampleSituationGateWithDefaults = (situationObject, rules) => + assume(() => name => situationObject[name], collectDefaults(rules))() // By luck this works as expected for both null and undefined, * but with different branches failing :O * export let isFloat = n => Number(n) === n && n % 1 !== 0 @@ -16,10 +20,8 @@ export let runExamples = (examples, rule, parsedRules) => examples .map(evolve({ situation: disambiguateExampleSituation(parsedRules, rule) })) .map(ex => { - let exampleSituationGate = () => name => ex.situation[name] - let runExample = analyse(parsedRules, rule.dottedName)( - assume(exampleSituationGate, collectDefaults(parsedRules))() + exampleSituationGateWithDefaults(ex.situation, parsedRules) ), exampleValue = runExample.targets[0].nodeValue, goal = ex['valeur attendue'], @@ -37,21 +39,25 @@ export let runExamples = (examples, rule, parsedRules) => } }) -@connect(state => ({ - situationGate: state.situationGate, - parsedRules: state.parsedRules, - colour: state.themeColours.colour -})) +@connect( + state => ({ + situationGate: state.situationGate, + parsedRules: state.parsedRules, + colour: state.themeColours.colour + }), + dispatch => ({ + setExample: compose(dispatch, setExample) + }) +) export default class Examples extends Component { render() { - let focusedExample = path(['focusedExample', 'nom'])(this.props), - { - inject, + let { situationExists, - showValues, rule, parsedRules, - colour + colour, + setExample, + currentExample } = this.props, { exemples = [] } = rule, examples = runExamples(exemples, rule, parsedRules) @@ -70,46 +76,51 @@ export default class Examples extends Component {

) : (