-
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 SlotFill in Status & Availability panel to match existing hook #6300
Add SlotFill in Status & Availability panel to match existing hook #6300
Conversation
…tus and Availability panel. Relies on WordPress/gutenberg#6300
This looks good @ryanwelcher , thanks for contributing! I can definitely see the use case for adding a slot here and am surprised there isn;t something here already. It would be good to add some docs for this slot, and possibly tests especially if we already have testing around other slots. |
* Defines extensibility lot for the Status & Visibility panel | ||
*/ | ||
|
||
import { createSlotFill } from '../../../../components/slot-fill'; |
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.
This will include the whole components bundle in the edit-post bundle, to import from other modules, we use @wordpress/*
. This should be import { createSlotFille } from '@wordpress/components'
@@ -17,6 +17,8 @@ import PostSticky from '../post-sticky'; | |||
import PostAuthor from '../post-author'; | |||
import PostFormat from '../post-format'; | |||
import PostPendingStatus from '../post-pending-status'; | |||
import PluginPostStatusVisibility from '../plugin-post-status-visibility'; | |||
import PanelRow from '../../../../components/panel/row'; |
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.
Same as above (external import)
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.
@youknowriad are you meaning the PanelRow and the PluginPostStatusVisibility import? I've done the first but not 100% sure on how to do the second.
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 was only talking about PanelRow, all good now
edit-post/index.js
Outdated
@@ -77,5 +77,6 @@ export function initializeEditor( id, post, settings ) { | |||
}; | |||
} | |||
|
|||
export { default as PluginPostStatusVisibility } from './components/sidebar/plugin-post-status-visibility'; |
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.
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.
We usually export as PluginPostStatusVisibility
(Fill) + PluginPostStatusVisibility.Slot
, but I'm not a big fun of this approach. This one exports them as PluginPostStatusVisibility.Fill
+ PluginPostStatusVisibility.Slot
. The only benefit of what we have in other places it that Fill is used in many places but Slot usually only in one.
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 think we should only export the Fills (in the external API)
It is indeed a very good request, but against the overall plan for the user experience planned for the editor. @jasmussen and @mtias should be able to answer this question, but as far as I am aware, we don't want to allow plugins to add their own functionalities in
There is work started by @c-shultz in #5795 on this functionality which hopefully will land soon in |
eefa198
to
90d1d41
Compare
Where would you suggest plugins add information about the status and visibility of a post - including a published post? I understand the need to show plugin information during publish flow, however there is also a great use case for displaying document status and visibility information inside the status and visibility area of the editor. In particular, when a plugin has information to add about the status or visibility of the post. There are many examples, our particular use case is for the Distributor plugin which enables sharing content between WordPress sites. When a post has been shared in this way, that information shows up in the status area: This information is related to the status of the post you are editing and we would like to show it in Gutenberg in the matching location: Showing the status information in the publish flow is not helpful the goal of the message is to inform the user of the distribution status when they open the editor. Published posts also need to show this information, and no publish flow is available for these posts. As soon as users open the post edit screen, it should be clear if the post is a distributed (shared) post. Even for drafts, the publish flow is not available until changes are made to the post, which is disallowed for distributed posts. |
Thanks so much for your contribution here! My personal opinion is this is a valid use case, and it is eloquently described by Adam as well. However I do recall a bunch of discussions around how to build the extensibility, and remember that @mtias had some thoughts about how this is best architected for the future. These discussions, I believe included some thoughts about adding items to existing metaboxes, exactly as is suggested here. Alas, I can't recall the exact details, and Matías is AFK this week, but I believe he will be back some time next week. I would prefer that he gets to share his thoughts on this before we merge. But we should be able to have a decision before 2.8. |
@@ -32,6 +33,9 @@ function PostStatus( { isOpened, onTogglePanel } ) { | |||
<PostSticky /> | |||
<PostPendingStatus /> | |||
<PostAuthor /> | |||
<PanelRow> |
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 <PanelRow>
should be included here. At the moment every item in this Panel is wrapped with PanelRow
. Instead, we can expose Fill
which is wrapped with PanelRow
. In effect, you would add new items as follows:
<PluginPostStatusVisibility>
My item
</PluginPostStatusVisibility>
and Fill
would work as follows:
const PluginPostStatusVisibility = ( { children } ) => (
<Fill>
<PanelRow>
{ children }
</PanelRow>
</Fill>
);
Alternative solution would be to leave it to plugin developers in case they wanted to add more than one item:
<PluginPostStatusVisibility>
<PanelRow>My item 1</PanelRow>
<PanelRow>My item 2</PanelRow>
</PluginPostStatusVisibility>
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 I was thinking the same thing, I would prefer to have a single component. I am new using createSlotFill and am not sure how to implement what you are asking for. Where does
const PluginPostStatusVisibility = ( { children } ) => (
<Fill>
<PanelRow>
{ children }
</PanelRow>
</Fill>
);
go?
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 can go in here: https://github.com/WordPress/gutenberg/pull/6300/files#diff-ee98bfe279b9987ab8753b1c2fd680f0R7
You will have to juggle a bit with exports.
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 can you provide some examples of how I would be able to do this - specifically the reference to juggling the exports?
Along with documentation, I would love to see a simple example added to https://github.com/wordpress/gutenberg-examples Maybe something as simple as showing the post ID. |
I was thinking we should rather create a plugin that would be included in e2e tests similar to https://github.com/WordPress/gutenberg/blob/master/test/e2e/test-plugins/templates.php but with JS code enqueued. I plan to do something like that for the Sidebar and MenuItem working with Plugins API. |
@@ -0,0 +1,7 @@ | |||
/** | |||
* Defines extensibility lot for the Status & Visibility panel |
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.
slot, not lot
@ryanwelcher and @adamsilverstein - We need to wait for @mtias to confirm that this change is expected or there is another way that it can be achieved. In the meantime, do you think it is expected to have other panels extensible in the <PluginDocumentSettings panel="status-visibility" /> |
@ryanwelcher - sharing the example for the Sidebar for reference, to better picture how it looks in action: https://gist.github.com/gziolo/e2954aa83aa1f823b2b05ca1660c2223. This is also how you would extend |
I was thinking we need a more general higher level way of creating these slots and wasn't sure how... so in your example |
@adamsilverstein yes, that's the idea to have matching |
@gziolo in general I like the concept of what you are describing. So looking at the existing panels: I see the following panels:
Do you already have an idea of how this might work behind the scenes? |
As developers, we tend to like extensibility APIs by default, because we know these will empower what we would be able to achieve with plugins etc... And part of me is the same, I want to be able to extend everything in my plugin. But as Core developers, we have to be very careful and don't just add slots everywhere because in the end, these will end up abused by extensions even if the said extension doesn't really make sense in this Area. Plugin authors will try to be as visible as they can regardless of the User Experience, they just want to be used. Not saying, we shouldn't add slots in the Document Panel at specific positions but I'm saying we should be very careful and if it's possible to leverage a unique extensibility API (menuitem + sidebar|modal|screentakeover|post/prepublishpanel), I'd prefer to stick with it even if it's not perfect for all use-cases. |
To add to @rianrietveld's statement (which is 💯), future compatibility is easier the less extensible something is. The amount of community pushback when extension points are removed is incredible, and rightfully so. Creating trust requires a stable API and trust is a foundation for the success of a project. |
The API proposed here is a new API, even if it's similar to an existing API, we can't say it's stable because people will rewrite their applications anyway. I think we should consider this as an opportunity to think about the API. Whether we really need it or not. It's easier to add APIs later than to remove. We should not neglect the fact that adding more and more slots will inevitably create an inconsistent User Experience. |
I completely agree with this and wondered about this at first when reading the more general proposal. After considering though, I could imaging a use case for each of the existing panels and I'm sure there are many use cases that I haven't imagined. Perhaps we should avoid changing the API for now and simple add slots in spots on a case by case basis where a clear use case can be articulated. We can look to our existing extension points (exposed as
That is a risk, and we need to find a balance between the desire for consistent user experience with the desire to be extensible and useful to the developers who make the platform itself great for users. Any extension point is an opportunity for unanticipated possibly poor UX. Hopefully we can alleviate that by providing consistent APIs and documenting simple code pattern examples. |
Let's put it on hold until we hear from @mtias to make sure there isn't an alternative solution that we missed. If it turns out we should add new slots, I will provide all necessary help to make it both flexible and easy to use. |
Merge with master didn’t go well 🙁 |
@gziolo it's that kind of day already :) I'm addressing now. |
0001a6c
to
a9025b0
Compare
edit-post/README.md
Outdated
@@ -90,3 +90,32 @@ The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug st | |||
- Required: No | |||
|
|||
|
|||
## SlotsFill |
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.
"Slot Fills"?
@gziolo I've addressed the bad merge with master and added some documentation. Would love some feedback to be sure the docs are clear and complete. |
edit-post/README.md
Outdated
@@ -90,3 +90,32 @@ The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug st | |||
- Required: No | |||
|
|||
|
|||
## SlotFills | |||
SlotFills provide plugin or theme authors the ability to add items into the Gutenberg interface. While these slots appear in certain locations, |
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.
Question: are the items above on this page also slotfills? can you check the codebase and if they are move this header section to the top of the page (eg are PluginSidebar, PluginSidebarMoreMenuItem slots)?
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.
@adamsilverstein the do have slots defined in them yes. Perhaps we don't need the SlotFills header and I add the note about the implementation vs location under the header for the actual slot.
@gziolo can you please review this again, especially the documentation - I'm really not sure where this belongs, is there one place in the docs that lists all of the slots that are available? Thanks! |
It’s placed properly. We will have to find a better way to expose it in Gutenberg handbook. At the moment this Readme is only linked from Extensibility docs. I didn’t look closely, I’ll review on Monday. There might be some small stylistic tweaks required but nothing major really. Previous code examples use JSX and there some other markdown differences. This Slot & Fill idea needs to be better explained in the foreword or sth. |
/** | ||
* Defines as extensibility slot for the Status & Visibility panel | ||
*/ | ||
import { createSlotFill, PanelRow } from '@wordpress/components'; |
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.
This import statement should have WordPress dependencies
comment as it is done in all other files.
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 addressed my own comments to speed up the process. It is good to go in my opinion. @ryanwelcher and @adamsilverstein hank you for driving this task 🙇
Description
This PR adds a slotFill and is meant as a first pass to fix #6299
Checklist: