Skip to content

Commit

Permalink
fix(client): bug fix for unable to remove filter when range min is 0
Browse files Browse the repository at this point in the history
when the range filter min is 0, failed to remove the filter
  • Loading branch information
joemcelroy committed Dec 20, 2020
1 parent ee22887 commit 93bd74e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/searchkit-client/src/__tests__/searchkit.test.tsx
Expand Up @@ -76,6 +76,14 @@ describe('Searchkit Client', () => {
])
})

it('should toggle range filters', () => {
const api = new SearchkitClient()
api.addFilter({ identifier: 'type', min: 0, max: 100 })
expect(api.getFilters()).toEqual([{ identifier: 'type', min: 0, max: 100 }])
api.toggleFilter({ identifier: 'type', min: 0, max: 100 })
expect(api.getFilters()).toEqual([])
})

it('should remove multiple filters by id', () => {
const api = new SearchkitClient()
api.addFilter({ identifier: 'type', value: 'Movies' })
Expand Down
10 changes: 9 additions & 1 deletion packages/searchkit-client/src/searchkit.tsx
Expand Up @@ -27,9 +27,17 @@ export interface SearchkitClientConfig {
searchOnLoad?: boolean
}

const isDefined = (str) => typeof str !== 'undefined' && str !== null

const filterSelector = (filter: Filter) => (f: Filter) => {
if (filter.identifier !== f.identifier) return false
if (filter.min && filter.max && filter.min === f.min && filter.max === f.max) return true
if (
isDefined(filter.min) &&
isDefined(filter.max) &&
filter.min === f.min &&
filter.max === f.max
)
return true
if (
filter.dateMin &&
filter.dateMax &&
Expand Down

0 comments on commit 93bd74e

Please sign in to comment.