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

Create OrderSelect and Label components #905

Merged
merged 9 commits into from Aug 23, 2019
Merged

Create OrderSelect and Label components #905

merged 9 commits into from Aug 23, 2019

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Aug 23, 2019

This PR creates an <OrderSelect /> component with most of the logic from <ReviewOrderSelect /> so we have a generic component that can be used in All Products block.

I also extracted some logic to display/hide label and screen reader labels into a <Label /> component, this way it can be shared between <OrderSelect /> and <LoadMoreButton />.

Screenshots

(this PR shouldn't produce any visible change)

How to test the changes in this Pull Request:

  1. Add a Reviews by Product block into a post and verify the Order by select and the Load more button still display the correct labels and work fine.
  2. Inspecting them or using a screen reader verify they have the correct screen reader labels.
  3. Look at the assets/js/base/components/label/test/__snapshots__/index.js.snap markup and verify it makes sense.

Changelog

Create new generic base components: <OrderSelect /> and <Label /> so they can be shared between different blocks.

@Aljullu Aljullu added status: needs review type: refactor The issue/PR is related to refactoring. labels Aug 23, 2019
@Aljullu Aljullu added this to the 2.4 milestone Aug 23, 2019
@Aljullu Aljullu requested a review from a team August 23, 2019 13:23
@Aljullu Aljullu self-assigned this Aug 23, 2019
@Aljullu Aljullu added this to In Progress PRs (for automation purposes) in Isotope via automation Aug 23, 2019
}

if ( ! label && screenReaderLabel ) {
if ( typeof Wrapper === 'symbol' && Symbol.keyFor( Wrapper ) === 'react.fragment' ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure doing this typeof check for 'symbol' will work in IE11 even with polyfill (should be verified). Instead you could probably do something like:

if ( label.type && label.type === Fragment )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking the type didn't seem to work, but I refactored the component so we don't need to check for Symbol anymore: d398806. Tested and it works fine on IE11. 👍

import Label from '../label';
import './style.scss';

const OrderSelect = ( { className, componentId, defaultValue, label, onChange, options, screenReaderLabel, readOnly, value } ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is OrderSelect? I think it would be helpful to include some doc block here explaining what the OrderSelect component is used for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b7ed466.

package.json Outdated
@@ -86,6 +86,7 @@
"postcss-loader": "3.0.0",
"progress-bar-webpack-plugin": "1.12.1",
"promptly": "3.0.3",
"prop-types-elementtype": "^1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't look like this is needed? facebook/prop-types#211 - from the text on the `prop-types-elementtype repo README.md:

You can use this library until this PR is merged in the official PropTypes.

It looks like the prop-types library has PropTypes.element and PropTypes.elementType as options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird, I must have had an old version of prop-types installed locally because it wasn't working for me before.

Should be fixed now: 850dc62.

@Aljullu
Copy link
Contributor Author

Aljullu commented Aug 23, 2019

Thanks for the review @nerrad. This is ready for another look.

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 good, I'm pre-approving however it does look like you can simplify the propTypes check for wrapperElement.

@@ -48,13 +54,12 @@ Label.propTypes = {
screenReaderLabel: PropTypes.string,
wrapperElement: PropTypes.oneOfType( [
PropTypes.string,
elementType,
PropTypes.elementType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking into this, it looks like under the hood, PropTypes.elementType is using react-is. So this type also validates string elements (like 'div', 'span' etc). So it should be safe to just remove the PropTypes.string here and only validate PropTypes.elementType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Changed in 1fcd28a.

@Aljullu Aljullu merged commit a0281e9 into master Aug 23, 2019
Isotope automation moved this from In Progress PRs (for automation purposes) to Done Sprint 23 (August 13 - August 26) Aug 23, 2019
@Aljullu Aljullu deleted the add/order-select branch August 23, 2019 16:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants