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

wp.data.select() is not working on the Experimental Navigation page #22022

Closed
manmotive opened this issue May 1, 2020 · 7 comments
Closed

wp.data.select() is not working on the Experimental Navigation page #22022

manmotive opened this issue May 1, 2020 · 7 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Bug An existing feature does not function as intended

Comments

@manmotive
Copy link

manmotive commented May 1, 2020

Describe the bug

I am attempting to retrieve the menu item ID (the underlying post ID) of the selected menu item. On the Experimental Navigation page, I believe the menu item ID will be stored as the clientId on the block.

I am using the following to get the clientId:

wp.data.select( 'core/block-editor' ).getSelectedBlock().clientId;

On a standard post or page

This works, the client ID is returned as expected:

a

On the Experimental Navigation page

This doesn't work, the same code returns an error:

b

To reproduce

  1. Go to Gutenberg > Navigation (beta)
  2. Select a menu item
  3. Paste the following into the console:

wp.data.select( 'core/block-editor' ).getSelectedBlock().clientId;

  1. See error

Expected behavior

The client ID of the selected block is returned.

Editor version:

  • WordPress version: 5.4.1
  • Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? Plugin
  • If the Gutenberg plugin is installed, which version is it? 8.0
@manmotive
Copy link
Author

@annezazu annezazu added [Feature] List View Menu item in the top toolbar to select blocks from a list of links. [Type] Bug An existing feature does not function as intended [Block] Navigation Affects the Navigation Block labels May 1, 2020
@noisysocks noisysocks added [Feature] Extensibility The ability to extend blocks or the editing experience and removed [Feature] List View Menu item in the top toolbar to select blocks from a list of links. labels May 19, 2020
@noisysocks
Copy link
Member

It looks like there's two separate issues here:

  1. wp.data.select( 'core/block-editor' ).getSelectedBlock() should not return undefined on the Navigation screen. This is a bug.

  2. As mentioned in First pass at Navigation screen #21036 (comment), there's currently no way for third parties to get the ID of the underlying menu item given a Navigation Link's client ID.

    We probably should be using @wordpress/data in the Navigation screen. Props to @talldan for first suggesting this. We could then close this issue by adding e.g. a getMenuItem selector.

    wp.data.select( 'core/edit-navigation' ).getMenuItem( clientId )

@noisysocks noisysocks added [Feature] Navigation Screen and removed [Block] Navigation Affects the Navigation Block labels May 20, 2020
@talldan
Copy link
Contributor

talldan commented May 20, 2020

I wonder if this is because those selectors can only run within the scope of the <BlockEditorProvider>. Looks like the same thing happens on the experimental Widgets screen.

@youknowriad
Copy link
Contributor

No, that's because by BlockEditorProvider is "scoped" which means it doesn't rely on the global 'core/block-editor' store. I'd argue that it's a good thing to start this way and see later if we really need to make it global. (it's just a prop)

@adamziel
Copy link
Contributor

adamziel commented Jul 3, 2020

As mentioned in #21036 (comment), there's currently no way for third parties to get the ID of the underlying menu item given a Navigation Link's client ID.

#23033 solved this issue. It is now possible to use the following selectors:

wp.data.select( 'core/edit-navigation' ).getNavigationPostForMenu( menuId );
wp.data.select( 'core/edit-navigation' ).getMenuItemForClientId( clientId );

@adamziel
Copy link
Contributor

adamziel commented Jul 3, 2020

wp.data.select( 'core/block-editor' ).getSelectedBlock() should not return undefined on the Navigation screen. This is a bug.

#23675 will solve this problem - I encourage reviews and discussion.

@adamziel
Copy link
Contributor

adamziel commented Jul 7, 2020

This issue is now solved in full. Feel free to reopen if anything comes up.

@adamziel adamziel closed this as completed Jul 7, 2020
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

No branches or pull requests

6 participants