Skip to content

Conversation

@mdperez86
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

Load dimensions and weight units to show them as a suffix of shipping dimensions fields, so the user will know a reference of which unit of the product dimensions will be used. These units are comming from WooCommerce > Settings > Products configuration.

Partialy closes #34329.

How to test the changes in this Pull Request:

  1. When in the new Product page
  2. A Shipping Dimensions section should be shown with the dimensions and weight units loaded as suffixes of each input field according the WooCommerce > Settings > Products configuration.

image

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm changelog add --filter=<project>?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@mdperez86 mdperez86 requested a review from a team September 27, 2022 19:38
@github-actions github-actions bot added focus: react admin package: @woocommerce/components issues related to @woocommerce/components package: @woocommerce/data issues related to @woocommerce/data package: @woocommerce/number issues related to @woocommerce/number plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Sep 27, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2022

Test Results Summary

Commit SHA: fa2e2cb

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests11800201200m 56s
E2E Tests186102018913m 18s
To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@mdperez86 mdperez86 force-pushed the add/34329-load-size-units branch from e2bee57 to 50d217e Compare September 28, 2022 18:55
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Nice work @mdperez86, this tested well and looked good!
I did leave several comments, one small one around styling and a couple in relation to the BaseControl wrapper, which I don't think is necessary.

Outside of that, nice work on the Form updates and consolidating some of the styling and removing some of the duplicate styling.

const resetForm = (
newInitialValues: Values,
newChangedFields = {},
newInitialValues = {} as Values,
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing the newChangedFields param is probably ok, given I added the additional params just a month ago.
We do have to be careful removing those in the future, for backwards compability.

}

&__content {
padding: $gap-large;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to remove some of these and replace it with the Card component, but the Card component styling is slightly different. It's top/bottom margin is smaller 16px versus 24px and the border-radius a little bit less.

So maybe add the padding and border-radius back for this and target the .components-card specifically.

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

<BaseControl
{ ...regularPriceProps }
id="product_pricing_regular_price"
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why these fields need to be wrapped in a BaseControl component? and why the BaseControl component needs the same props?

Copy link
Contributor

Choose a reason for hiding this comment

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

Left another comment further down in relation to this, I don't think it's necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now it's a little more explicit why I was using BaseControl

label={ __( 'Shipping class', 'woocommerce' ) }
{ ...getTextControlProps(
getInputProps( 'shipping_class' )
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this Fragment is necessary is it? Given everything is wrapped within the ProductSectionLayout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, that's right. Thanks.

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

</p>
<div className="product-shipping-section__container">
<div>
<BaseControl
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the BaseControl is needed for wrapping each InputControl. The logic within BaseControl is already integrated within the InputControl if you look at the label code for example:
BaseControl: https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/base-control/index.tsx#L52-L73
InputControl: https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/input-control/label.tsx

Was this recommended somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrapped each InputControl with BaseControl for 2 reasons.

  1. Other TextControls we are using they are all wrapped within the BaseControl as you can see here.
  2. InputControl does not have the help feature which is used to show error messages and it's spaces styles are not the same as the TextControl we are using.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other TextControls we are using they are all wrapped within the BaseControl as you can see here.

Yeah, although the InputControl is suppose to replace this TextControl so maybe the help feature needed as part of your second point will still get added to the InputControl. I guess we should keep an eye out during any WordPress updates for this.

I think it would be worth to make our own InputControl wrapper that acts much like the TextControl you referenced, that wraps the BaseControl already. So in the case were WordPress does add this on update we only have one spot to update, and not a bunch of places.
But I acknowledge this would be out of the scope of this PR and can be done as a follow up.

const valuesToSet: Values = {} as Values;
valuesToSet[ name as keyof Values ] = value;
setValues( valuesToSet );
setValues( _setWith( { ...values }, name, value, _clone ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @joshuatf in relation to the lodash usage, I know you are less of a fan of using lodash.
This does allow us to reference fields in this manner dimensions.width which is very handy, for the shipping field for example.
We could potentially implement this manually, but given lodash would be much more stable, I would be fine with using this (given we aren't pruning it out yet).
But let me know if you have any strong sense against this?

@mdperez86 mdperez86 requested a review from louwie17 September 29, 2022 15:30
Copy link
Contributor

@louwie17 louwie17 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 @mdperez86, I just left one comment with a small bug I found now with separating the props out for the shipping dimensions. The onBlur is missing, which is required for the help text to show.

'woocommerce'
)
) }
onChange={ ( value: string ) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

You also want to pass in the onBlur callback to the InputControl as otherwise the help text doesn't show up.

Copy link
Contributor Author

@mdperez86 mdperez86 Sep 29, 2022

Choose a reason for hiding this comment

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

Done

@mdperez86 mdperez86 force-pushed the add/34329-load-size-units branch from b525da8 to 458fcb3 Compare September 29, 2022 16:12
louwie17
louwie17 previously approved these changes Sep 29, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Nice work @mdperez86, it's looking great now, thanks for your hard work on this 👍

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Re-approving after rebase.

@mdperez86 mdperez86 merged commit 7fe05d6 into trunk Sep 29, 2022
@mdperez86 mdperez86 deleted the add/34329-load-size-units branch September 29, 2022 17:54
@github-actions github-actions bot added this to the 7.1.0 milestone Sep 29, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2022

Hi @mdperez86, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: @woocommerce/components issues related to @woocommerce/components package: @woocommerce/data issues related to @woocommerce/data package: @woocommerce/number issues related to @woocommerce/number plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Shipping] Dimensions

3 participants