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

Issue #9311 - populate search bar on select #9321

Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion web/client/actions/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ describe('Test correctness of the search actions', () => {
expect(retval2.append).toBe(true);
});
it('search item selected', () => {
const retval = selectSearchItem("A", "B", {color: '#ff0000'});
const retval = selectSearchItem("A", "B", "C", {color: '#ff0000'});
expect(retval).toExist();
expect(retval.type).toBe(TEXT_SEARCH_ITEM_SELECTED);
expect(retval.item).toEqual("A");
expect(retval.mapConfig).toBe("B");
expect(retval.service).toBe("C");
expect(retval.resultsStyle).toEqual({color: '#ff0000'});
});
it('search item cancelled', () => {
Expand Down
4 changes: 3 additions & 1 deletion web/client/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ export function textSearch(searchText, {services = null} = {}, maxResults = 15)
* @memberof actions.search
* @param {object} item the selected item
* @param {object} mapConfig the current map configuration (with size, projection...)
* @param {object} service the selected item results generating service (nominatim, wfs, etc.)
* @param {object} resultsStyle style to apply to results geometries
*/
export function selectSearchItem(item, mapConfig, resultsStyle) {
export function selectSearchItem(item, mapConfig, service, resultsStyle) {
ale-cristofori marked this conversation as resolved.
Show resolved Hide resolved
return {
type: TEXT_SEARCH_ITEM_SELECTED,
item,
mapConfig,
service,
resultsStyle
};

Expand Down
6 changes: 3 additions & 3 deletions web/client/components/mapcontrols/search/SearchResultList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default class SearchResultList extends React.Component {
showGFI: () => {}
};

onItemClick = (item) => {
this.props.onItemClick(item, this.props.mapConfig);
onItemClick = (item, service) => {
this.props.onItemClick(item, this.props.mapConfig, service);
};

renderResults = () => {
Expand All @@ -63,7 +63,7 @@ export default class SearchResultList extends React.Component {
displayName={service.displayName}
key={item.osm_id || item.id || "res_" + idx}
item={item}
onItemClick={this.onItemClick}
onItemClick={() => this.onItemClick(item, service)}
tools={[{
id: 'open-gfi',
keyProp: 'open-gfi',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ describe("test the SearchResultList", () => {
var items = [{
osm_id: 1,
display_name: "Name",
boundingbox: [1, 2, 3, 4]
boundingbox: [1, 2, 3, 4],
__SERVICE__: {
type: 'nominatim'
}
}];
const spy = expect.spyOn(testHandlers, 'clickHandler');
const mapConfig = {size: 100, projection: "EPSG:4326"};
Expand All @@ -145,7 +148,7 @@ describe("test the SearchResultList", () => {
let elem1 = TestUtils.findRenderedDOMComponentWithClass(elem[0], "search-result");
ReactDOM.findDOMNode(elem1).click();
expect(spy.calls.length).toEqual(1);
expect(spy).toHaveBeenCalledWith(items[0], mapConfig);
expect(spy).toHaveBeenCalledWith(items[0], mapConfig, items[0].__SERVICE__);
});

it('test showGFI button is enabled when openFeatureInfoButton=true', () => {
Expand Down
35 changes: 35 additions & 0 deletions web/client/reducers/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TEXT_SEARCH_CANCEL_ITEM,
UPDATE_RESULTS_STYLE,
resetSearch,
selectSearchItem,
changeFormat,
changeCoord,
changeActiveSearchTool,
Expand Down Expand Up @@ -178,6 +179,40 @@ describe('Test the search reducer', () => {
state = search({}, resetSearch());
expect(state).toEqual({style: {}});
});
it('TEXT_SEARCH_ITEM_SELECTED - wfs service', () => {
let service = {
type: 'wfs',
displayName: '${properties.DISPLAY_NAME}'
};
let item = {
properties: {
DISPLAY_NAME: 'Display Name'
}
};
const state = search({}, selectSearchItem(item, {}, service, {}));
expect(state.searchText).toBe('Display Name');
});
it('TEXT_SEARCH_ITEM_SELECTED - Nominatim service', () => {
let service = {
type: 'nominatim'
};
let item = {
properties: {
display_name: 'Display Name'
}
};
const state = search({}, selectSearchItem(item, {}, service, {}));
expect(state.searchText).toBe('Display Name');
});
it('TEXT_SEARCH_ITEM_SELECTED - undefined service', () => {
let item = {
properties: {
display_name: 'Display Name'
}
};
const state = search({ searchText: 'Displ' }, selectSearchItem(item, {}, undefined, {}));
expect(state.searchText).toBe('Displ');
});
it('RESET_CONTROLS', () => {

const state = search({style: {
Expand Down
8 changes: 8 additions & 0 deletions web/client/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {
TEXT_SEARCH_ITEM_SELECTED,
TEXT_SEARCH_RESULTS_LOADED,
TEXT_SEARCH_RESULTS_PURGE,
TEXT_SEARCH_RESET,
Expand All @@ -25,6 +26,7 @@ import {
} from '../actions/search';

import { RESET_CONTROLS } from '../actions/controls';
import { generateTemplateString } from '../utils/TemplateUtils';
import assign from 'object-assign';
/**
* Manages the state of the map search with it's results
Expand Down Expand Up @@ -88,6 +90,12 @@ import assign from 'object-assign';
*/
function search(state = null, action) {
switch (action.type) {
case TEXT_SEARCH_ITEM_SELECTED: {
const { type: serviceType } = action.service || {};
const displayName = serviceType === 'nominatim' ? action.item.properties?.display_name : serviceType === 'wfs' ?
generateTemplateString(action.service?.displayName || '')(action.item) : state.searchText;
return {...state, searchText: displayName || state.searchText || '' };
}
case TEXT_SEARCH_LOADING: {
return assign({}, state, {loading: action.loading});
}
Expand Down
Loading