Correction de l'inversion quand la donnée n'est pas renseignée
parent
6a3a8ebff3
commit
f101096dff
|
@ -134,7 +134,6 @@ export var FormDecorator = formType => RenderField =>
|
|||
|
||||
renderTitleAndAnswer(valueType, human) {
|
||||
let {
|
||||
name,
|
||||
stepAction,
|
||||
answer,
|
||||
themeColours,
|
||||
|
@ -149,7 +148,7 @@ export var FormDecorator = formType => RenderField =>
|
|||
</span>
|
||||
<button
|
||||
className="edit"
|
||||
onClick={() => stepAction('unfold', name)}
|
||||
onClick={() => stepAction('unfold', this.state.fieldName)}
|
||||
style={{ color: themeColours.textColourOnWhite }}
|
||||
>
|
||||
<i className="fa fa-pencil-square-o" aria-hidden="true" />
|
||||
|
|
|
@ -78,14 +78,19 @@ export default class Input extends Component {
|
|||
</span>
|
||||
)
|
||||
}
|
||||
componentDidMount() {
|
||||
let { stepProps: { inversions } } = this.props
|
||||
if (inversions)
|
||||
this.inverse(inversions[0].dottedName)
|
||||
}
|
||||
renderInversions() {
|
||||
let { stepProps: { name: inputName, inversions } } = this.props
|
||||
let { stepProps: { inversions } } = this.props
|
||||
if (!inversions) return null
|
||||
|
||||
return (
|
||||
<select
|
||||
value={inputName}
|
||||
onChange={e => this.inverse(e.target.value)}
|
||||
value={inversions[0].dottedName}
|
||||
onMouseDown={e => this.inverse(e.target.value)}
|
||||
>
|
||||
{inversions.map(({ name, title, dottedName }) => (
|
||||
<option key={dottedName} value={dottedName}>
|
||||
|
|
|
@ -48,7 +48,6 @@ export let nextSteps = (situationGate, flatRules, analysis) => {
|
|||
let missingVariables = collectMissingVariables(analysis.targets),
|
||||
pairs = R.toPairs(missingVariables),
|
||||
sortedPairs = R.sort(R.descend(impact), pairs)
|
||||
|
||||
return R.map(R.head, sortedPairs)
|
||||
}
|
||||
|
||||
|
|
|
@ -418,7 +418,8 @@ export let findInversion = (situationGate, rules, rule) => {
|
|||
let fixedObjective = inversions
|
||||
.map(i => disambiguateRuleReference(rules, rule, i))
|
||||
.find(name => situationGate(name) != undefined)
|
||||
if (fixedObjective == null) return null
|
||||
|
||||
if (fixedObjective == null) return {inversionChoiceNeeded: true}
|
||||
//par exemple, fixedObjective = 'salaire net', et v('salaire net') == 2000
|
||||
return {
|
||||
fixedObjective,
|
||||
|
@ -430,6 +431,10 @@ export let findInversion = (situationGate, rules, rule) => {
|
|||
let doInversion = (situationGate, parsedRules, r) => {
|
||||
let inversion = findInversion(situationGate, parsedRules, r)
|
||||
if (!inversion) return null
|
||||
if (inversion.inversionChoiceNeeded) return {
|
||||
inversionMissingVariables: [r.dottedName],
|
||||
nodeValue: null
|
||||
}
|
||||
let { fixedObjectiveValue, fixedObjectiveRule } = inversion
|
||||
let fx = x =>
|
||||
clearDict() && evaluateNode(
|
||||
|
|
|
@ -50,6 +50,36 @@ describe("inversions", () => {
|
|||
expect(analysis.targets[0].nodeValue).to.be.closeTo(2000 / (77 / 100), 0.0001 * 2000)
|
||||
})
|
||||
|
||||
it("should ask the input of one of the possible inversions", () => {
|
||||
let rawRules = dedent`
|
||||
- nom: net
|
||||
formule:
|
||||
multiplication:
|
||||
assiette: assiette
|
||||
variations:
|
||||
- si: cadre
|
||||
taux: 80%
|
||||
- si: ≠ cadre
|
||||
taux: 70%
|
||||
|
||||
- nom: brut
|
||||
format: euro
|
||||
inversions possibles:
|
||||
- net
|
||||
- nom: cadre
|
||||
- nom: assiette
|
||||
formule: 67 + brut
|
||||
|
||||
`,
|
||||
rules = yaml.safeLoad(rawRules).map(enrichRule),
|
||||
stateSelector = name => null,
|
||||
analysis = analyse(rules, "brut")(stateSelector),
|
||||
missing = collectMissingVariables(analysis.targets)
|
||||
|
||||
expect(analysis.targets[0].nodeValue).to.be.null
|
||||
expect(missing).to.have.key("brut")
|
||||
})
|
||||
|
||||
it("should handle inversions with missing variables", () => {
|
||||
let rawRules = dedent`
|
||||
- nom: net
|
||||
|
|
Loading…
Reference in New Issue