-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Fix: Featured invalid-id item handled with new item picker panel #59033
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
Fix: Featured invalid-id item handled with new item picker panel #59033
Conversation
WalkthroughThe changes introduce logic to handle cases where a featured product or category in WooCommerce blocks becomes invalid, such as when deleted or unpublished. A new React hook checks the item’s status, and the block editor UI now displays a contextual message if the item is unavailable. Minor style updates and utility functions support this behavior. Changes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes were found. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
🧹 Nitpick comments (4)
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/utils.ts (1)
4-4
: Import organization improvement.Consider keeping external dependencies at the top and internal dependencies below for better organization consistency.
/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** * Internal dependencies */ import { BLOCK_NAMES } from './constants'; -import { Coordinates, ImageFit } from './types'; - -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; +import { Coordinates, ImageFit } from './types';plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts (1)
12-21
: Improve TypeScript interfaces.The interfaces could be more specific and descriptive.
-interface FeaturedItemProps { +interface UseFeaturedItemStatusProps { itemId: number | undefined; - itemType: string; + itemType: typeof BLOCK_NAMES.featuredProduct | typeof BLOCK_NAMES.featuredCategory; } -interface FeaturedItemReturnType { +interface UseFeaturedItemStatusReturn { - status: string | null; - isDeleted: boolean | null; + status: 'publish' | 'draft' | 'deleted' | null; + isDeleted: boolean; isLoading: boolean; }plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx (1)
51-51
: Update interface for consistency.The
isLoading
property was added but the interface description could be clearer.interface EditModeRequiredProps< T > { attributes: EditModeRequiredAttributes & EditorBlock< T >[ 'attributes' ]; debouncedSpeak: ( label: string ) => void; setAttributes: ( attrs: Partial< EditModeRequiredAttributes > ) => void; triggerUrlUpdate: () => void; - isLoading: boolean; + isLoading?: boolean; // Optional since it's derived from the hook }plugins/woocommerce/changelog/fix-develop-featured-items-invalid-id (1)
4-4
: Improve changelog entry clarity and grammar.The description could be more specific and grammatically correct.
-Handled the invalid product id once the product is deleted or moved to draft in featured item blocks . +Handle invalid product/category IDs when items are deleted or moved to draft in featured item blocks.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
plugins/woocommerce/changelog/fix-develop-featured-items-invalid-id
(1 hunks)plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/style.scss
(1 hunks)plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
(1 hunks)plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/utils.ts
(2 hunks)plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
(3 hunks)
🔇 Additional comments (1)
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/style.scss (1)
184-186
: LGTM! Clean CSS implementation.The CSS rule properly uses CSS custom properties with a fallback color and follows the established naming conventions. The orange color choice effectively communicates the warning/info state for invalid items.
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/utils.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
Outdated
Show resolved
Hide resolved
Testing GuidelinesHi , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
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 working on this! Everything works as expected:
Screen.Capture.on.2025-06-26.at.14-53-11.mp4
I left a few comments, but they are pretty straightforward to fix.
I see two interesting follow-ups if you are interested in working on:
- Remove
editMode
attribute -> I think that we should not have theeditMode
attribute because it is just a “flag” for the editor side, but handle with a React state. - We have the same issue for other blocks. It would be interesting to create a block that renders the list of product/category/etc and handles the invalid ID too. At the same time, I don't know how much effort is required.
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/utils.ts
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
Outdated
Show resolved
Hide resolved
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/with-edit-mode.tsx
Outdated
Show resolved
Hide resolved
Also, it looks like that this PR breaks some E2E tests. Can you investigate why? |
…tton was not usable is resolved
Hello @gigitux , I have a doubt regarding register_post_type(
'product_variation',
apply_filters(
'woocommerce_register_post_type_product_variation',
array(
'label' => __( 'Variations', 'woocommerce' ),
'public' => false,
'hierarchical' => false,
'supports' => false,
'capability_type' => 'product',
'rewrite' => false,
'show_in_rest' => true,
)
)
); The reason behind this change is , while i was performing test on the productPicker i've noticed it's only working for single products .Whenever i'm selecting a variable product option -> save -> refresh it , it's causing edit mode to true as the product was not found as it's a |
@gigitux if i'm not wrong the failed CI test isn't associated with this PRs changes. |
You're right! |
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, I left a comment regarding a refactor that it is needed. Also, I noticed that the label is wrong when the product list is rendered: can you replicate it?
Screen.Capture.on.2025-08-01.at.14-26-13.mp4
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
@gigitux resolved the feedbacks, Thanks! featured-items-edit-mode-test.mov |
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 tested the PR and now it works correctly! I left a small feedback; once you fix it, I will do the final round of testing! Thanks! 🙇
plugins/woocommerce/client/blocks/assets/js/blocks/featured-items/use-featured-item-status.ts
Outdated
Show resolved
Hide resolved
Thanks, removed the parenthesis. |
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 all your work. LGTM! Everything works as expected!
Blocks with not deleted product
Screen.Capture.on.2025-08-08.at.08-44-56.mp4
Blocks with deleted product
Screen.Capture.on.2025-08-08.at.08-46-04.mp4
It is not related to this PR, but I noticed a different behavior between the Featured Category block and the Featured Product block.
When the category is deleted, the block renders nothing on the frontend. However, in the Featured Product block, the product is still displayed. This likely happens because the PHP render logic for Featured Product doesn’t check whether the product is in the trash.
Also, with 3d5f993, I update the error type from Why
I hope that it makes sense! |
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR introduces a custom hook
useFeaturedItemStatus
to handleinvalid
selected items for the Featured Product and Featured Category block.The
useFeaturedItemStatus
hook:Accepts an itemId and an itemType ('product' or 'category')
Returns three state values:
status: the current publish status of the item ('publish', 'draft', etc.)
isDeleted: a boolean indicating whether the item has been deleted .
isLoading: indicates the loading state during fetch.
Closes #42677 .
Screenshots or screen recordings:
featured-item-invalid-id-fix-video.mov
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Testing that has already taken place:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment
Summary by CodeRabbit
Bug Fixes
New Features
Style