From d5d4e71e925ed00c97ff4d047e883fd8553216c4 Mon Sep 17 00:00:00 2001 From: mama Date: Tue, 6 Feb 2018 18:01:20 +0100 Subject: [PATCH] Simplification gen questions (3) --- source/engine/generateQuestions.js | 13 +++++++------ source/engine/rules.js | 5 ++--- source/engine/traverse.js | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index 820366cf6..c33f00838 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -12,6 +12,7 @@ import { unless, is, prop, + pick, path, reject, identity @@ -55,7 +56,7 @@ export let getNextSteps = (situationGate, analysis) => { return map(head, sortedPairs) } -let isVariant = path(['formule', 'une possibilité']) +let isVariant = rule => queryRule(rule.raw)('formule . une possibilité') let buildVariantTree = (allRules, path) => { let rec = path => { @@ -80,10 +81,10 @@ let buildVariantTree = (allRules, path) => { let buildPossibleInversion = (rule, rules, targetNames) => { let query = queryRule(rule), - invertible = query('formule . inversion') + inversion = query('formule . inversion') - if (!invertible) return null - let inversionObjects = query('inversion . avec').map(i => + if (!inversion) return null + let inversionObjects = query('formule . inversion . avec').map(i => findRuleByDottedName(rules, disambiguateRuleReference(rules, rule, i)) ), inversions = reject(({ name }) => targetNames.includes(name))( @@ -104,10 +105,10 @@ export let getInputComponent = ({ unfolded }) => ( let rule = findRuleByDottedName(rules, dottedName) let commonProps = { + key: dottedName, unfolded, fieldName: dottedName, - title: rule.title, - question: rule.question + ...pick(['dottedName', 'title', 'question', 'defaultValue'], rule) } if (isVariant(rule)) diff --git a/source/engine/rules.js b/source/engine/rules.js index d4315d0ca..a62b38e56 100644 --- a/source/engine/rules.js +++ b/source/engine/rules.js @@ -57,7 +57,8 @@ export let enrichRule = (rule, sharedData = {}) => { data, dottedName, subquestion, - defaultValue + defaultValue, + raw: rule } } @@ -156,8 +157,6 @@ export let findRuleByNamespace = (allRules, ns) => export let queryRule = rule => query => path(query.split(' . '))(rule) -let isVariant = path(['formule', 'une possibilité']) - export let formatInputs = (flatRules, formValueSelector) => state => name => { // Our situationGate retrieves data from the "conversation" form // The search below is to apply input conversions such as replacing "," with "." diff --git a/source/engine/traverse.js b/source/engine/traverse.js index a7bdd3d0c..f584556fa 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -410,6 +410,7 @@ let treat = (rules, rule) => rawNode => { complément: mecanismComplement, sélection: mecanismSelection, 'une possibilité': always({ + ...v, 'une possibilité': 'oui', missingVariables: {[rule.dottedName]:1} }),