-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Invert the useValidation hook behavior to return an error instead of a boolean value #37695
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
|
Hi @joshuatf, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: c619b21
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. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## trunk #37695 +/- ##
==========================================
- Coverage 51.6% 51.6% -0.0%
Complexity 17260 17260
==========================================
Files 429 429
Lines 79928 79928
==========================================
- Hits 41213 41211 -2
- Misses 38715 38717 +2
|
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.
One optional change, but code tests well and looks great so pre-approving! 🎉
| const validateTitle = useCallback( (): ValidationError => { | ||
| if ( product.title.length < 2 ) { | ||
| return false; | ||
| return 'Title must be greater than 1'; |
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.
Probably worth including localization in here just in case people copy/paste this.
| return 'Title must be greater than 1'; | |
| return __( 'Title must be greater than 1', 'text-domain' ); |
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 -> 0378401
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.
A couple very minor semantic issues. Sorry I didn't catch those in my last review.
| function dimensionsWidthValidator() { | ||
| if ( dimensions?.width && +dimensions.width <= 0 ) { | ||
| return false; | ||
| return __( 'Width must be higher than zero.', 'woocommerce' ); |
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.
| return __( 'Width must be higher than zero.', 'woocommerce' ); | |
| return __( 'Width must be greater than zero.', 'woocommerce' ); |
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 -> c619b21
| function dimensionsLengthValidator() { | ||
| if ( dimensions?.length && +dimensions.length <= 0 ) { | ||
| return false; | ||
| return __( 'Length must be higher than zero.', 'woocommerce' ); |
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.
| return __( 'Length must be higher than zero.', 'woocommerce' ); | |
| return __( 'Length must be greater than zero.', 'woocommerce' ); |
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 -> c619b21
| function dimensionsHeightValidator() { | ||
| if ( dimensions?.height && +dimensions.height <= 0 ) { | ||
| return false; | ||
| return __( 'Height must be higher than zero.', 'woocommerce' ); |
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.
| return __( 'Height must be higher than zero.', 'woocommerce' ); | |
| return __( 'Height must be greater than zero.', 'woocommerce' ); |
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 -> c619b21
| function weightValidator() { | ||
| if ( weight && +weight <= 0 ) { | ||
| return false; | ||
| return __( 'Weight must be higher than zero.', 'woocommerce' ); |
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.
| return __( 'Weight must be higher than zero.', 'woocommerce' ); | |
| return __( 'Weight must be greater than zero.', 'woocommerce' ); |
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 -> c619b21
| const validateTitle = useCallback( (): ValidationError => { | ||
| if ( product.title.length < 2 ) { | ||
| return false; | ||
| return __( 'Title must be greater than 1', 'text-domain' ); |
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.
| return __( 'Title must be greater than 1', 'text-domain' ); | |
| return __( 'Title must be more than 1 character', 'text-domain' ); |
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 -> c619b21
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.
Looks good! Thanks for those last changes 🎉
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #37663
Closes #37706
Closes #37707
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
/wp-admin/tools.php?page=woocommerce-admin-test-helperproduct-block-editor/wp-admin/admin.php?page=wc-admin&path=/add-product