From 8bd85834af588f2410f27a68bbce24680271ed8d Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Fri, 4 Jun 2021 15:59:59 +0200 Subject: [PATCH 1/2] #123 Always show owner selection when ambiguous --- js/extension/components/search/OwnersSearch.jsx | 8 +------- js/extension/epics/search.js | 9 +++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/js/extension/components/search/OwnersSearch.jsx b/js/extension/components/search/OwnersSearch.jsx index c49b9c7..5561c09 100644 --- a/js/extension/components/search/OwnersSearch.jsx +++ b/js/extension/components/search/OwnersSearch.jsx @@ -47,13 +47,7 @@ export default function OwnersSearch({ loading, onSearch = () => { }, onOwnersSe valid={isSearchValid(currentTab, searchState[currentTab])} onClear={() => resetFormState(currentTab)} onSearch={() => { - // text search opens the owners tab - if (currentTab === SEARCH_TYPES.USER && isString(searchState[SEARCH_TYPES.USER]?.proprietaire)) { - onOwnersSearch(SEARCH_TYPES.USER, searchState[currentTab]); - } else { - // plot search - onSearch(currentTab, searchState[currentTab]); - } + onOwnersSearch(SEARCH_TYPES.USER, searchState[currentTab]); }} /> ); diff --git a/js/extension/epics/search.js b/js/extension/epics/search.js index f840c9b..38f2d66 100644 --- a/js/extension/epics/search.js +++ b/js/extension/epics/search.js @@ -1,6 +1,6 @@ import Rx from 'rxjs'; import uuid from 'uuid'; -import {head, trim} from 'lodash'; +import {head, trim, isString} from 'lodash'; import { SEARCH_TYPES } from '../constants'; import { getCadastrappLayer, cadastreLayerIdParcelle } from '../selectors/cadastrapp'; import { getLayerJSONFeature } from '@mapstore/observables/wfs'; @@ -10,7 +10,7 @@ import { error } from '@mapstore/actions/notifications'; import { getCoProprietaireList, getParcelle, getParcelleByCompteCommunal, getProprietaire } from '../api/api'; import { workaroundDuplicatedParcelle } from '../utils/workarounds'; -import { SEARCH, addPlots, OWNERS_SEARCH, showOwners, loading } from '../actions/cadastrapp'; +import { SEARCH, addPlots, OWNERS_SEARCH, showOwners, loading, search } from '../actions/cadastrapp'; import { isValidParcelle } from '../utils/validation'; const DELIMITER_REGEX = /[\s\;\,\n]/; @@ -202,11 +202,12 @@ export function cadastrappOwnersSearch(action$) { const { commune, proprietaire, birthsearch, comptecommunal } = rawParams; // proprietaire in this case is a string // ddenom birthsearch=true const { cgocommune } = commune; + const ddenom = isString(proprietaire) ? proprietaire : proprietaire?.value; return Rx.Observable.defer(() => searchType === SEARCH_TYPES.USER - ? getProprietaire({ ddenom: proprietaire, birthsearch, cgocommune, details: 2 }) + ? getProprietaire({ ddenom, birthsearch, cgocommune, details: 2 }) : getCoProprietaireList({ ddenom: proprietaire, cgocommune, comptecommunal, details: 1}) ) - .switchMap( owners => Rx.Observable.of(showOwners(owners))) + .switchMap( owners => Rx.Observable.of(owners.length > 1 ? showOwners(owners) : search(searchType, rawParams))) .let(wrapStartStop(loading(true, 'search'), loading(false, 'search'))); }); } From afc33eae2385ed52ebce393691a131acda09e5e9 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Fri, 4 Jun 2021 16:28:05 +0200 Subject: [PATCH 2/2] Add documentation and more checks --- js/extension/epics/search.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/extension/epics/search.js b/js/extension/epics/search.js index 38f2d66..0eb2ffc 100644 --- a/js/extension/epics/search.js +++ b/js/extension/epics/search.js @@ -205,9 +205,14 @@ export function cadastrappOwnersSearch(action$) { const ddenom = isString(proprietaire) ? proprietaire : proprietaire?.value; return Rx.Observable.defer(() => searchType === SEARCH_TYPES.USER ? getProprietaire({ ddenom, birthsearch, cgocommune, details: 2 }) - : getCoProprietaireList({ ddenom: proprietaire, cgocommune, comptecommunal, details: 1}) + : getCoProprietaireList({ ddenom, cgocommune, comptecommunal, details: 1}) ) - .switchMap( owners => Rx.Observable.of(owners.length > 1 ? showOwners(owners) : search(searchType, rawParams))) + .switchMap( owners => Rx.Observable.of( + // if proprietaire was an object, a selection of the user occurred. So if owner is one, can perform search. + // Otherwise, always show the list of users to avoid ambiguity or to do textual search. + owners.length > 1 || isString(proprietaire) + ? showOwners(owners) + : search(searchType, rawParams))) .let(wrapStartStop(loading(true, 'search'), loading(false, 'search'))); }); }