From afee37857086f21de73f3058bf17a35939f5380e Mon Sep 17 00:00:00 2001 From: Mael Date: Fri, 7 Sep 2018 12:51:30 +0200 Subject: [PATCH] :art: Affichage de la variation satisfaite --- source/engine/mecanismViews/Variations.js | 62 +++++++++++++---------- source/engine/mecanisms.js | 27 ++++++---- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/source/engine/mecanismViews/Variations.js b/source/engine/mecanismViews/Variations.js index 9ee0d68bc..d95a95f95 100644 --- a/source/engine/mecanismViews/Variations.js +++ b/source/engine/mecanismViews/Variations.js @@ -2,34 +2,44 @@ import React from 'react' import { Node } from './common' import { makeJsx } from '../evaluation' import './Variations.css' +import { ShowValuesConsumer } from 'Components/rule/ShowValuesContext' export default function Variations(nodeValue, explanation) { return ( - - {explanation.map(c => ( -
  • -
    - {c.condition && ( - <> - Si {makeJsx(c.condition)} - - )} -
    - {c.condition ? 'Alors : ' : 'Sinon : '} - {makeJsx(c.consequence)} -
    -
    -
  • - ))} - - } - /> + + {showValues => ( + + {explanation.map( + c => + console.log('c', c) || ( +
  • +
    + {c.condition && ( + <> + Si {makeJsx(c.condition)} + + )} +
    + {c.condition ? 'Alors : ' : 'Sinon : '} + + {makeJsx(c.consequence)} + +
    +
    +
  • + ) + )} + + } + /> + )} +
    ) } diff --git a/source/engine/mecanisms.js b/source/engine/mecanisms.js index 58d620254..9646bd946 100644 --- a/source/engine/mecanisms.js +++ b/source/engine/mecanisms.js @@ -162,17 +162,21 @@ export let mecanismVariations = (recurse, k, v, devariate) => { : evaluateNode(cache, situationGate, parsedRules, prop) ), evaluatedExplanation = map(evaluateVariation, node.explanation), - satisfiedVariation = reduce( - (_, variation) => - variation.condition == undefined - ? reduced(variation) // We've reached the eventual defaut case - : variation.condition.nodeValue === null - ? reduced(null) // one case has missing variables => we can't go further - : variation.condition.nodeValue === true - ? reduced(variation) - : null, - null + // mark the satisfied variation if any in the explanation + [, resolvedExplanation] = reduce( + ([resolved, result], variation) => + resolved + ? [true, [...result, variation]] + : variation.condition == undefined + ? [true, [...result, { ...variation, satisfied: true }]] // We've reached the eventual defaut case + : variation.condition.nodeValue === null + ? [true, [...result, variation]] // one case has missing variables => we can't go further + : variation.condition.nodeValue === true + ? [true, [...result, { ...variation, satisfied: true }]] + : [false, [...result, variation]], + [false, []] )(evaluatedExplanation), + satisfiedVariation = resolvedExplanation.find(v => v.satisfied), nodeValue = satisfiedVariation ? satisfiedVariation.consequence.nodeValue : null @@ -978,7 +982,8 @@ export let mecanismSynchronisation = (recurse, k, v) => { let nodeValue = val(APIExplanation) == null ? null - : path(v.chemin.split(' . '))(JSON.parse(val(APIExplanation))) + : console.log(APIExplanation) || + path(v.chemin.split(' . '))(JSON.parse(val(APIExplanation))) let missingVariables = val(APIExplanation) === null ? { [APIExplanation.dottedName]: 1 } : {} let explanation = { ...v, API: APIExplanation }