Simplification gen qestions (2)

pull/206/head
mama 2018-02-06 17:02:13 +01:00 committed by Laurent Bossavit
parent c5379ca697
commit ebd159081e
5 changed files with 36 additions and 32 deletions

View File

@ -15,7 +15,7 @@ import {
import './conversation/conversation.css'
import './Simulateur.css'
import Conversation from './conversation/Conversation'
import { makeQuestion } from 'Engine/generateQuestions'
import { getInputComponent } from 'Engine/generateQuestions'
import ReactPiwik from './Tracker'
@ -80,10 +80,10 @@ export default class extends Component {
flatRules,
foldedSteps,
currentQuestion,
situationGate,
themeColours,
inputInversions,
done
done,
parsedRules
} = this.props,
reinitalise = () => {
ReactPiwik.push(['trackEvent', 'restart', ''])
@ -109,14 +109,14 @@ export default class extends Component {
reinitalise,
currentQuestion:
currentQuestion &&
this.buildStep({ unfolded: true, flatRules })(
situationGate,
getInputComponent({ unfolded: true })(
flatRules,
this.targetNames,
inputInversions
)(currentQuestion),
foldedSteps: map(
this.buildStep({ unfolded: false, flatRules })(
situationGate,
getInputComponent({ unfolded: false })(
flatRules,
this.targetNames,
inputInversions
),

View File

@ -46,10 +46,7 @@ export var FormDecorator = formType => RenderField =>
return (
<div className={classNames({ step: unfolded }, formType)}>
<div
style={{
visibility: this.state.helpVisible ? 'hidden' : 'visible'
}}>
<div>
{/* Une étape déjà répondue est marquée 'folded'. Dans ce dernier cas, un résumé
de la réponse est affiché */}
{unfolded ? this.renderUnfolded() : this.renderFolded()}
@ -68,7 +65,6 @@ export var FormDecorator = formType => RenderField =>
valueType,
fieldName,
inversion,
inverted,
themeColours
} = this.props,
{ i18n } = this.context

View File

@ -16,14 +16,18 @@ import {
reject,
identity
} from 'ramda'
import React from 'react'
import Question from 'Components/conversation/Question'
import Input from 'Components/conversation/Input'
import Select from 'Components/conversation/select/Select'
import SelectAtmp from 'Components/conversation/select/SelectTauxRisque'
import formValueTypes from 'Components/conversation/formValueTypes'
import { findRuleByDottedName, disambiguateRuleReference } from './rules'
import {
findRuleByDottedName,
disambiguateRuleReference,
queryRule
} from './rules'
/*
COLLECTE DES VARIABLES MANQUANTES
@ -74,14 +78,13 @@ let buildVariantTree = (allRules, path) => {
return rec(path)
}
let buildPossibleInversion = (rule, flatRules, targetNames) => {
let ruleInversions = path(['formule', 'inversion', 'avec'])(rule)
if (!ruleInversions) return null
let inversionObjects = ruleInversions.map(i =>
findRuleByDottedName(
flatRules,
disambiguateRuleReference(flatRules, rule, i)
)
let buildPossibleInversion = (rule, rules, targetNames) => {
let query = queryRule(rule),
invertible = query('formule . inversion')
if (!invertible) return null
let inversionObjects = query('inversion . avec').map(i =>
findRuleByDottedName(rules, disambiguateRuleReference(rules, rule, i))
),
inversions = reject(({ name }) => targetNames.includes(name))(
[rule].concat(inversionObjects)
@ -89,7 +92,7 @@ let buildPossibleInversion = (rule, flatRules, targetNames) => {
return {
inversions,
question: rule.formule.inversion.question
question: query('formule . inversion . question')
}
}
@ -100,15 +103,11 @@ export let getInputComponent = ({ unfolded }) => (
) => 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
fieldName: dottedName,
title: rule.title,
question: rule.question
}
if (isVariant(rule))
@ -156,14 +155,20 @@ export let getInputComponent = ({ unfolded }) => (
/>
)
let fieldName =
(inputInversions && path(dottedName.split('.'), inputInversions)) ||
commonProps.fieldName,
inversion = buildPossibleInversion(rule, rules, targetNames)
return (
<Input
{...{
...commonProps,
valueType: formValueTypes[rule.format],
suggestions: rule.suggestions,
inversion: buildPossibleInversion(rule, rules, targetNames),
fieldTitle,
inversion,
fieldTitle: findRuleByDottedName(rules, fieldName).title,
fieldName,
inverted: dottedName !== fieldName
}}
/>

View File

@ -491,6 +491,7 @@ export let mecanismInversion = dottedName => (recurse, k, v) => {
}
return {
...v,
evaluate,
jsx: nodeValue => (
<Node

View File

@ -154,6 +154,8 @@ export let findRuleByNamespace = (allRules, ns) =>
/*********************************
Autres */
export let queryRule = rule => query => path(query.split(' . '))(rule)
let isVariant = path(['formule', 'une possibilité'])
export let formatInputs = (flatRules, formValueSelector) => state => name => {