-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add: Plugin Sidebar management functionality to plugins package. #20336
Add: Plugin Sidebar management functionality to plugins package. #20336
Conversation
@jorgefilipecosta - can you elaborate more about the components and APIs introduced? Names differ from |
ceaddbd
to
09a1004
Compare
Size Change: +2.52 kB (0%) Total Size: 864 kB
ℹ️ View Unchanged
|
09a1004
to
02c8dd0
Compare
…the functionality on edit-site.
02c8dd0
to
0bcec0e
Compare
Hi @gziolo, as an overview of what we are exposing now: Under PluginSidedar we have PluginSidedar.Slot that is a slot to render the sidebar and we also have PluginSidedar.PinnedItemsSlot is a slot where the pinned items will be rendered. We expose an API in the store that allows keeping track of which area is active in a given zone when only one area can be active at a time. For example what sidebar is being rendered, what tab in a tab system is enabled etc...
We expose an API in the store that allows keeping track of which areas are active in a given zone when multiple areas can be active at a time
|
One important thing I would like to fix here is that we don’t use the “sidebar” keyword in the The way the edit post page is structured prevents us from using
However, when you ignore all the WP-Admin wrapping, this is the best way to think about the sidebar. How do you feel about using |
@@ -21,6 +22,7 @@ export default function Header() { | |||
</h1> | |||
<div className="edit-site-header__actions"> | |||
<SaveButton /> | |||
<PluginSidebar.PinnedItemsSlot scope="edit-site/sidebar" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that PinnedItems
should be specific to the sidebar. It's a completely independent feature that provides shortcuts to access plugins. The current implementation might be misleading:
gutenberg/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js
Lines 34 to 46 in ec68bb8
{ isPinnable && ( | |
<PinnedPlugins> | |
{ isPinned && ( | |
<Button | |
icon={ icon } | |
label={ title } | |
onClick={ toggleSidebar } | |
isPressed={ isActive } | |
aria-expanded={ isActive } | |
/> | |
) } | |
</PinnedPlugins> | |
) } |
It's colocated with the Sidebar component that has this button that allows to pin or unpin it. However, you could easily make the menu item that executes an action pinnable. Everything can be pinnable. There is probably a lot of prior knowledge hidden on GitHub accumulated in the discussions between me and @jasmussen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the ping. Yes, for one, any item that has a pinned button in the toolbar must have an item in the more menu. Otherwise you can unpin that item and not get it back. I believe this is currently something the developer must ensure, but it would be nice if the API handled it so that a pinned item is an extension of a menu item.
And also, the pinned items do not need to have anything to do with sidebars, it could be sidebars, but it could be a popover, or a modal dialog, or hey, a link that opens a new tab. Think of it very much like a Chrome or Firefox extension in that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gziolo Are you saying it's currently possible to have a pinned icon that does something other than open a sidebar? I've been struggling to figure out how to do that in the shipping version of Gutenberg. I think it would be an awesome addition though and makes sense to ensure it's accommodated here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisvanpatten - unfortunately it isn't implemented for modals and menu items that call arbitrary actions. Priorities change too often so I never got back to those APIs. However, technically speaking it should be straightforward to replicate.
As @jasmussen mentioned, we need to fix the issue for the sidebar first - #14457. In that issue, there is a proposal where the plugin sidebar would have a corresponding menu item attached by default.
import SidebarHeader from './sidebar-header'; | ||
|
||
function PluginSidebarPinnedItems( { scope, ...props } ) { | ||
return <Fill name={ `PluginPinnedAreas/${ scope }` } { ...props } />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It made me think that maybe we should support scopes natively in the SlotFill? What do you think? If I recall properly there are more places like that where we have to play with the name of the SlotFill pair.
isActive: getSingleActiveArea( scope ) === sidebarName, | ||
isPinned: isMultipleActiveAreaActive( scope, sidebarName ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit confusing to see the names of selectors so loosely related to the local constants used. Can you explain how multiple active areas relate to pinned items? I might be missing something because the notion of active areas is brand new.
For reference, this is how it is implemented in edit-post
package:
gutenberg/packages/edit-post/src/components/sidebar/plugin-sidebar/index.js
Lines 149 to 150 in 8bba7e1
isActive: getActiveGeneralSidebarName() === sidebarName, | |
isPinned: isPluginItemPinned( sidebarName ), |
Aside: to be clear, I don't like getActiveGeneralSidebarName
at all :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this PR. It's quite challenging to build a good abstraction that uses names that are flexible enough to cover all uses cases that we deal with including native mobile. In general, this proposal is very good. I have some issues with the names proposed but I'm biased because I know how edit-post
was implemented. The fact that we never implemented plugins for modals and menu items with actions makes it harder to process. I would appreciate help from someone who can judge better what's the best approach to take taking into account feedback shared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was talking to @jorgefilipecosta about the need for a @wordpress/admin-screen
package to handle the common things across WP screens (Skeleton, Fullscreen, Plugins) instead of adding these APIs to the plugins package.
Also, I'd like to see how this would apply to edit-post
as it's a more concrete use-case and the refactor wouuld give us a clear idea about the needed APIs
Closed in favor #20698. |
This PR adds Plugin Sidebar management functionality to plugins package similar to what we had in edit post.
That functionality is used to implement sidebars in edit-site uses the functionality on edit-site.
In order to make this PR reviewable for now, just PluginSidebar is added to plugins.
If we agree with this approach the following follow-ups are required:
The plugins API is used in edit-site to register a sidebar for the block inspector and for the global styles.
cc: @ItsJonQ, @gziolo
How has this been tested?
I went to edit site and I verified I could toggle the block inspector and the "global styles sidebar" for now just a paragraph of text.