From 7d189575afebeb1e6d1b5f96a7ceafa5b318231a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Nov 2021 13:28:40 +0300 Subject: [PATCH] fix(commune): do not display foreign departement when selecting commune --- app/javascript/components/ComboCommunesSearch.jsx | 1 + .../components/ComboDepartementsSearch.jsx | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/javascript/components/ComboCommunesSearch.jsx b/app/javascript/components/ComboCommunesSearch.jsx index fa9aca1ab..16a2815fe 100644 --- a/app/javascript/components/ComboCommunesSearch.jsx +++ b/app/javascript/components/ComboCommunesSearch.jsx @@ -91,6 +91,7 @@ function ComboCommunesSearch(params) { inputId={!departementCode ? inputId : null} aria-describedby={departementDescribedBy} placeholder={placeholderDepartement} + addForeignDepartement={false} required={params.mandatory} onChange={(value, result) => { setDepartementCode(result?.code); diff --git a/app/javascript/components/ComboDepartementsSearch.jsx b/app/javascript/components/ComboDepartementsSearch.jsx index 745a29803..3f4c3350a 100644 --- a/app/javascript/components/ComboDepartementsSearch.jsx +++ b/app/javascript/components/ComboDepartementsSearch.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { QueryClientProvider } from 'react-query'; import { matchSorter } from 'match-sorter'; @@ -16,14 +17,19 @@ function expandResultsWithForeignDepartement(term, results) { ]; } -export function ComboDepartementsSearch(params) { +export function ComboDepartementsSearch({ + addForeignDepartement = true, + ...params +}) { return ( [code, `${code} - ${nom}`]} - transformResults={expandResultsWithForeignDepartement} + transformResults={ + addForeignDepartement ? expandResultsWithForeignDepartement : undefined + } /> ); } @@ -39,4 +45,9 @@ function ComboDepartementsSearchDefault(params) { ); } +ComboDepartementsSearch.propTypes = { + ...ComboSearch.propTypes, + addForeignDepartement: PropTypes.bool +}; + export default ComboDepartementsSearchDefault;