From 70b25592560d7f13a0a6132601d5f7f16adf602e Mon Sep 17 00:00:00 2001 From: mama Date: Fri, 24 Nov 2017 11:04:29 +0100 Subject: [PATCH] :bug: On ne peut rentrer un brut si c'est un objectif --- source/engine/generateQuestions.js | 37 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index 59797d731..27a8ba7f3 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -102,6 +102,25 @@ let buildVariantTree = (allRules, path) => { return rec(path) } +let buildPossibleInversion = (rule, flatRules, targetNames) => { + let inversions = R.path(['formule', 'inversion', 'avec'])(rule), + inversionObjects = inversions.map(i => + findRuleByDottedName( + flatRules, + disambiguateRuleReference(flatRules, rule, i) + ) + ), + yo = R.reject(({ name }) => targetNames.includes(name))([rule].concat(inversionObjects)) + + return ( + inversions && { + inversions: yo, + question: rule.formule.inversion.question, + title: rule.formule.inversion.titre + } + ) +} + export let makeQuestion = (flatRules, targetNames) => dottedName => { let rule = findRuleByDottedName(flatRules, dottedName) @@ -113,23 +132,7 @@ export let makeQuestion = (flatRules, targetNames) => dottedName => { placeholder: 'votre réponse' }, suggestions: rule.suggestions, - inversion: do { - let inversions = R.path(['formule', 'inversion', 'avec'])(rule) - inversions && { - inversions: [rule].concat( - R.reject(({ name }) => targetNames.includes(name))( - inversions.map(i => - findRuleByDottedName( - flatRules, - disambiguateRuleReference(flatRules, rule, i) - ) - ) - ) - ), - question: rule.formule.inversion.question, - title: rule.formule.inversion.titre - } - } + inversion: buildPossibleInversion(rule, flatRules, targetNames) }) let selectQuestion = rule => ({ component: Select,