Extend search algorith to include AND between columns and sort at EnhacedTable component

This commit is contained in:
Letícia Camara 2019-01-16 01:52:35 -02:00
parent 26357612eb
commit 7a17666e76
3 changed files with 21 additions and 8 deletions

View file

@ -219,18 +219,27 @@ class EnhancedTable extends Component {
// Logic of search query and columns
if(searchQuery.length > 0) {
data = data.filter((item) => {
let insert = false;
// Remove white spaces and wrong "" split
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
data = data.filter((item) => {
const insertArray = [];
// Implement hardcoded AND query over each column
// Iterate over each search term
queryTerms.forEach(searchItem => {
let insert = false;
// Iterate over the search column select boxes
searchColumns.map(column => {
try {
if( column.checked && (item[column.name] !== undefined) ) {
if(item[column.name].hasOwnProperty('searchText') && item[column.name].searchText.toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
if(item[column.name].hasOwnProperty('searchText') &&
item[column.name].searchText.toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1
){
insert = true;
}
else if(item[column.name].toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
else if(item[column.name].toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1){
insert = true;
}
}
@ -241,7 +250,11 @@ class EnhancedTable extends Component {
return column;
});
if(insert){
insertArray.push(insert);
});
// AND logic
if(insertArray.filter(item => !item).length === 0){
return item;
}
return false;

View file

@ -357,7 +357,7 @@ class AmbassadorsPage extends Component {
});
});
data = data.sort(sortBy('location.searchText'));
data = data.sort(sortBy('nickname'));
const textComponent = (
<span>

View file

@ -419,7 +419,7 @@ class MerchantsPage extends Component {
return this.getMerchantMarker(merchant);
});
merchantsData = merchantsData.sort(sortBy('location.searchText'));
merchantsData = merchantsData.sort(sortBy('name'));
const textComponent = (
<span>