-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Select the current new added shipping class #35123
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
Test Results SummaryCommit SHA: c32f0e5
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. |
joshuatf
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.
Hey @mdperez86, this looks great and is testing well!
Just left a quick suggestion on how we set the new shipping value.
| // This should never be a real slug value of any existing shipping class | ||
| export const ADD_NEW_SHIPPING_CLASS_OPTION_VALUE = | ||
| '__ADD_NEW_SHIPPING_CLASS_OPTION__'; | ||
| export const UNCATEGORIZED_CATEGORY_SLUG = 'uncategorized'; |
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.
Thanks for moving these constants into here!
I know you're just moving this slug in here so I won't let it hold up this PR, but I'm wondering if this will function as expected since users can change the uncategorized slug and definitely may depending on locale.
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.
Yes, that's interesting! I'm wondering what is the logic WP is using to assign this category by default to any product if the user never select any category at all. If this is a variable thing then how do they deal with this? If you can enlighten me with that answer will be great for me, otherwise I think I should find the answer by myself.
Anyway this is a super great catch!
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 the default category is stored in an option - get_option( 'default_product_cat', 0 ).
We should probably rely on that instead of the slug/name since those could be changed.
This is obviously unrelated to this PR though, so I don't want to block your work here. Would you mind creating a follow-up issue for this?
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.
| Promise< ProductShippingClass > | ||
| >( values ).then( ( value ) => { | ||
| invalidateResolution( 'getProductShippingClasses' ); | ||
| selectShippingClassProps?.onChange( value.slug ); |
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.
Calling the onChange handler from the Form feels a tiny bit hacky to me and something I'd like to avoid if we can.
Would a call to setValue from the useFormContext work well here?
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 a matter of how it reads. But using setValue forces me to know the field name and duplicate it around the code. But I don't have a special oppinion for any of the two solutions.
I can change it by your suggestion.
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.
Done!
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.
But using setValue forces me to know the field name and duplicate it around the code
Ya, that's a great point. I guess my main concern is that the intent of the onChange api is to handle changes coming from an input and not necessarily manual changes.
Luckily this handles both events and direct value changes so it works in the current scenario, but I do worry about breaking changes in the future.
Maybe we can introduce something like setValue from getInputProps that acts as a shortcut if we don't want to hold the name of input in a constant.
| useDispatch: jest.fn(), | ||
| } ) ); | ||
|
|
||
| describe( 'ProductShippingSection', () => { |
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.
Thanks for adding these tests ❤️
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.
Definitively!!!
bcc9424 to
f6b18fc
Compare
joshuatf
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.
Code looks great and is testing well! Thanks, Maikel!
| // This should never be a real slug value of any existing shipping class | ||
| export const ADD_NEW_SHIPPING_CLASS_OPTION_VALUE = | ||
| '__ADD_NEW_SHIPPING_CLASS_OPTION__'; | ||
| export const UNCATEGORIZED_CATEGORY_SLUG = 'uncategorized'; |
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 the default category is stored in an option - get_option( 'default_product_cat', 0 ).
We should probably rely on that instead of the slug/name since those could be changed.
This is obviously unrelated to this PR though, so I don't want to block your work here. Would you mind creating a follow-up issue for this?
|
Hi @mdperez86, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
All Submissions:
Changes proposed in this Pull Request:
Closes #35036.
How to test the changes in this Pull Request:
Shipping classdropdown fieldAdd new shipping classoption from the listNew shipping classmodal form, add a new shipping class name then clickAddbutton.Shipping classdropdown.Screen.Recording.2022-10-17.at.2.20.11.PM.mov
Other information:
pnpm --filter=<project> run changelog add?FOR PR REVIEWER ONLY: