appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 466 forks source link

SingleDataList doesn't render counts for boolean fields #1797

Closed msabramo closed 2 years ago

msabramo commented 2 years ago

Affected Projects React (@appbaseio/reactivesearch)

Library Version: x.y.z 3.24.3 (@appbaseio/reactivesearch@3.24.3)

Describe the bug The showCount feature of SingleDataList (originally added in https://github.com/appbaseio/reactivesearch/pull/658) doesn't render counts for fields of type boolean.

To Reproduce

Expected behavior The Favorite filter should show the counts next to Favorite and Not favorite.

Screenshots Screen Shot 2021-10-08 at 6 59 07 PM

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

Additional context The data for this codesandbox.io demo is hosted at: https://6692428591fa:c8d5ae7e-8625-410c-97d8-ce19c3708edd@reactivesearch-test-ceyfyhm-arc.searchbase.io/reactive-search-test-1/_search

From https://reactivesearch-test-ceyfyhm-arc.searchbase.io/reactive-search-test-1, you can see the follow field types:

Screen Shot 2021-10-10 at 9 34 44 AM

In particular, note that the field favorite is of type boolean.

msabramo commented 2 years ago

The problem is that aggregations in the Elasticsearch response looks like this:

Screen Shot 2021-10-11 at 3 44 44 PM

and "true" and "false" are what are used in the app code:

          <SingleDataList
            componentId="favorites"
            dataField="favorite"
            title="Favorite"
            showRadio={true}
            showCount={true}
            showSearch={false}
            data={[
              { label: "Favorite", value: "true" },
              { label: "Not favorite", value: "false" },
            ]}
          />

The problem is the app code is using "true" and "false" for the value but the code in SingleDataList.js is looking only at key (and not key_as_string) in the ES response and the values for key are 0 and 1.

(Note that I tried changing the app code to use 0 and 1 for the values in data and that makes the counts work, but it breaks the search results themselves, which is a much worse problem)

So my thought is that maybe it's better for the code in SingleDataList.js to look at both key and key_as_string in the ES response, which is what I did in #1798.