inveniosoftware / inveniosoftware/react-searchkit
selectedFilters doesn't work for Integer bucket keys
- Dominant language
- JavaScript
- Stars
- 83
- Forks
- 48
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 4
Description
## Describe the bug
[`selectedFilters.filter((filter) => filter[0] === aggName && filter[1] === value)`](https://github.com/inveniosoftware/react-searchkit/blob/883926248b4d81b7302916c090e20631c864ad2b/src/lib/components/BucketAggregation/BucketAggregationValues.js#L27) This step uses strict comparison between value and type.
In case the bucket contains Integer value (key), i.e. year, age, etc., upon bucket click, the checkbox doesn't appear visually checked (the comparison fails). On the other hand, the filter is applied, so the search parameters (and URL) gets updated. The problem lies only in the unset `isSelected` prop that gets passed down to the `Checkbox` SemanticUI component.
The same problem could potentially happen with other data types: boolean, etc.
I don't think that it's meant for the bucket containing key as integer (or boolean), to also contain bucket.key_as_string property, as seen [here](https://github.com/inveniosoftware/react-searchkit/blob/883926248b4d81b7302916c090e20631c864ad2b/src/lib/components/BucketAggregation/BucketAggregationValues.js#L65C7-L66C84):
```
const keyField = bucket.key_as_string ? bucket.key_as_string : bucket.key;
const isSelected = this._isSelected(this.aggName, keyField, selectedFilters);
```
For example for years or age, or any other number coming from backend.
## Expected behavior
Using value comparison only, the issue can be easily solved:
`selectedFilters.filter((filter) => filter[0] == aggName && filter[1] == value)`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.