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

Fixes to append items via toolbar #18412

Merged
merged 1 commit into from Nov 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/block-library/src/navigation-menu-item/edit.js
Expand Up @@ -245,7 +245,7 @@ export default compose( [
hasDescendants: !! getClientIdsOfDescendants( [ clientId ] ).length,
};
} ),
withDispatch( ( dispatch, ownProps ) => {
withDispatch( ( dispatch, ownProps, registry ) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only suggestion I'd have would be to maybe consider destructuring registry to just pick select?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some advice from @mcsf that Gutenberg prefers being explicit about where you are accessing the properties of data controls. I took this as avoiding unnecessary destructuring in/around select/dispatch/registry. I could be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some advice from @mcsf that Gutenberg prefers being explicit about where you are accessing the properties of data controls. I took this as avoiding unnecessary destructuring in/around select/dispatch/registry. I could be wrong.

Thanks for thinking about my advice 😄. In this case I don't really have an opinion, since, in the context of withDispatch, select could only come from one place.

My main point — which was merely stylistic — in the other PR was about not extracting the selectors into their own variable, e.g. const { getFoos } = select( store ), and instead always calling select( store ).getFoos( ...args ).

return {
insertMenuItemBlock() {
const { clientId } = ownProps;
Expand All @@ -254,10 +254,15 @@ export default compose( [
insertBlock,
} = dispatch( 'core/block-editor' );

const { getClientIdsOfDescendants } = registry.select( 'core/block-editor' );
const navItems = getClientIdsOfDescendants( [ clientId ] );
const insertionPoint = navItems.length ? navItems.length : 0;

const blockToInsert = createBlock( 'core/navigation-menu-item' );

insertBlock(
blockToInsert,
0,
insertionPoint,
clientId,
);
},
Expand Down