From 94e7615360ea8e47c5cf5491eb9899f9d82db6a4 Mon Sep 17 00:00:00 2001 From: Mael Date: Thu, 6 Sep 2018 18:33:12 +0200 Subject: [PATCH] =?UTF-8?q?:bug:=20M=C3=A9canisme=20de=20synchronisation?= =?UTF-8?q?=20+=20ou=20-=20fonctionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conversation/select/{Select.js => SelectGéo.js} | 11 +++++++---- source/engine/generateQuestions.js | 9 ++++----- source/engine/mecanisms.js | 8 +++++--- source/engine/rules.js | 11 +++++++++-- 4 files changed, 25 insertions(+), 14 deletions(-) rename source/components/conversation/select/{Select.js => SelectGéo.js} (80%) diff --git a/source/components/conversation/select/Select.js b/source/components/conversation/select/SelectGéo.js similarity index 80% rename from source/components/conversation/select/Select.js rename to source/components/conversation/select/SelectGéo.js index 82807388d..ab8336113 100644 --- a/source/components/conversation/select/Select.js +++ b/source/components/conversation/select/SelectGéo.js @@ -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 { - nom + ` (${codeDepartement})` + optionRenderer={({ nom, departement }) => + nom + ` (${departement.nom})` } placeholder="Entrez le nom de commune" noResultsText="Nous n'avons trouvé aucune commune" diff --git a/source/engine/generateQuestions.js b/source/engine/generateQuestions.js index e1b72b21a..30eceb254 100644 --- a/source/engine/generateQuestions.js +++ b/source/engine/generateQuestions.js @@ -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 + 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