-
Notifications
You must be signed in to change notification settings - Fork 93
LF-4967 Implement product filter #3891
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
Conversation
| export const inventoryFilterSelector = createSelector( | ||
| [filterReducerSelector], | ||
| (filterReducer) => filterReducer.inventory ?? initialInventoryFilter, | ||
| ); |
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.
It's been a long time since we've had this kind of change to the shape of an existing Redux slice, so I don't 100% remember if we have an established way to handle it.
We could either force logout or supply a fallback as above; otherwise the selector (and setter) will error when trying to access the nonexistent tempStateReducer.filterReducer.inventory. I'm thinking logout is certainly more common as our pattern, but we have to then commit to bumping the app version when this goes live, and since I wasn't sure if we wanted to commit to that, I added fallback here.
| "SUPPLIERS": "Suppliers", | ||
| "ACTIVE": "Active", | ||
| "ABANDONED": "Abandoned", | ||
| "ACTIVE": "Active", |
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.
Looks like i18n had not touched this file in a while, so the keys got ordered alphabetically.
SayakaOno
left a comment
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.
It works great!
Is it possible to create a reusable filter container that accepts the filter content as children? Encapsulating isFilterOpen/isDirty state management etc. would be nice...
At least, I’d prefer to import the SCSS file from the animal filter as you did before. Was there a reason you duplicated it instead of reusing it?
| <FilterGroup | ||
| filters={filters.map(sortFilterOptions)} | ||
| filterContainerClassName={filterContainerClassName} | ||
| onChange={handleChange} |
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.
Could we pass onChange directly?
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.
Thank you!! I don't think I would have ever noticed that; callback prop drilling still really trips me up 😓
Maybe it wasn't very good reasoning, but I duplicated instead of referring for this one since we have so many filter drawers in app (as opposed to only 2 inventories) and I thought maybe they should stay independent from each other! I also thought perhaps the styling would be changed in some way as I finished the component, but it was definitely not so 😅 I see the old filters had all been grouped via the |
|
@SayakaOno thank you -- I think an extraction of a shared component was definitely necessary here! Could you please take a look and re-review? 🙏 The extraction should not have changed any logic. |
SayakaOno
left a comment
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 love it!!!
I’m being a bit greedy and want to take it one step further…
The more I look at it, the more I feel like the new FilterDrawerContainer could maybe contain <FilterGroup />. Handling onChange would be needed, but now that ProductFilter and AnimalsFilter are super lean, filters could go in there...?
You’ve already done so much, so no pressure! I just thought it could be a nice improvement if you agree :)
This is such an interesting suggestion, because in a certain way, it's very much going full circle back to our original implementation of filters! Like if you look at one of the older filters in app (e.g. It makes me wonder if the use of the independent That said, I'm not sure I want to move off the modularity of the It's probably not for now -- or at least I'm not super inspired to pick it up 😅 -- but I agree there is definitely scope for more filter refactor here. At the very least I think the main TransactionFilter should be using the same component as Animals and Inventory now, shouldn't it? |
That looks like it! I don’t fully remember how we ended up with this filter code, but I like I initially got overwhelmed by the number of files I’d have to review for the filter, so I think I was unconsciously trying to reduce the diffs and my mental load 😅 |
Description
This adds the filter to Product Inventory, following Animal Inventory exactly (except the fallback in
filterSlice-- see in-line comment below).A common component has been refactored out of
AnimalFilterandProductInventoryFilter.Jira link: https://lite-farm.atlassian.net/browse/LF-4967
Type of change
How Has This Been Tested?
Checklist:
pnpm i18nto help with this)