-
Notifications
You must be signed in to change notification settings - Fork 942
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
Refactoring filter setup #1296
Refactoring filter setup #1296
Conversation
@Gnito This looks really good! A couple of comments / questions / suggestions:
|
IMO this looks good with the features it currently has. I also think that the array to define the order is definitely more convenient than any other hierarchical solution. Some questions:
|
I'm a bit worried about how big a task this is going to be.
const primaryFilters = filterConfig
.filter(selectVisibleFilters)
.filter(selectPrimaryFilters)
.map(f => <FilterComponent />); I'm a bit worried about the possible complexity of ´selectVisibleFilters`. To me, it sounds that this kind of "hide these filters" cross-referencing could become cumbersome to deal with (users could create loops there) - which becomes annoying if they start to directly manipulate shared URLs. |
My plan was to get rid of it. So, if we start to reference filters, then we need to add ids to those individual filter configs and find relevant queryParameterName through the config file as discussed in the Olli's Q6. What comes to SortBy config, it would require something like |
Hmmm. I think the line between filters and sort is muddy so wouldn't it make sense to have them be part of the same system. Like keyword filter is not only a filter but a sort too. Maybe that's not good enough reason though but in any case there are dependencies between the two and that has to be handled somehow.
I too was not thinking that this should be a per filter thing. Like a filter should not need to know about any other filters. I was thinking this would a place above them. A function that gets called with the combined state of all filters (not with a query string but a map keyd by filter id?) before props are passed to filter rendering. A filter would then just take a prop in it's config
I don't think I'm fully following now. The This makes me think, what layer is now responsible of taking all the filter output and creating a map that's in passed to the dispatched redux action? I think I just need to see more code on how this is all put together to understand this part so we can also continue this discussion once we're there. |
@ovan If the sort config is among filter configs, then we need to extract it away in all the places where we want to render filters (because SortBy is not rendered in the same place in the UI). This is pretty consistent between any other marketplace and e-commerce sites too - different functionality, so the gestalt theory dictates that it should be separated. And the exported sort config variable is pretty simple to get it out:
|
da59e8b
to
eb6fd66
Compare
Status update: The key files in this new setup are:
Through marketplace-custom-config.js one can add/remove/order/configure existing filter components. If there's a need to add completely new filter component (e.g. LongFilter for filtering 'long' type data), customizer needs to create that filter component and add it to the generic filter wrapper: FilterComponent. Every filter gets Edit:
|
In addition to previous comment, we decided to renamed UI containers: I also added a bug fix to SortBy component's functionality. Now updating a filter doesn't clear sort parameter from the URL (except when keywords filter is active since it is sorting the results already with relevance). |
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.
I have only gone through the non-component files, but posting this partial review for you to check already.
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.
Review part 2, still 10 UI component files to go through.
…, and SearchFiltersPanel
b2f10f0
to
2e6b2c6
Compare
This keeps the sort among search params except when keywords filter is activated.
Current filter setup is a mess since routing and state handling (for user inputs) is spread out to 3 different container components:
Furthermore, creating different versions of generic enum-type filters is difficult since you need to duplicate code on those different containers. (e.g. amenities filter is using SelectMultipleFilter, but it could be configurable instead of fixed to variable names etc.)
marketplace-custom-config.js contains filter setup (and sort by too).
So, every filter are described in an array (to get rendering order) and they have keys
In addition, sort configuration also exists in the
marketplace-custom-config.js
.Then all the filter components are added through a single file (
SearchPage/FilterComponent.js
) and related code is removed from those child-containers (i.e. SearchFilters, SearchFiltersPanel, SearchFiltersMobile). The idea is that when you add a custom filter component (let's say, LongFilter since we don't have filter component for long type), you only need to touch this one file instead of spreading and duplicating code in different UI containers.In practice, this means that those container components just render filters through
props.children
and their main tasks are to provide UI and Apply, Reset all, etc. buttons.In the SearchPage/MainPanel.js, those presentational containers get their children rendered through one generic component (called
FilterComponent
), which essentially just maps correct filter config, state/submit handling functions, and other props that the UI container expects.Renaming some of the existing components makes sense at this point:
SearchFilters
->SearchFiltersPrimary
SearchFiltersPanel
->SearchFiltersSecondary
.SortBy's state is now also tracked in MainPanel - so it's not cleared when filters are updated.
Taking update from upstream:
if you have just modified filters on SearchPage, it might be best if you reimplement those filter configurations through marketplace-custom-config.js - i.e. skip the merge conflicts since customizing existing filters (add/remove/update/reorder) is very easy with this new setup.
If you have created completely new filters, you should note that in this new setup
initialValues
for the filter are strings come originally from URL parameters. Therefore, a filter component needs to parse them themselves and vice versa:onSubmit
should give formatted URL parameter values per key (e.g.{ price: '15,1000' }
).Because filter configurations have changed, you need to refactor both EditListingWizard (EditListingFeaturesForm and EditListingDescriptionForm) and ListingPage so that select filters get options correctly. Something like this:
https://github.com/sharetribe/ftw-daily/blob/v5.0.0/src/forms/EditListingFeaturesForm/EditListingFeaturesForm.js#L52