Skip to content
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 property name in PluginBlockSettingsMenuItem #14741

Merged

Conversation

swissspidy
Copy link
Member

@swissspidy swissspidy commented Apr 1, 2019

Description

In #7895, PluginBlockSettingsMenuItem was made extensible for plugin developers.

There was a slight oversight though regarding the allowedBlockNames prop. While the documentation was referring to allowedBlockNames, the code was actually checking for allowedBlocks,

How has this been tested?

I extended the settings menu by using the examples from the documentation and verified that allowedBlocks now is properly documented as such.

Screenshots

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@swissspidy swissspidy added [Type] Bug An existing feature does not function as intended [Feature] Extensibility The ability to extend blocks or the editing experience labels Apr 1, 2019
swissspidy added a commit to ampproject/amp-wp that referenced this pull request Apr 1, 2019
@oandregal
Copy link
Member

In my own testing example, I used allowedBlocks 🤦‍♂️

Thanks for catching this @swissspidy I think it'll be better to fix it the other way round: rename the allowBlockNames instances to allowBlocks, as that's what we use in other places of the codebase for allowed lists (filters, innerBlocks, columns, media-text, etc.).

@aduth
Copy link
Member

aduth commented Apr 1, 2019

Bug fix (non-breaking change which fixes an issue)

Wouldn't it be considered breaking for those which would have used allowedBlocks from how it had been implemented in the code?

@swissspidy
Copy link
Member Author

Wouldn't it be considered breaking for those which would have used allowedBlocks from how it had been implemented in the code?

Indeed, but I am not sure how many people that really did. I'd say most people go by the documentation, which means changing everything to allowBlocks would be breaking as well.

I suppose we could just do allowBlockNames || allowBlocks for BC?

@aduth
Copy link
Member

aduth commented Apr 1, 2019

which means changing everything to allowBlocks would be breaking as well.

Is it breaking if it never worked? 😆

@swissspidy
Copy link
Member Author

Fair enough :-)

I'll change it to allowedBlocks then.

@aduth
Copy link
Member

aduth commented Apr 1, 2019

rename the allowBlockNames instances to allowBlocks, as that's what we use in other places of the codebase for allowed lists (filters, innerBlocks, columns, media-text, etc.).

Frustratingly, it's not all consistent. The BlockEditorProvider component, for example, receives allowedBlockTypes as a setting.

I'd say as far as not creating further inconsistency, allowedBlocks would be the best option here. There's no other existing occurrence of allowedBlockNames to use as precedent.

I guess the documentation may have been misled by the argument of this function?

* @param {string[]} selectedBlockNames Array containing the names of the blocks selected
* @param {string[]} allowedBlockNames Array containing the names of the blocks allowed
* @return {boolean} Whether the item will be rendered or not.
*/
const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.isArray( allowedBlockNames ) ||

@swissspidy swissspidy requested a review from aduth April 1, 2019 14:11
@oandregal
Copy link
Member

It'll be nice if we changed the shouldRenderItem( selectedBlockNames, allowedBlockNames ) to shouldRenderItem( selectedBlocks, allowedBlocks ) as per internal consistency.

@swissspidy swissspidy merged commit ed3691a into master Apr 2, 2019
@swissspidy swissspidy added this to the 5.5 (Gutenberg) milestone Apr 2, 2019
@swissspidy swissspidy deleted the fix/plugin-block-settings-menu-item-allowed-blocks branch April 2, 2019 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants