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
Hide Variations
section when it is empty
#36202
Conversation
Test Results SummaryCommit SHA: e9d7f4d
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. |
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.
bdedf7b
to
eaaf86b
Compare
Thank you @joshuatf for reviewing this PR. |
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 the update! Looks good for each case of options existing or not, but ran into a little bit of trouble when changing the options.
Could you check if that's happening on your end? Left a couple possible solutions in the comments.
const { values } = useFormContext< Product >(); | ||
const productId = values.id; | ||
|
||
const { totalCount } = useSelect( |
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.
This is working well for me on the default state, but when options are changed by deleting them if they already existed or by adding them on a new product, the variations section does not change.
We might need cache invalidation for this store when options are changed or maybe we should just use the same getProductAttributes
request that is used in options and check that there is at least 1 item.
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 the updated logic!
I left one case where things are broken on a new product page, but left a comment on how we can fix it. Let me know if that works and we can approve if so.
[ productId, options ] | ||
); | ||
|
||
if ( options.length === 0 || totalCount === 0 || isNaN( totalCount ) ) { |
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.
I think we can remove all of this totalCount
logic now and just rely on the options.length
.
On a new product page when adding options, this totalCount
will not get updated and the variations will remain hidden.
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.
Thank you @joshuatf for your review.
This is interesting; when I place a breakpoint here the totalCount
const is loaded correctly after adding a new option. I guess that there is something related to the variations creation time.
As you mentioned, it seems like we can remove the totalCount
. I removed that logic in the commit e9d7f4d
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.
Testing well on my end and LGTM! 🚢
* Add changelog * Hide Variations section when it is empty * Fix hiding variations * Remove `totalCount const Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
All Submissions:
Changes proposed in this Pull Request:
Hide the
Variations
section when there aren't any variations to show.Closes #36181.
How to test the changes in this Pull Request:
Variations
section should be hidden.wp-admin/admin.php?page=wc-admin&path=/product/{product_id}
.Other information:
pnpm --filter=<project> changelog add
?FOR PR REVIEWER ONLY: