Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#123 Always show owner selection when ambiguous #127

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions js/extension/components/search/OwnersSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}} />
</div>
);
Expand Down
16 changes: 11 additions & 5 deletions js/extension/epics/search.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]/;
Expand Down Expand Up @@ -202,11 +202,17 @@ 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 })
: getCoProprietaireList({ ddenom: proprietaire, cgocommune, comptecommunal, details: 1})
? getProprietaire({ ddenom, birthsearch, cgocommune, details: 2 })
: getCoProprietaireList({ ddenom, cgocommune, comptecommunal, details: 1})
)
.switchMap( owners => Rx.Observable.of(showOwners(owners)))
.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')));
});
}