-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Price range filter on PLP #1364
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1790e31:
|
033d77d
to
1f51cb0
Compare
/** | ||
* Callback that fires when the slider value ends changing. | ||
*/ | ||
onEnd?: (value: { min: number; max: number }) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has the same behavior as onBlur
, why not call it that then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, on end fires when the user stops clicking the element. onBlur
fires when the object it blurred, i.e. the user clicks, interacts and them leaves.
ea38b03
to
77cac24
Compare
1355f94
to
1bc60d3
Compare
1bc60d3
to
334ed95
Compare
334ed95
to
1790e31
Compare
What's the purpose of this pull request?
This PR adds PriceRange filter functionality to our starters. For that to work, changes to UI, SDK and API were needed
How it works?
FastStore API
For FastStore API I had to do two main changes:
-to-
with:
and forwardsprice
to Search APITo understand why I had to do 3 more clearly, think about the Boolean facets. For boolean facets, search API returns if a given facet is selected or not depending on the forwarded
selectedFacets
. This simplifies rendering on the UI because for rendering the filters, all the UI needs to do is iterate over the Search API response, selecting the checkboxes that haveselected=true
as value.I made the same for the range filter, since Search API does not return the selected value for range filters.
FastStore UI
FastStore UI suffered these two changes:
1 was necessary for displaying a pre-selected range on PLPs. Also, onEnd callback function was necessary to enable applying filters after the user slides to a new range.
FastStore SDK
Changes to FastStore SDK were a bit more dramatic then on both API and UI. Most of changes were derived from
useSearchState.ts
file. This file implemented a hook that returned many functions for changing search state, like setTerm, setSort, toggleFacets etc. The issue with this implementation is that these functions did not alter a React state, but changed the browser's URL. This means that, if you wanted to perform two consecutive changes to the search state, these changes were not batched and many wild bugs emerged. To address this issue, a new setState function was added to the context and all the rest were removed and re-exported as helper functions. This makes it so we can change multiple parts of the searchState elsewhere and perform one singlesetState
for triggering the navigation to the final url.How to test it?
Make sure you are able to side the filters bellow and everything gets set correctly