Skip to content

Conversation

@mdperez86
Copy link
Contributor

@mdperez86 mdperez86 commented Sep 14, 2022

All Submissions:

Changes proposed in this Pull Request:

Closes #34328.

How to test the changes in this Pull Request:

  1. Make sure you have at least one shipping class added. If not, go to WooCommerce > Settings > Shipping > Shipping classes add it.
  2. Go to Add New (MVP) product page
  3. A Shipping section should be shown

image

4. A Shipping class dropdown should list `No shipping class` option and the other shipping classes you added in point 1.

image

5. When click on helper text `global settings` below the dropdown you should be redirected to `WooCommerce > Settings > Shipping > Shipping classes` page in a new tab

image

6. Add a Spinner during shipping classes resolution
Screen.Recording.2022-09-22.at.1.37.03.PM.mov

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

github-actions bot commented Sep 14, 2022

Test Results Summary

Commit SHA: c6405f1

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests11800201200m 43s
E2E Tests185002018715m 48s
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 marked this pull request as ready for review September 14, 2022 20:12
@louwie17 louwie17 self-requested a review September 15, 2022 16:12
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.

Overall nice work on the @mdperez86, you put this together quickly and well :)
I did encounter a couple issues, as my shipping classes never showed up in the list, which isn't a problem with your code, just the shipping class data store, but I left a suggestion around that for now. - this was a build issue
The shipping classes weren't saving correctly, as we want to use shipping_class versus shipping_class_id. shipping_class uses the slug.
I left some other comments and suggestions within the code.

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

Choose a reason for hiding this comment

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

shipping_class_id is a readonly field, it looks like we want to use shipping_class instead and use the slug as the value instead of the id.
See https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties for more context on the readonly field.

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!!!, awesome @louwie17 that was a question I had and you answered. So are we gonna use shipping_class (slug) as the options value and also to send it when the product gets save right?

Copy link
Contributor

Choose a reason for hiding this comment

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

So are we gonna use shipping_class (slug) as the options value and also to send it when the product gets save right?

Yes, that is right!

return [
...DEFAULT_SHIPPING_CLASS_OPTIONS,
...mapShippingClassToSelectOption( shippingClasses ),
];
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to avoid creating any new arrays or objects within the useSelect function. As everything returned by the useSelect gets "cached". Meaning the useSelect will only trigger a React re-render when the returned value is different.
It only checks this by ===, so any newly created objects or arrays will always show as dirty as the reference will be different.

In theory this is fine for your array as long as the order stays the same, as the useSelect checks for each value with the object returned.
In this case it would loop over each shipping class item and check if it matches the old one.

What I would recommend is just returning the shippingClasses:

return {
  shippingClasses: getProductShippingClasses< ProductShippingClass[] >();
}

Then outside of the useSelect append the two arrays and map them.
Hope that makes sense, let me know if you have any questions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done

EXPERIMENTAL_PRODUCT_SHIPPING_CLASSES_STORE_NAME
);
const shippingClasses =
getProductShippingClasses< ProductShippingClass[] >();
Copy link
Contributor

@louwie17 louwie17 Sep 15, 2022

Choose a reason for hiding this comment

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

It appears there might be something broken with the crud data store at the moment and the above returns null all the time (at-least for me). This might of been something I broke :/ which I thought I had fixed.
To get around it for now you could pass an empty object query object, but I will get a fix up for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this might of been an issue with my build, I will get back to you on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, just double checked and made sure my build was correct. This is indeed working correctly as is, sorry for the confusion.

/**
* External dependencies
*/
import { SelectControl } from '@wordpress/components';
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to use the new experimental SelectControl from @woocommerce/components for this so the dropdown supports typeahead field.
I am not sure how long a shipping class list could get, but being able to search for them in the field would be really nice.
cc: @jarekmorawski on this if we should use a standard dropdown for this, or a typeahead field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because SelectControl is still experimental I will continue using the WP one until this SelectControl will become more stable. I left this branch with a partial implemetation that we can reuse for autocomplete implementation.


const DEFAULT_SHIPPING_CLASS_OPTIONS: SelectControl.Option[] = [
{ value: '', label: __( 'No shipping class', 'woocommerce' ) },
{ value: '-1', label: __( 'Standard shipping', 'woocommerce' ) },
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for leaving a question surrounding this in the original issue :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to this comment we will have only the 'No shipping class' option and it will be the default.

@mdperez86 mdperez86 force-pushed the add/34328-shipping-shipping-class-dropdown branch from edbeec5 to 8f6789c Compare September 15, 2022 19:07
@mdperez86 mdperez86 closed this Sep 21, 2022
@mdperez86 mdperez86 deleted the add/34328-shipping-shipping-class-dropdown branch September 21, 2022 14:50
@mdperez86 mdperez86 restored the add/34328-shipping-shipping-class-dropdown branch September 21, 2022 14:53
@mdperez86 mdperez86 reopened this Sep 21, 2022
@github-actions github-actions bot added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Sep 21, 2022
@mdperez86 mdperez86 force-pushed the add/34328-shipping-shipping-class-dropdown branch 2 times, most recently from c4fc857 to e816f21 Compare September 21, 2022 18:46
@mdperez86 mdperez86 force-pushed the add/34328-shipping-shipping-class-dropdown branch from e816f21 to 08a73b3 Compare September 21, 2022 19:55
@github-actions github-actions bot removed the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Sep 21, 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.

@mdperez86 thanks for the updates, this is testing very well, and updates work great.
I only noticed one minor issue, given the getProductShippingClasses is async, I briefly see "No shipping class" when I open an existing product even though I have a shipping class selected.

Kapture.2022-09-21.at.17.36.21.mp4

I wonder if we could maybe just show a loading icon for the entire block first, kinda like this wireframe: 5sAIeTRd9Yp7nSCT33BAWz-fi-6823%3A312388
Or show it as blank until the shippingClasses are retrieved, or show a loading icon within the dropdown if that is possible.
But following the wireframe apparoach is probably the best:
Screen Shot 2022-09-21 at 5 41 30 PM

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.

Thanks for all your hard work and doing the several updates. This is testing very well and looks great, nice work on the loading screen as well :)

@mdperez86 mdperez86 requested a review from louwie17 September 22, 2022 20:49
@mdperez86 mdperez86 merged commit 2eda531 into trunk Sep 23, 2022
@mdperez86 mdperez86 deleted the add/34328-shipping-shipping-class-dropdown branch September 23, 2022 12:54
@github-actions github-actions bot added this to the 7.1.0 milestone Sep 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 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

Konamiman pushed a commit that referenced this pull request Sep 27, 2022
* Add shipping class section and dropdown

* Add comment suggestions

* Add a Spinner during shipping classes resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Shipping] Shipping class dropdown

3 participants