Merge pull request #6677 from tchak/fix-commune-select

fix(commune): do not display foreign departement when selecting commune
This commit is contained in:
Paul Chavard 2021-11-25 14:35:43 +03:00 committed by GitHub
commit f86e202738
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -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);

View file

@ -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 (
<ComboSearch
{...params}
scope="departements"
minimumInputLength={1}
transformResult={({ code, nom }) => [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;