Fix/update hide ticket block logic to prevent errors in editor#72
Conversation
…y its insertaion so it cant be inserted when nont on an event post
WalkthroughThe 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/variations/blocks/unregister_blocks.js (1)
6-10: Optional: extract the block name into a constant.Using a single
const BLOCK_NAME = 'simple-events/event-tickets';would reduce repetition and avoid future string drift acrossgetBlockType,unregisterBlockType, andregisterBlockType.♻️ Suggested small cleanup
domReady( function () { if ( window?.seSettings?.postType && 'se-event' !== window.seSettings.postType ) { - const blockType = getBlockType( 'simple-events/event-tickets' ); + const BLOCK_NAME = 'simple-events/event-tickets'; + const blockType = getBlockType( BLOCK_NAME ); if ( blockType ) { - unregisterBlockType( 'simple-events/event-tickets' ); - registerBlockType( 'simple-events/event-tickets', { + unregisterBlockType( BLOCK_NAME ); + registerBlockType( BLOCK_NAME, { ...blockType, supports: { ...blockType.supports,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/variations/blocks/unregister_blocks.js` around lines 6 - 10, Declare a constant like BLOCK_NAME = 'simple-events/event-tickets' and replace the repeated string literals in getBlockType, unregisterBlockType, and registerBlockType calls with that constant (i.e., use getBlockType(BLOCK_NAME), unregisterBlockType(BLOCK_NAME), registerBlockType(BLOCK_NAME, { ...blockType })). This reduces repetition and prevents string drift while leaving the existing logic in getBlockType, unregisterBlockType, and registerBlockType unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/variations/blocks/unregister_blocks.js`:
- Around line 6-10: Declare a constant like BLOCK_NAME =
'simple-events/event-tickets' and replace the repeated string literals in
getBlockType, unregisterBlockType, and registerBlockType calls with that
constant (i.e., use getBlockType(BLOCK_NAME), unregisterBlockType(BLOCK_NAME),
registerBlockType(BLOCK_NAME, { ...blockType })). This reduces repetition and
prevents string drift while leaving the existing logic in getBlockType,
unregisterBlockType, and registerBlockType unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 92de2c3c-2484-4b25-a63c-fbef66ab0fa9
📒 Files selected for processing (1)
src/variations/blocks/unregister_blocks.js
Changes proposed in this Pull Request
This pull request updates the logic for unregistering and re-registering the
simple-events/event-ticketsblock to ensure it is not available in the block inserter for certain post types. The change checks if the block type exists before modifying its registration and updates itssupportsproperty to disable the inserter.Block registration logic improvements:
simple-events/event-ticketsblock type exists before attempting to unregister and re-register it, preventing potential errors.supports.insertertofalse, hiding it from the block inserter for non-se-eventpost types.Testing instructions
Mentions #71
Summary by CodeRabbit