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

Packages: Extract edit post package #8958

Closed
wants to merge 5 commits into from
Closed

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Aug 14, 2018

Description

Partially addresses #8421.

There are no breaking changes so far even though this PR has some refactorings:

  • Rename PluginsBlockSettingsMenuGroup and move to editor package - PluginBlockSettingsMenuItem was an internal component in edit-post so couldn't be really used.
  • Update PluginBlockSettingsMenuItem to align with docs - we need to decide whether we should fix docs instead.

Testing

Example plugins for the following components can be found inside e2e tests folder:

  • PluginPostPublishPanel
  • PluginPrePublishPanel
  • PluginPostStatusInfo (it is covered by actual e2e test case)

The easiest way to test it is to use docker image for e2e tests and activate manually the following plugin: Gutenberg Test Plugin, Plugins API and ensure that they work as expected.

TODO

  • Extract plugin components into @wordpress/edit-post package.
    • PluginBlockSettingsMenuItem
    • PluginPostPublishPanel
    • PluginPostStatusInfo
    • PluginPrePublishPanel
    • PluginSidebarMoreMenuItem - this should be its own PR
    • PluginsMoreMenuGroup - this should be its own PR
    • PluginSidebar - this should be its own PR
    • PinnedPlugins - moved to @wordpress/plugins (Plugins: Move PinnedPlugins component #9312)
  • Rename PluginsBlockSettingsMenuGroup and move to editor package.
  • Update PluginBlockSettingsMenuItem to align with docs.
  • Extract parts of the store into @wordpress/edit-post package.
  • Update documentation
    • package README
    • store reference - this should be its own PR

@gziolo gziolo added [Status] In Progress Tracking issues with work in progress npm Packages Related to npm packages labels Aug 14, 2018
@gziolo gziolo self-assigned this Aug 14, 2018
@gziolo gziolo force-pushed the update/edit-post-package branch from 16b875b to f7fe9f6 Compare August 14, 2018 07:07
@gziolo gziolo requested a review from youknowriad August 14, 2018 08:26
@gziolo gziolo requested review from vindl, gwwar and aduth August 14, 2018 08:39
@youknowriad
Copy link
Contributor

So let's think about what each package is and see how this PR fits:

1- The editor package is the package exposing Components you can compose together to "implement" a block editor.

2- The edit-post package is the implementation of the editor in the WPAdmin's editor page.

In the current PR, we're exposing some parts of edit-post as an external API and If I understand properly, these APIs are meant to be used to "implement" other editor layouts. It's kind of weird to use an implementation to build another implementation. So What I think is:

  • If these components are usefull to build alternative implementations, maybe they can be moved to editor? unless we're just trying to gain some time and ultimately, these components will have specific implementations in the long run in which case, it's wrong to expose them entirely.
  • The only public API the edit-post module should have is initializeEditor( config ) which intializes the WPAdmin specific editor layout given some config.

I think it's probably too soon to make such a decision (whether these components are implementation details or should be reused across implementations). I'd be in favor of waiting for alternative implementations to emerge and see if they really need these components or it's just a gain of time.

@gziolo
Copy link
Member Author

gziolo commented Aug 14, 2018

The only public API the edit-post module should have is initializeEditor( config ) which intializes the WPAdmin specific editor layout given some config.

Let me disagree with this statement. All those components listed are part of the public API, too. They are already exposed as part of wp.editPost.* because there are essential for plugin developers to register their own plugin implementations. See:

screen shot 2018-08-14 at 11 08 14

BTW, I'm surprised reinitializeEditor is exposed, too.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

I tend to agree with @gziolo here. As plugin developers, we should have full access to edit-post and its innerworkings, so I'd expect they're part of the public API.

To be honest, I was surprised to see that there's no edit-post package back when I was working on Automattic/wp-calypso#26603 - in this one we had to still rely on the global wp variable.

I understand this is already an implementation of the editor, meant to be used in wp-admin, but I think this shouldn't be a strict limitation - we can always make edit-post work in a synthetic environment emulates wp-admin but is different than it - I recall working on custom dashboards before, and if I wanted to embed Gutenberg there, I'd definitely start from implementing it in a similar way to how it's done in wp-admin.


const { Fill: PluginsBlockSettingsMenuGroup, Slot } = createSlotFill( 'PluginsBlockSettingsMenuGroup' );

PluginsBlockSettingsMenuGroup.Slot = ( { fillProps } ) => {
Copy link
Member

Choose a reason for hiding this comment

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

It feels a little odd to have PluginsBlockSettingsMenuGroup and PluginBlockSettingsMenuItem being parts of different packages - could you please clarify the rationale behind that decision?

Copy link
Member Author

Choose a reason for hiding this comment

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

PluginBlockSettingsMenuItem is just one of the implementation of the PluginsBlockSettingsMenuGroup fill. In fact, it is a wrapper which enforces consistency across all menu items added in edit-post. My reasoning is that this slot is general purpose for all editor implementations. The same applies for other slots like InspectorControls and BlockControls - they only define the place where plugins can put they fills, they don't have any opinions. You could use them directly as it happens with blocks and their definitions, but using an abstraction will help us to apply those block settings only in edit-post context. It is still possible to use PluginsBlockSettingsMenuGroup fill directly, but this is going to be a bit more complex.

I'm happy to discuss it further, this is something that needs some more thought as this is something that might have implications in the future if we don't limit its usage by scoping it.

For the better context, we already did some exploration for edit-template page which would allow you to use blocks to build your own page template. This is why I'm not sold on the idea of having specialized implementations inside editor package as they might show up in the context some plugin developers didn't intend to. It's safer to assume all plugins are applied to edit-post as of today and move it up to editor in the future than the other way around.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, thanks for clarifying 👍

@gziolo gziolo requested review from abotteram and atimmer August 28, 2018 08:06
@gziolo gziolo force-pushed the update/edit-post-package branch from f2e23a8 to 9b859a8 Compare August 28, 2018 09:01
@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Aug 28, 2018
@gziolo
Copy link
Member Author

gziolo commented Aug 28, 2018

PluginSidebar depends on shared state with DocumentSidebar and BlockSidebar - to move forward we would probably have to decouple it or convert those 2 components to plugins to make it possible to use general-purpose state. That's why removed them from this PR with 9b859a8.

@gziolo gziolo added this to the 3.7 milestone Aug 28, 2018
@youknowriad youknowriad modified the milestones: 3.7, 3.8 Aug 30, 2018
@youknowriad youknowriad removed this from the 3.8 milestone Sep 5, 2018
@gziolo
Copy link
Member Author

gziolo commented Oct 11, 2018

@youknowriad took a different approach in #10429 which moves all code from edit-post to its own package. Closing this one as it is no longer relevant.

@gziolo gziolo closed this Oct 11, 2018
@gziolo gziolo deleted the update/edit-post-package branch October 11, 2018 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Packages Related to npm packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants