From c40c853db9447ee48c5394076845864f048881c5 Mon Sep 17 00:00:00 2001 From: Suren Date: Wed, 23 Feb 2022 20:58:47 +0530 Subject: [PATCH] #144: Search by commune and libcom (#151) --- js/extension/api/api.js | 5 +++-- .../components/forms/MunicipalityCombo.jsx | 1 - .../components/forms/ProprietaireCombo.jsx | 1 - js/extension/components/forms/RoadCombo.jsx | 1 - js/extension/components/forms/SearchCombo.jsx | 14 ++++++++++---- .../request/searchCombos/ProprietaireComboList.jsx | 1 - js/extension/constants.js | 2 ++ js/extension/selectors/cadastrapp.js | 8 +++++++- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/js/extension/api/api.js b/js/extension/api/api.js index 41384f9..f9b131e 100644 --- a/js/extension/api/api.js +++ b/js/extension/api/api.js @@ -90,11 +90,12 @@ export function getCommune({ libcom, cgocommune }) { } /** - * Search commune by text. Min 3 chars for results + * Search commune by text. + * Min char is obtained from configuration of cadastrapp services * @param {string} text text to search */ export function searchCommune(text) { - return getCommune({libcom: text}); + return getCommune({[isNaN(text) ? "libcom" : "cgocommune"]: text}); } /** diff --git a/js/extension/components/forms/MunicipalityCombo.jsx b/js/extension/components/forms/MunicipalityCombo.jsx index e777959..13d3d69 100644 --- a/js/extension/components/forms/MunicipalityCombo.jsx +++ b/js/extension/components/forms/MunicipalityCombo.jsx @@ -4,7 +4,6 @@ import SearchCombo from './SearchCombo'; export default (props) => { return ( { return ( { return (({ minCharToSearch: minCharToSearchSelector(state) }) +)(({ value = {}, valueField, minLength, @@ -41,13 +45,15 @@ export default ({ additionalStyle = {}, placeholder = "", dropUp = false, + minCharToSearch, ...props }) => { + const _minLength = minLength ?? minCharToSearch; const [text, setText] = useState(""); const [busy, setBusy] = useState(false); const [data, setData] = useState([]); useEffect( () => { - if (text.length >= minLength) { + if (text.length >= _minLength) { setBusy(true); search(text).then(results => { setData(results); @@ -73,7 +79,7 @@ export default ({ } } data={data} - minLength={minLength} + minLength={_minLength} {...props} /> {!hideRemove && (text || value) ? : null} ); -}; +}); diff --git a/js/extension/components/request/searchCombos/ProprietaireComboList.jsx b/js/extension/components/request/searchCombos/ProprietaireComboList.jsx index 6100cfd..5b4aefe 100644 --- a/js/extension/components/request/searchCombos/ProprietaireComboList.jsx +++ b/js/extension/components/request/searchCombos/ProprietaireComboList.jsx @@ -6,7 +6,6 @@ export default ({ commune, section, numero, ...props }) => { return ( diff --git a/js/extension/constants.js b/js/extension/constants.js index f5c2416..1f31002 100644 --- a/js/extension/constants.js +++ b/js/extension/constants.js @@ -69,3 +69,5 @@ export const DEFAULT_POPUP_PROPS = { MINZOOM: '14', TIMETOSHOW: 1000 }; + +export const DEFAULT_MIN_CHAR_TO_SEARCH = 3; diff --git a/js/extension/selectors/cadastrapp.js b/js/extension/selectors/cadastrapp.js index 5721e75..5d67f04 100644 --- a/js/extension/selectors/cadastrapp.js +++ b/js/extension/selectors/cadastrapp.js @@ -1,6 +1,7 @@ import { CADASTRAPP_RASTER_LAYER_ID, - CADASTRAPP_VECTOR_LAYER_ID + CADASTRAPP_VECTOR_LAYER_ID, + DEFAULT_MIN_CHAR_TO_SEARCH } from '../constants'; import { additionalLayersSelector } from '@mapstore/selectors/additionallayers'; import { userGroupSecuritySelector } from '@mapstore/selectors/security'; @@ -268,3 +269,8 @@ export function cadastrappPluginCfgSelector(state) { export function popupPluginCfgSelector(state) { return cadastrappPluginCfgSelector(state)?.popup ?? {}; } + +export function minCharToSearchSelector(state) { + const { minNbCharForSearch } = configurationSelector(state) ?? {}; + return minNbCharForSearch ?? DEFAULT_MIN_CHAR_TO_SEARCH; +}