{showValues =>
!showValues ? (
Active seulement si {makeJsx(explanation)}
) : nodeValue === true ? (
Active car {makeJsx(explanation)}
) : nodeValue === false ? (
Non active car {makeJsx(explanation)}
) : null
}
)
return {
evaluate: (cache, situation, parsedRules) =>
node.evaluate(cache, situation, parsedRules, node),
jsx,
category: 'ruleProp',
rulePropType: 'cond',
name: 'parentDependency',
type: 'numeric',
explanation: node
}
},
'non applicable si': evolveCond('non applicable si', rule, rules),
'applicable si': evolveCond('applicable si', rule, rules),
// formule de calcul
formule: value => {
let evaluate = (cache, situationGate, parsedRules, node) => {
let explanation = evaluateNode(
cache,
situationGate,
parsedRules,
node.explanation
),
nodeValue = explanation.nodeValue,
missingVariables = explanation.missingVariables
return rewriteNode(node, nodeValue, explanation, missingVariables)
}
let child = treat(rules, rule)(value)
let jsx = (nodeValue, explanation) => makeJsx(explanation)
return {
evaluate,
jsx,
category: 'ruleProp',
rulePropType: 'formula',
name: 'formule',
type: 'numeric',
explanation: child
}
}
})(root)
let controls =
rule['contrôles'] &&
rule['contrôles'].map(control => {
let testExpression = treatString(rules, rule)(control.si)
if (!testExpression.explanation)
throw new Error(
'Ce contrôle ne semble pas être compris :' + control['si']
)
let otherVariables = testExpression.explanation.filter(
node =>
node.category === 'variable' && node.dottedName !== rule.dottedName
)
let isInputControl = !otherVariables.length,
level = control['niveau']
if (level === 'bloquant' && !isInputControl) {
throw new Error(
`Un contrôle ne peut être bloquant et invoquer des calculs de variables :
${control['si']}
${level}
`
)
}
return {
dottedName: rule.dottedName,
level: control['niveau'],
test: control['si'],
message: control['message'],
testExpression,
solution: control['solution'],
isInputControl
}
})
return {
// Pas de propriété explanation et jsx ici car on est parti du (mauvais) principe que 'non applicable si' et 'formule' sont particuliers, alors qu'ils pourraient être rangé avec les autres mécanismes
...parsedRoot,
evaluate,
parsed: true,
controls
}
}
let evolveCond = (name, rule, rules) => value => {
let evaluate = (cache, situationGate, parsedRules, node) => {
let explanation = evaluateNode(
cache,
situationGate,
parsedRules,
node.explanation
),
nodeValue = explanation.nodeValue,
missingVariables = explanation.missingVariables
return rewriteNode(node, nodeValue, explanation, missingVariables)
}
let child = treat(rules, rule)(value)
let jsx = (nodeValue, explanation) => (