Skip to content

Commit

Permalink
now only filter buttons are used as or and field filters are used as …
Browse files Browse the repository at this point in the history
…and (#44)

* now only filter buttons are used as or and field filters are used as and

* created criteriaExist variable so code gets more readable

* Update web-page/src/components/filter-box/index.js

great!

Co-Authored-By: ~./user -n irving.gomez <[email protected]>
  • Loading branch information
1 parent 5bab290 commit 6bbd80c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions web-page/src/components/filter-box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ const FilterBox = ({ totalCards, appliedFilters, fieldOptions, searchCards, onFi
onFilterRemove(isFilterAdd.id)
return// Filter already added
}
let filterExists = appliedFilters.find(a =>
a.id.toLocaleLowerCase().startsWith(fieldName.toLocaleLowerCase()))
if(filterExists){
let newId, newFilterText, removeFilterRegexp = new RegExp(`\\s\\|\\|\\s(not\\s)?${filterText}|(not\\s)?${filterText}\\s\\|\\|\\s`, 'i'),
criteriaExist = filterExists.id.toLocaleLowerCase().includes(filterText.toLocaleLowerCase())
if(criteriaExist)
newId = filterExists.id.replace(removeFilterRegexp, '')
else
newId = filterExists.id + ' || ' + (isFilterNegation ? 'NOT ' : '') + filterText
newFilterText = newId.split(':')[1]
const filterConditions = parseFilterText(newFilterText)
const filter = createFilter(fieldName, filterConditions, type)
onUpdateFilter(filterExists.id, newId, filter)
return
}
onAddFilter(type, fieldName, filterText, isFilterNegation)
}

Expand All @@ -48,20 +63,6 @@ const FilterBox = ({ totalCards, appliedFilters, fieldOptions, searchCards, onFi
return// Empty string
}

let filterExists = appliedFilters.find(a=> a.id.toLocaleLowerCase().startsWith(fieldName.toLocaleLowerCase()))
if(filterExists){
let newId, newFilterText, removeFilterRegexp = new RegExp(`\\s\\|\\|\\s(not\\s)?${filterText}|(not\\s)?${filterText}\\s\\|\\|\\s`, 'i')
if(filterExists.id.toLocaleLowerCase().includes(filterText.toLocaleLowerCase()))
newId = filterExists.id.replace(removeFilterRegexp, '')
else
newId = filterExists.id + ' || ' + (isFilterNegation ? 'NOT ' : '') + filterText
newFilterText = newId.split(':')[1]
const filterConditions = parseFilterText(newFilterText)
const filter = createFilter(fieldName, filterConditions, type)
onUpdateFilter(filterExists.id, newId, filter)
return
}

if(isFilterNegation)
filterText = 'not ' + filterText
const filterConditions = parseFilterText(filterText)
Expand All @@ -88,7 +89,7 @@ const FilterBox = ({ totalCards, appliedFilters, fieldOptions, searchCards, onFi
}
}

const removedOptions = ['availableDate', 'cardImageUrl', 'cardBack', 'era', /*'type', 'color', 'energy', 'comboEnergy', 'rarity', 'character', 'skillKeywords', 'cardNumber', */]
const removedOptions = ['availableDate', 'cardImageUrl', 'cardBack', 'era', 'type', 'color', 'energy', 'comboEnergy', /*'rarity', 'character', 'skillKeywords', 'cardNumber', */]
const optionsToSelect = fieldOptions.map(
(option, index) =>
!removedOptions.includes(option.fieldName)
Expand Down

0 comments on commit 6bbd80c

Please sign in to comment.