2018-01-08 15:07:26 +00:00
|
|
|
import {
|
2018-04-10 12:27:25 +00:00
|
|
|
flatten,
|
2018-04-12 13:43:02 +00:00
|
|
|
mergeAll,
|
2018-04-10 12:27:25 +00:00
|
|
|
pluck,
|
2018-01-08 15:07:26 +00:00
|
|
|
groupBy,
|
|
|
|
toPairs,
|
|
|
|
sort,
|
|
|
|
map,
|
|
|
|
length,
|
|
|
|
descend,
|
|
|
|
head,
|
|
|
|
unless,
|
|
|
|
is,
|
|
|
|
prop,
|
|
|
|
path,
|
|
|
|
reject,
|
|
|
|
identity
|
|
|
|
} from 'ramda'
|
2017-07-02 17:12:02 +00:00
|
|
|
|
|
|
|
import Question from 'Components/conversation/Question'
|
|
|
|
import Input from 'Components/conversation/Input'
|
2017-09-19 14:55:23 +00:00
|
|
|
import Select from 'Components/conversation/select/Select'
|
2017-09-24 13:26:07 +00:00
|
|
|
import SelectAtmp from 'Components/conversation/select/SelectTauxRisque'
|
2017-07-02 17:12:02 +00:00
|
|
|
import formValueTypes from 'Components/conversation/formValueTypes'
|
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
import { findRuleByDottedName, disambiguateRuleReference } from './rules'
|
2017-04-28 15:03:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
COLLECTE DES VARIABLES MANQUANTES
|
|
|
|
*********************************
|
|
|
|
on collecte les variables manquantes : celles qui sont nécessaires pour
|
|
|
|
remplir les objectifs de la simulation (calculer des cotisations) mais qui n'ont pas
|
|
|
|
encore été renseignées
|
|
|
|
|
|
|
|
TODO perf : peut-on le faire en même temps que l'on traverse l'AST ?
|
|
|
|
Oui sûrement, cette liste se complète en remontant l'arbre. En fait, on le fait déjà pour nodeValue,
|
|
|
|
et quand nodeValue vaut null, c'est qu'il y a des missingVariables ! Il suffit donc de remplacer les
|
|
|
|
null par un tableau, et d'ailleurs utiliser des fonction d'aide pour mutualiser ces tests.
|
|
|
|
|
|
|
|
missingVariables: {variable: [objectives]}
|
|
|
|
*/
|
2017-07-07 08:35:40 +00:00
|
|
|
|
2018-04-12 13:43:02 +00:00
|
|
|
export let collectMissingVariables = targets => mergeAll(pluck('missingVariables', targets))
|
2017-11-07 18:46:40 +00:00
|
|
|
|
2017-11-28 11:45:06 +00:00
|
|
|
export let getNextSteps = (situationGate, analysis) => {
|
2018-04-12 13:43:02 +00:00
|
|
|
let impact = ([, count]) => count
|
2017-04-28 15:03:34 +00:00
|
|
|
|
2017-11-07 18:46:40 +00:00
|
|
|
let missingVariables = collectMissingVariables(analysis.targets),
|
2018-01-08 15:07:26 +00:00
|
|
|
pairs = toPairs(missingVariables),
|
|
|
|
sortedPairs = sort(descend(impact), pairs)
|
|
|
|
return map(head, sortedPairs)
|
2017-11-04 11:09:58 +00:00
|
|
|
}
|
2017-04-24 18:03:38 +00:00
|
|
|
|
2018-01-08 15:07:26 +00:00
|
|
|
let isVariant = path(['formule', 'une possibilité'])
|
2017-04-24 18:03:38 +00:00
|
|
|
|
2017-09-07 20:22:16 +00:00
|
|
|
let buildVariantTree = (allRules, path) => {
|
2017-04-24 18:03:38 +00:00
|
|
|
let rec = path => {
|
2017-07-01 09:17:54 +00:00
|
|
|
let node = findRuleByDottedName(allRules, path),
|
2017-04-27 18:08:52 +00:00
|
|
|
variant = isVariant(node),
|
2018-01-08 15:07:26 +00:00
|
|
|
variants = variant && unless(is(Array), prop('possibilités'))(variant),
|
|
|
|
shouldBeExpanded = variant && true, //variants.find( v => relevantPaths.find(rp => contains(path + ' . ' + v)(rp) )),
|
2017-04-27 18:08:52 +00:00
|
|
|
canGiveUp = variant && !variant['choix obligatoire']
|
2017-04-24 18:03:38 +00:00
|
|
|
|
|
|
|
return Object.assign(
|
|
|
|
node,
|
2017-11-15 13:46:48 +00:00
|
|
|
shouldBeExpanded
|
|
|
|
? {
|
2018-01-03 15:54:19 +00:00
|
|
|
canGiveUp,
|
|
|
|
children: variants.map(v => rec(path + ' . ' + v))
|
2018-02-06 15:17:58 +00:00
|
|
|
}
|
2017-11-15 13:46:48 +00:00
|
|
|
: null
|
2017-04-24 18:03:38 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return rec(path)
|
|
|
|
}
|
|
|
|
|
2017-11-24 10:04:29 +00:00
|
|
|
let buildPossibleInversion = (rule, flatRules, targetNames) => {
|
2018-01-08 15:07:26 +00:00
|
|
|
let ruleInversions = path(['formule', 'inversion', 'avec'])(rule)
|
2017-11-24 17:45:28 +00:00
|
|
|
if (!ruleInversions) return null
|
2018-01-03 15:54:19 +00:00
|
|
|
let inversionObjects = ruleInversions.map(i =>
|
2017-11-24 10:04:29 +00:00
|
|
|
findRuleByDottedName(
|
|
|
|
flatRules,
|
|
|
|
disambiguateRuleReference(flatRules, rule, i)
|
|
|
|
)
|
|
|
|
),
|
2018-02-26 12:36:08 +00:00
|
|
|
inversions = reject(({ name }) => targetNames.includes(name))(
|
2018-01-03 15:54:19 +00:00
|
|
|
[rule].concat(inversionObjects)
|
|
|
|
)
|
2017-11-24 10:04:29 +00:00
|
|
|
|
2017-11-24 17:45:28 +00:00
|
|
|
return {
|
2018-02-26 12:36:08 +00:00
|
|
|
inversions,
|
2017-12-19 10:44:12 +00:00
|
|
|
question: rule.formule.inversion.question
|
2017-11-24 17:45:28 +00:00
|
|
|
}
|
2017-11-24 10:04:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 15:17:58 +00:00
|
|
|
export let getInputComponent = ({ unfolded }) => (
|
|
|
|
rules,
|
|
|
|
targetNames,
|
|
|
|
inputInversions
|
|
|
|
) => dottedName => {
|
|
|
|
let rule = findRuleByDottedName(rules, dottedName)
|
|
|
|
|
|
|
|
let fieldName =
|
|
|
|
(inputInversions && path(dottedName.split('.'), inputInversions)) ||
|
|
|
|
dottedName,
|
|
|
|
fieldTitle = findRuleByDottedName(rules, fieldName).title
|
|
|
|
|
|
|
|
let commonProps = {
|
|
|
|
unfolded,
|
|
|
|
fieldName,
|
|
|
|
title: rule.title
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVariant(rule))
|
|
|
|
return (
|
|
|
|
<Question
|
|
|
|
{...{
|
|
|
|
...commonProps,
|
|
|
|
choices: buildVariantTree(rules, dottedName)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
if (rule.format == null)
|
|
|
|
return (
|
|
|
|
<Question
|
|
|
|
{...{
|
|
|
|
...commonProps,
|
|
|
|
choices: [
|
|
|
|
{ value: 'non', label: 'Non' },
|
|
|
|
{ value: 'oui', label: 'Oui' }
|
|
|
|
]
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
if (rule.suggestions == 'atmp-2017')
|
|
|
|
return (
|
|
|
|
<SelectAtmp
|
|
|
|
{...{
|
|
|
|
...commonProps,
|
|
|
|
valueType: formValueTypes[rule.format],
|
|
|
|
suggestions: rule.suggestions
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
if (typeof rule.suggestions == 'string')
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
{...{
|
|
|
|
...commonProps,
|
|
|
|
valueType: formValueTypes[rule.format],
|
|
|
|
suggestions: rule.suggestions
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Input
|
|
|
|
{...{
|
|
|
|
...commonProps,
|
|
|
|
valueType: formValueTypes[rule.format],
|
|
|
|
suggestions: rule.suggestions,
|
|
|
|
inversion: buildPossibleInversion(rule, rules, targetNames),
|
|
|
|
fieldTitle,
|
|
|
|
inverted: dottedName !== fieldName
|
|
|
|
}}
|
|
|
|
/>
|
2017-09-07 20:22:16 +00:00
|
|
|
)
|
|
|
|
}
|