Skip to content

Commit

Permalink
#144: Search by commune and libcom (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 authored Feb 23, 2022
1 parent 346f850 commit c40c853
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
5 changes: 3 additions & 2 deletions js/extension/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}

/**
Expand Down
1 change: 0 additions & 1 deletion js/extension/components/forms/MunicipalityCombo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SearchCombo from './SearchCombo';

export default (props) => {
return (<SearchCombo
minLength={3}
valueField="cgocommune"
textField="label"
search={
Expand Down
1 change: 0 additions & 1 deletion js/extension/components/forms/ProprietaireCombo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SearchCombo from './SearchCombo';

export default ({ cgocommune, birthsearch = false, onSelect, ...props}) => {
return (<SearchCombo
minLength={3}
valueField="value"
textField="label"
onSelect={onSelect}
Expand Down
1 change: 0 additions & 1 deletion js/extension/components/forms/RoadCombo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SearchCombo from './SearchCombo';

export default ({cgocommune, ...props}) => {
return (<SearchCombo
minLength={3}
valueField="dvoilib"
textField="label"
search={
Expand Down
14 changes: 10 additions & 4 deletions js/extension/components/forms/SearchCombo.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, {useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { find, isObject } from 'lodash';
import { Combobox as CB } from 'react-widgets';
import { Glyphicon } from "react-bootstrap";
import localizedProps from '@mapstore/components/misc/enhancers/localizedProps';
import { getMessageById } from '../../../../MapStore2/web/client/utils/LocaleUtils';
import {compose, getContext, mapProps} from 'recompose';
import { minCharToSearchSelector } from "@js/extension/selectors/cadastrapp";


const localizeMessages = compose(
Expand All @@ -29,7 +31,9 @@ const Combobox = localizedProps('placeholder')(localizeMessages(CB));
* A utility combo for search.
* @params search
*/
export default ({
export default connect(
state=>({ minCharToSearch: minCharToSearchSelector(state) })
)(({
value = {},
valueField,
minLength,
Expand All @@ -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);
Expand All @@ -73,7 +79,7 @@ export default ({
}
}
data={data}
minLength={minLength}
minLength={_minLength}
{...props}
/>
{!hideRemove && (text || value) ? <Glyphicon glyph="remove"
Expand All @@ -92,4 +98,4 @@ export default ({
onSelect(undefined);
}}/> : null}
</div>);
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default ({ commune, section, numero, ...props }) => {
return (
<SearchCombo
dropUp
minLength={3}
valueField="proprietaire"
textField="label"
search={ddenom =>
Expand Down
2 changes: 2 additions & 0 deletions js/extension/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ export const DEFAULT_POPUP_PROPS = {
MINZOOM: '14',
TIMETOSHOW: 1000
};

export const DEFAULT_MIN_CHAR_TO_SEARCH = 3;
8 changes: 7 additions & 1 deletion js/extension/selectors/cadastrapp.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}

0 comments on commit c40c853

Please sign in to comment.