I am trying to dynamically modify the geo center in the range search for the National Parks codesandbox example.
I am trying to changing the geo-center coordinate for the range search via custom component with select menu as described in Build Your Own Component.
Here is the forked National Parks example with the implementation so far.
You should probably lift the selectedOption state out of that component up to App.js, and use the selecteOption to populate the center property of the location facet, here.
location: {
// San Francisco. In the future, make this the user's current position
center: geocenter.value,
type: "range",
unit: "mi",
ranges: [
{ from: 0, to: 100, name: "Nearby" },
{ from: 100, to: 500, name: "A longer drive" },
{ from: 500, name: "Perhaps fly?" }
]
}
You'd basically need to lift the state up to be stored as state in App.js. You'd pass the current value of geocenter into ChangeGeoCenter, as well as a callback to update it in App.js. React has some great docs on lifting state: https://reactjs.org/docs/lifting-state-up.html.
Let me know if you are still confused after react that and I'll try to put together an example.
When I make the change in the select I can see the updates of the the values in the facet above.
However this does not update the search results. I would need to re-check the Distance filter in order to refresh the results.
Great! And yeah, there's no super elegant solution to re-query right now, so do this...
You still have WithSearch in there, right? That lets you access underlying state and actions. Just call setSearchTerm with the current resultSearchTerm to rerun the current query.
Since it looks like you need to call that in your handleGeocenterChange handler, you may need to use the withSearch Higher Order Component instead of WithSearch. The pattern is the same, you just add it slightly differently...
The only thing that is not so great about this, is when we call setSearchTerm is actually erases your previous filters. I'm guessing this is not what you are looking for.
I could add some sort of work around for this faily quickly to a 1.4.0-rc.1 if that helps.
Thank you Jason,
Erasing the previous filters is a minor inconvenience for my use-case. For me it was more important to preserve the selected set of filters via
We have to remove the filter from location, because unfortunately it appears that there is a bug where if you change the City Center and a filter had been previously applied to Distance, that the OLD value for "nearby", etc will be retained.
In other words, if you were looking at "nearby" values for "Chicago", and change to "San Franciso", it would still be showing "nearby" values for "Chicago".
For now, the solution is to just clear the location filter. With some somewhat tricky logic we could make this work, if we need to.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.