Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

New block: Filter Products by Price #853

Merged
merged 57 commits into from
Nov 1, 2019

Conversation

mikejolley
Copy link
Member

@mikejolley mikejolley commented Aug 13, 2019

Introduces the filter products by price block (#710).

Screenshots

2019-10-30 16 24 27

How to test the changes in this Pull Request:

  1. Insert block on the same page as an all products block
  2. Check it filters correctly
  3. Text with inputs/buttons hidden. When button is hidden, there should be a debounce/delay after using the filter.

Changelog

Feature - Filter Products by Price block. Allow customers to filter the all products block by price.

@mikejolley mikejolley added status: in progress type: new block Applied to work that introduces a new block (typically used on an epic issue). labels Aug 13, 2019
@mikejolley mikejolley added this to the 2.4 milestone Aug 13, 2019
@mikejolley mikejolley self-assigned this Aug 13, 2019
@mikejolley
Copy link
Member Author

@nerrad ready for review :)

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good progress @mikejolley 🎉 👍 ! I'm still reviewing but thought I'd submit what I have so far in terms of feedback.

  • why is assets/js/base/components/price-slider/handles.sketch in here? Should be removed?
  • I'm seeing styling issues with the slider in both the editor:

screenie

...and the frontend:

screenie2

Both the above are with the storefront theme (in Chrome browser).

  • It is general good practice in react to have all input type components be controlled vs uncontrolled in react. I realize the PriceFilter control is a bit on the border of being an "input" being it's more composite. I did a bit of exploration and I think the main hangup preventing trivially switching this component to be controlled vs uncontrolled is the "Go" button option as in order to trigger the onChange event it needs to know what value to give the callback (and it requires context on whether the last user interaction was on the min slider/input or the max slider/input). To resolve that would require some sort of local state and in that case it wouldn't vary too much from what you have now. So... long story short, let's leave this as uncontrolled for now 👍 .
  • all the render* callbacks you have could be extracted to be actual functional components and put them in their own files only used internally by PriceSlider. That keeps the PriceSlider contents more readable and easier to follow.

Re naming

I have some suggestions for naming variables etc in here, however is this a component that could potentially be used for more than just price (It looks like it might). If so, then it might be good to actually genericize the naming a bit more. So instead of this being a PriceSlider component, it could just be something like ComplexRangeSlider and that would allow for greater re-usability for other types of values that are controlled this way? If you agree, then you can ignore some of my suggestions about including price in other variable names.

To make more generic, you'd probably also want to provide a formatter callback to component and that can be used for doing any necessary formats for displaying the input values of the slider.

assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the rest of my review feedback 👇

assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/hooks/use-debounce.js Show resolved Hide resolved
assets/js/base/hooks/use-query-state.js Show resolved Hide resolved
assets/js/blocks/price-filter/block.js Outdated Show resolved Hide resolved
assets/js/blocks/price-filter/block.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
);

if ( containers.length ) {
Array.prototype.forEach.call( containers, ( el ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just do containers.forEach here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for ie11 compatibility, since we're not using lodash helpers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing pattern in existing code FYI

assets/js/settings/block-data.js Outdated Show resolved Hide resolved
src/Assets.php Outdated Show resolved Hide resolved
@mikejolley
Copy link
Member Author

I think this is ready for another look @nerrad

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming along great! Thanks for implementing the changes from the feedback. There's still a few things I think need addressed. Also, we'll probably want to exclude this block from legacy builds as well, so it can happen similarly as the all-products block:

  • configure webpack.config.js so that legacy configs exclude the path for this block.
  • change Library.php so price filter is moved to the same array as the all products block.

),
} );
}, [ min, max ] );
}, [ minConstraint, maxConstraint ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minPrice, and maxPrice should be dependencies as well otherwise this check won't run if they change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to; this check only needs to run if constraints change. If the min/max current changes it doesn't matter to this block - its within the constraints already.

Copy link
Contributor

@nerrad nerrad Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what about changes in the text input, or do we care about that?

assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/price-input.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/price-input.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/submit-button.js Outdated Show resolved Hide resolved
"integrity": "sha512-Wt2sNMKAX/CKeeeQkdPtolTDcP1nPjvPnXiKLL116h89i4nJ3gBgS6PA31XEeDFuj/tq8HiYeMbzfijKhJyHsA==",
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@wordpress/data-controls/-/data-controls-1.3.3.tgz",
"integrity": "sha512-MA67FZi733IAfUGSqjt/J1yGyls4xgnl6Z+l57ihpEcB6QCxRhWS4Nl3nOuAkzgtPvPgbTQTns/c3dTDpda2uw==",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 huh! I was wondering about this but I guess wp rolled back the patch versions (hence the changes in package-lock.json here for the @wordpress/* packages.)

@mikejolley
Copy link
Member Author

Should be resolved now.

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Are we going to iterate on any necessary styling improvements in separate pulls? Also I noticed some quirkiness in results returned from some queries (but I think that might be a result of the endpoint vs anything in the component - might change with switching to the new store route too).

@mikejolley
Copy link
Member Author

Styling improvements of the all products block as a hole should be done during QA and in a separate pull when we're done, yes.

Thanks for the review.

@mikejolley mikejolley merged commit 2b5c814 into master Nov 1, 2019
@mikejolley mikejolley deleted the feature/filter-products-by-price branch November 1, 2019 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: new block Applied to work that introduces a new block (typically used on an epic issue).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants