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

[Try] Add ability to extend content of other sidebars. #6899

Closed
wants to merge 1 commit into from

Conversation

jorgefilipecosta
Copy link
Member

If merged this PR will:
Add a pair of slot and fill SidebarExtender components.
Adds the slot of SidebarExtender to all general sidebars (block, document, and plugins ).

Although SidebarExtender adds the content to all sidebars, plugins can easily use withSelect + ifCondition to select exactly when they want to show something or just show something in a specific sidebar. We can also in the future create more HighLevel versions that rely on this low-level interface.

This idea appeared when reviewing #6798. The original idea was to also apply the sidebar extender in pre and post-publish sidebars so PluginPrePublishPanel could just use a combination of withSelect+ ifCondition+SidebarExtender, but the querying pre and post-publish state is not possible as it uses a local sate so I end up not pursuing this idea.

How has this been tested?

Add the following block of code in the console:

var el = wp.element.createElement;
var SidebarExtender = wp.editPost.SidebarExtender;
var sidebarContent = el( wp.components.PanelBody, {}, el( 'h3', {}, 'Hello world!' ) ); 
var mySidebarExtender = el( SidebarExtender, {}, sidebarContent );
wp.plugins.registerPlugin( 'test', { render: function(){ return mySidebarExtender } } );

Verify it adds 'Hello world!' to all sidebars including the plugins ones e.g Dropit.

Add the following block of code:

var el = wp.element.createElement;
var SidebarExtender = wp.editPost.SidebarExtender;
var sidebarContent = el( wp.components.PanelBody, {}, el( 'h3', {}, 'Hello world!' ) );
var MyConditionalSidebarExtender = wp.element.compose( [
    wp.data.withSelect( ( select ) => ( {
        isDocumentSidebar: 'edit-post/document' === select( 'core/edit-post' ).getActiveGeneralSidebarName()
    } ) ), 
    wp.components.ifCondition( ( props ) => props.isDocumentSidebar )
] )( SidebarExtender ); 
var mySidebarExtender = el( MyConditionalSidebarExtender, {}, sidebarContent );
wp.plugins.registerPlugin( 'test', { render: function(){ return mySidebarExtender } } );

Verify it writes 'Hello world! just in the document sidebar.

If merged this commit will:
Add a pair of slot and fill SidebarExtender components.
Adds the slot of SidebarExtender to all general sidebars general sidebars (block, document and plugins ).
@jorgefilipecosta jorgefilipecosta added the [Feature] Extensibility The ability to extend blocks or the editing experience label May 22, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this May 22, 2018
@gziolo
Copy link
Member

gziolo commented May 23, 2018

This a very interesting idea. I don’t think we should expose it for plugins as it is a bit complex to use but it might play a key role as internal solution which would simplify everything and allow us to keep smaller number of slots.

Did you think how we could handle the case when such slots are displayed in a few places at the same time? How to make sure it is rendered only once given some condition is met? Your case works perfectly fine with sidebars because only one of them is rendered at the time 😃

@HardeepAsrani
Copy link
Contributor

This seems interesting. I was looking for a way to do this in a plugin, where the Document Sidebar will only have a simple Checkbox, and clicking on it will put Plugin Sidebar to focus. Hope this gets merged soon. :)

@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Jul 9, 2018

Did you think how we could handle the case when such slots are displayed in a few places at the same time? How to make sure it is rendered only once given some condition is met?

I think if the same slot is exposed in more than one place at the same time, we are going to render to all of the slots. We will not be able to control to which slot to render. That is a limitation of this current idea.
Given that our current slot strategy is working well for now and that this was just created for demo purposes during a review, I'm going to close this PR.
This solution may still be valid if in the future we want for example to allow the extension of all the sidebars or something identical.

This seems interesting. I was looking for a way to do this in a plugin, where the Document Sidebar will only have a simple Checkbox, and clicking on it will put Plugin Sidebar to focus. Hope this gets merged soon. :)

@HardeepAsrani, it seems currently the best option you have is to use one of the slots we already have available for plugins, e.g.: PluginPostStatusInfo https://github.com/WordPress/gutenberg/blob/master/edit-post/README.md. If you fill, we are missing a slot for your case feel free to open an issue so we can discuss that in detail.

@HardeepAsrani
Copy link
Contributor

@jorgefilipecosta Yes, I've used PluginPostStatusInfo option right now. But even then I believe this feature is needed, so will probably open a new issue later on about it.

@xenobytezero
Copy link

I would also say I am looking for this feature, to add a simple extra bit of post data to specific posts where a whole new sidebar would be overkill.

@sirreal sirreal deleted the add/general-sidebar-exitensibility branch June 18, 2024 14:54
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants