From 6d244bc35e870f1ba531d7244f30ec1039b9fde5 Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Sat, 4 Nov 2017 12:09:58 +0100 Subject: [PATCH] :gear: Simplifier buildNextSteps --- .../components/conversation/FormDecorator.js | 3 +- source/engine/generateQuestions.js | 29 ++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/source/components/conversation/FormDecorator.js b/source/components/conversation/FormDecorator.js index e7521642b..0c0d2cdcd 100644 --- a/source/components/conversation/FormDecorator.js +++ b/source/components/conversation/FormDecorator.js @@ -48,8 +48,7 @@ export var FormDecorator = formType => RenderField => human, helpText, suggestions, - subquestion, - objectives, + subquestion } = this.props.step this.step = this.props.step diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index dff37cf84..358389531 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -78,16 +78,19 @@ export let collectMissingVariables = (groupMethod='groupByMissingVariable') => ( } export let buildNextSteps = (situationGate, flatRules, analysedSituation) => { - let missingVariables = collectMissingVariables('groupByMissingVariable')(situationGate, analysedSituation), - asPairs = R.toPairs(missingVariables) - - let generate = R.map(R.curry(generateQuestion)(flatRules)), - sort = R.sort((a,b) => b.impact - a.impact) - - return R.pipe(generate,sort)(asPairs) + let missing = nextSteps(situationGate, flatRules, analysedSituation) + return R.map(makeQuestion(flatRules), missing) } +export let nextSteps = (situationGate, flatRules, analysedSituation) => { + let impact = ([variable, objectives]) => R.length(objectives) + let missingVariables = collectMissingVariables('groupByMissingVariable')(situationGate, analysedSituation), + pairs = R.toPairs(missingVariables), + sortedPairs = R.sort((a,b) => impact(b) - impact(a), pairs) + + return R.map(R.head, sortedPairs) +} export let constructStepMeta = ({ titre, @@ -134,14 +137,8 @@ let buildVariantTree = (allRules, path) => { return rec(path) } -export let generateQuestion = flatRules => ([dottedName, objectives]) => { - let rule = findRuleByDottedName(flatRules, dottedName), - guidance = { - objectives, - impact: objectives.length - } - - // console.log(isVariant(rule)?"variant":"generateQuestion",[dottedName, objectives.length]) +export let makeQuestion = flatRules => dottedName => { + let rule = findRuleByDottedName(flatRules, dottedName) let inputQuestion = rule => ({ component: Input, @@ -185,7 +182,5 @@ export let generateQuestion = flatRules => ([dottedName, objectives]) => { typeof rule.suggestions == 'string' ? (rule.suggestions == 'atmp-2017' ? selectAtmp(rule) : selectQuestion(rule)) : inputQuestion(rule) - , - guidance ) }