🐛 Mécanisme de synchronisation + ou - fonctionnel
parent
abe3bcf101
commit
94e7615360
|
@ -8,7 +8,9 @@ import './Select.css'
|
|||
let getOptions = input =>
|
||||
input.length < 3
|
||||
? Promise.resolve({ options: [] })
|
||||
: fetch(`https://geo.api.gouv.fr/communes?nom=${input}`)
|
||||
: fetch(
|
||||
`https://geo.api.gouv.fr/communes?nom=${input}&fields=nom,code,departement,region&`
|
||||
)
|
||||
.then(response => {
|
||||
if (!response.ok)
|
||||
return [{ nom: 'Aucune commune trouvée', disabled: true }]
|
||||
|
@ -31,7 +33,8 @@ export default class Select extends Component {
|
|||
submit
|
||||
} = this.props,
|
||||
submitOnChange = option => {
|
||||
onChange(option)
|
||||
// serialize to not mix our data schema and the API response's
|
||||
onChange(JSON.stringify(option))
|
||||
submit()
|
||||
}
|
||||
|
||||
|
@ -40,8 +43,8 @@ export default class Select extends Component {
|
|||
<ReactSelect.Async
|
||||
onChange={submitOnChange}
|
||||
labelKey="nom"
|
||||
optionRenderer={({ nom, codeDepartement }) =>
|
||||
nom + ` (${codeDepartement})`
|
||||
optionRenderer={({ nom, departement }) =>
|
||||
nom + ` (${departement.nom})`
|
||||
}
|
||||
placeholder="Entrez le nom de commune"
|
||||
noResultsText="Nous n'avons trouvé aucune commune"
|
|
@ -22,7 +22,7 @@ import {
|
|||
import React from 'react'
|
||||
import Question from 'Components/conversation/Question'
|
||||
import Input from 'Components/conversation/Input'
|
||||
import Select from 'Components/conversation/select/Select'
|
||||
import SelectGéo from 'Components/conversation/select/SelectGéo'
|
||||
import SelectAtmp from 'Components/conversation/select/SelectTauxRisque'
|
||||
import formValueTypes from 'Components/conversation/formValueTypes'
|
||||
|
||||
|
@ -116,6 +116,9 @@ export let getInputComponent = rules => dottedName => {
|
|||
}}
|
||||
/>
|
||||
)
|
||||
if (rule.API && rule.API === 'géo')
|
||||
return <SelectGéo {...{ ...commonProps }} />
|
||||
if (rule.API) throw new Error("Le seul API implémenté est l'API géo")
|
||||
|
||||
if (rule.format == null)
|
||||
return (
|
||||
|
@ -141,10 +144,6 @@ export let getInputComponent = rules => dottedName => {
|
|||
/>
|
||||
)
|
||||
|
||||
if (rule.api && rule.api == 'géo') return <Select {...{ commonProps }} />
|
||||
|
||||
if (rule.api) throw new Error("Le seul API implémenté est l'API géo")
|
||||
|
||||
// Now the numeric input case
|
||||
|
||||
return (
|
||||
|
|
|
@ -974,11 +974,13 @@ export let mecanismSynchronisation = (recurse, k, v) => {
|
|||
parsedRules,
|
||||
node.explanation.API
|
||||
)
|
||||
|
||||
let nodeValue =
|
||||
val(APIExplanation) == null
|
||||
? null
|
||||
: path(v.chemin.split(' . '))(val(APIExplanation))
|
||||
let missingVariables = APIExplanation.nodeValue === null ? [v.API] : []
|
||||
: path(v.chemin.split(' . '))(JSON.parse(val(APIExplanation)))
|
||||
let missingVariables =
|
||||
val(APIExplanation) === null ? { [APIExplanation.dottedName]: 1 } : {}
|
||||
let explanation = { ...v, API: APIExplanation }
|
||||
return rewriteNode(node, nodeValue, explanation, missingVariables)
|
||||
}
|
||||
|
@ -986,7 +988,7 @@ export let mecanismSynchronisation = (recurse, k, v) => {
|
|||
return {
|
||||
explanation: { ...v, API: recurse(v.API) },
|
||||
evaluate,
|
||||
jsx: () => <span>API</span>,
|
||||
jsx: (nodeValue, explanation) => <span>{nodeValue}</span>,
|
||||
category: 'mecanism',
|
||||
name: 'synchronisation'
|
||||
}
|
||||
|
|
|
@ -86,8 +86,15 @@ export let hasKnownRuleType = rule => rule && enrichRule(rule).type
|
|||
export let splitName = split(' . '),
|
||||
joinName = join(' . ')
|
||||
|
||||
export let parentName = pipe(splitName, dropLast(1), joinName)
|
||||
export let nameLeaf = pipe(splitName, last)
|
||||
export let parentName = pipe(
|
||||
splitName,
|
||||
dropLast(1),
|
||||
joinName
|
||||
)
|
||||
export let nameLeaf = pipe(
|
||||
splitName,
|
||||
last
|
||||
)
|
||||
|
||||
export let encodeRuleName = name =>
|
||||
name.replace(/\s\.\s/g, '--').replace(/\s/g, '-')
|
||||
|
|
Loading…
Reference in New Issue