Skip to content

Commit

Permalink
Made nested services more generic (#1648)
Browse files Browse the repository at this point in the history
* Made nested services more generic

Now instead of filterTemplate we have the selected item passed to the nested service.
The nested service will use it to generate the new search.

* Fixed test
  • Loading branch information
offtherailz authored Mar 28, 2017
1 parent 3d10eb4 commit 85a95a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
6 changes: 4 additions & 2 deletions web/client/api/searchText.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const WFS = require('./WFS');
const assign = require('object-assign');
const GeoCodeUtils = require('../utils/GeoCodeUtils');
const {generateTemplateString} = require('../utils/TemplateUtils');
/*
const toNominatim = (fc) =>
fc.features && fc.features.map( (f) => ({
Expand All @@ -24,8 +25,9 @@ module.exports = {
require('./Nominatim')
.geocode(searchText, options)
.then( res => GeoCodeUtils.nominatimToGeoJson(res.data)),
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], ...params }) => {
wfs: (searchText, {url, typeName, queriableAttributes, outputFormat="application/json", predicate ="ILIKE", staticFilter="", blacklist = [], item, ...params }) => {
// split into words and remove blacklisted words
const staticFilterParsed = generateTemplateString(staticFilter || "")(item);
let searchWords = searchText.split(" ").filter(w => w).filter( w => blacklist.indexOf(w.toLowerCase()) < 0 );

// if the searchtext is empty use the full searchText
Expand All @@ -39,7 +41,7 @@ module.exports = {
typeName,
outputFormat,
// create a filter like : `(ATTR ilike '%word1%') AND (ATTR ilike '%word2%')`
cql_filter: "(".concat( searchWords.map( (w) => queriableAttributes.map( attr => `${attr} ${predicate} '%${w.replace("'", "''")}%'`).join(" OR ")).join(') AND (')).concat(")") .concat(staticFilter)
cql_filter: "(".concat( searchWords.map( (w) => queriableAttributes.map( attr => `${attr} ${predicate} '%${w.replace("'", "''")}%'`).join(" OR ")).join(') AND (')).concat(")") .concat(staticFilterParsed)
}, params))
.then( response => response.features );
}
Expand Down
43 changes: 23 additions & 20 deletions web/client/epics/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,31 @@ describe('search Epics', () => {

it('searchItemSelected epic with nested services', () => {
let nestedService = {
filterTemplate: "TEST_FILTER_TEMPLATE",
nestedPlaceholder: "TEST_NESTED_PLACEHOLDER"
};
const TEXT = "Dinagat Islands";
let action = selectSearchItem({
"type": "Feature",
"bbox": [125, 10, 126, 11],
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": TEXT
},
"__SERVICE__": {
displayName: "${properties.name}",
type: "wfs",
searchTextTemplate: "${properties.name}",
nestedPlaceholder: "SEARCH NESTED",
then: [nestedService]
}
}, {
const item = {
"type": "Feature",
"bbox": [125, 10, 126, 11],
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": TEXT
},
"__SERVICE__": {
searchTextTemplate: "${properties.name}",
displayName: "${properties.name}",
type: "wfs",
options: {
staticFilter: "${properties.name}"
},
nestedPlaceholder: "SEARCH NESTED",
then: [nestedService]
}
};
let action = selectSearchItem(item, {
size: {
width: 200,
height: 200
Expand All @@ -122,7 +125,7 @@ describe('search Epics', () => {
expect(actions[4].services[0]).toEqual({
...nestedService,
options: {
staticFilter: "TEST_FILTER_TEMPLATE"
item
}
});
expect(actions[4].items).toEqual({
Expand Down
6 changes: 3 additions & 3 deletions web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const searchEpic = action$ =>
*/
const searchItemSelected = action$ =>
action$.ofType(TEXT_SEARCH_ITEM_SELECTED)
.mergeMap(action => {
.switchMap(action => {
const item = action.item;


Expand Down Expand Up @@ -117,8 +117,8 @@ const searchItemSelected = action$ =>
nestedServices.map((nestedService) => ({
...nestedService,
options: {
...nestedService.options,
staticFilter: generateTemplateString(nestedService.filterTemplate || "")(item)
item,
...nestedService.options
}
})), {
text: generateTemplateString(item.__SERVICE__.displayName || "")(item),
Expand Down

0 comments on commit 85a95a5

Please sign in to comment.