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

Introduces PluginSettingsSidebar slotfill to the Document sidebar. #13361

Merged
merged 62 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
10f2155
Merge remote-tracking branch 'upstream/master'
Oct 25, 2018
1e71527
Merge branch 'master' of github.com:ryanwelcher/gutenberg
Oct 26, 2018
1f84880
Merge remote-tracking branch 'upstream/master'
Oct 29, 2018
1b8abb5
Merge remote-tracking branch 'upstream/master'
Oct 30, 2018
4e157e3
Merge remote-tracking branch 'upstream/master'
Jan 17, 2019
c16ceec
Create new file for the plugin
Jan 17, 2019
ffe0dc7
Adding new slotfill
Jan 17, 2019
352783b
Adds tests
Jan 17, 2019
ed2fe85
Ensuring that the slot wraps in a PanelBody and updates tests
Jan 17, 2019
dbdb17b
Adds unintentionally deleted snapshot
Jan 17, 2019
80d16f9
Merge remote-tracking branch 'upstream/master'
Feb 12, 2019
44df501
Merge remote-tracking branch 'upstream/master'
Feb 12, 2019
60ecdbf
Merge remote-tracking branch 'upstream/master'
Apr 22, 2019
becc99e
Merge remote-tracking branch 'upstream/master'
Apr 29, 2019
baabb3d
Merge remote-tracking branch 'upstream/master'
May 6, 2019
80da436
Merge branch 'master' into feature/settings-panel-slot
May 6, 2019
0c10e9e
Changes as per Riad
May 6, 2019
7875f9c
Merge remote-tracking branch 'upstream/master'
May 6, 2019
4c0c834
Merge branch 'master' into feature/settings-panel-slot
May 6, 2019
42c74b7
Exporting the new slot on the EditPost global
May 6, 2019
739c0ad
Adds e2e test for the new slot
May 6, 2019
4c4641a
Fixes PHPCS error with whitespace
May 6, 2019
b41b60a
Updates to whitespace and docs as per gziolo
May 7, 2019
7f84a0e
Docs updates
May 7, 2019
47b6603
Merge remote-tracking branch 'upstream/master'
May 7, 2019
86b9774
Merge branch 'master' into feature/settings-panel-slot
May 7, 2019
5fde5a1
Uses correct slotfill.
May 20, 2019
d406e81
Merge remote-tracking branch 'upstream/master'
May 20, 2019
3dd3031
Merge branch 'master' into feature/settings-panel-slot
May 20, 2019
ae92d91
Merge remote-tracking branch 'upstream/master'
May 22, 2019
88e5faf
Merge remote-tracking branch 'upstream/master'
May 23, 2019
642b80f
Merge remote-tracking branch 'upstream/master'
May 24, 2019
25a396e
Merge remote-tracking branch 'upstream/master'
Jun 4, 2019
356397f
Merge branch 'master' into feature/settings-panel-slot
Jun 4, 2019
fd8f007
Simplifies the Slot render
Jun 4, 2019
28984f1
Updates Slot show the icon if passed as part of register_plugin. Ensu…
Jun 4, 2019
11e6281
Updates e2e tests
Jun 4, 2019
ac92347
Merge remote-tracking branch 'upstream/master'
Jun 13, 2019
c15441e
Merge branch 'master' into feature/settings-panel-slot
Jun 13, 2019
c56219f
Updates src order
Jun 13, 2019
628436b
Updates docs
Jun 13, 2019
7d83a36
Updated docs
Jun 13, 2019
26bca28
Removes unneeded mock and component
Jun 13, 2019
cca3571
Fixes misnamed export and adds toggle handling to the slot
Jun 15, 2019
8b98804
Cleaning up the Slot properties
Jun 15, 2019
2bc05de
Doc updates
Jun 15, 2019
6b57e00
Doc updates 2: Docs harder
Jun 15, 2019
797ced8
Adds logic to allow removal of panel using removeEditorPanel
Jun 15, 2019
30e4692
Merge remote-tracking branch 'upstream/master'
Jun 15, 2019
b6f8ab6
Merge branch 'master' into feature/settings-panel-slot
Jun 15, 2019
f4f25ef
Removes snapshot tests due to strange failures
Jun 15, 2019
b1954c5
Updates e2e test
Jun 15, 2019
c78138a
Merge remote-tracking branch 'upstream/master'
Jun 21, 2019
1b5c6f2
Merge branch 'master' into feature/settings-panel-slot
Jun 21, 2019
3ccdbfc
Explicitly using props instead of ...props
Jun 21, 2019
f71ae7d
Docs updated and correctly naming import
Jun 21, 2019
b1e1f7f
Updates tests
Jun 21, 2019
1744eec
Fixes doc indents
Jul 1, 2019
9e36834
Merge remote-tracking branch 'upstream/master'
Jul 1, 2019
2a7f05c
Merge branch 'master' into feature/settings-panel-slot
Jul 1, 2019
7c8a6ab
Updates e2e test to use snapshot
Jul 1, 2019
ddb5028
Updates snapshot for plugins
Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/e2e-tests/plugins/plugins-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ function enqueue_plugins_api_plugin_scripts() {
filemtime( plugin_dir_path( __FILE__ ) . 'plugins-api/annotations-sidebar.js' ),
true
);

wp_enqueue_script(
'gutenberg-test-plugins-api-document-setting',
plugins_url( 'plugins-api/document-setting.js', __FILE__ ),
array(
'wp-edit-post',
'wp-element',
'wp-i18n',
'wp-plugins',
),
filemtime( plugin_dir_path( __FILE__ ) . 'plugins-api/document-setting.js' ),
true
);
}

add_action( 'init', 'enqueue_plugins_api_plugin_scripts' );
21 changes: 21 additions & 0 deletions packages/e2e-tests/plugins/plugins-api/document-setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
( function() {
var el = wp.element.createElement;
var __ = wp.i18n.__;
var registerPlugin = wp.plugins.registerPlugin;
var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;

function MyDocumentSettingPlugin() {
return el(
PluginDocumentSettingPanel,
{
className: 'my-document-setting-plugin',
title: 'My Custom Panel'
},
__( 'My Document Setting Panel' )
);
}

registerPlugin( 'my-document-setting-plugin', {
render: MyDocumentSettingPlugin
} );
} )();
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Using Plugins API Document Setting Custom Panel Should render a custom panel inside Document Setting sidebar 1`] = `
"
My Custom Panel
"
`;

exports[`Using Plugins API Sidebar Should open plugins sidebar using More Menu item and render content 1`] = `"<div class=\\"components-panel__header edit-post-sidebar-header__small\\"><span class=\\"edit-post-sidebar-header__title\\">(no title)</span><button type=\\"button\\" aria-label=\\"Close plugin\\" class=\\"components-button components-icon-button\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" class=\\"dashicon dashicons-no-alt\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></div><div class=\\"components-panel__header edit-post-sidebar-header\\"><strong>Sidebar title plugin</strong><button type=\\"button\\" aria-label=\\"Unpin from toolbar\\" aria-expanded=\\"true\\" class=\\"components-button components-icon-button is-toggled\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" class=\\"dashicon dashicons-star-filled\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\"><path d=\\"M10 1l3 6 6 .75-4.12 4.62L16 19l-6-3-6 3 1.13-6.63L1 7.75 7 7z\\"></path></svg></button><button type=\\"button\\" aria-label=\\"Close plugin\\" class=\\"components-button components-icon-button\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" class=\\"dashicon dashicons-no-alt\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></div><div class=\\"components-panel\\"><div class=\\"components-panel__body is-opened\\"><div class=\\"components-panel__row\\"><label for=\\"title-plain-text\\">Title:</label><textarea class=\\"editor-plain-text block-editor-plain-text\\" id=\\"title-plain-text\\" placeholder=\\"(no title)\\" rows=\\"1\\" style=\\"overflow: hidden; overflow-wrap: break-word; resize: none; height: 18px;\\"></textarea></div><div class=\\"components-panel__row\\"><button type=\\"button\\" class=\\"components-button is-button is-primary\\">Reset</button></div></div></div>"`;
8 changes: 8 additions & 0 deletions packages/e2e-tests/specs/plugins/plugins-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ describe( 'Using Plugins API', () => {
expect( pluginSidebarClosed ).toBeNull();
} );
} );

describe( 'Document Setting Custom Panel', () => {
it( 'Should render a custom panel inside Document Setting sidebar', async () => {
await openDocumentSettingsSidebar();
const pluginDocumentSettingsText = await page.$eval( '.edit-post-sidebar .my-document-setting-plugin', ( el ) => el.innerText );
expect( pluginDocumentSettingsText ).toMatchSnapshot();
} );
} );
} );
54 changes: 54 additions & 0 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,60 @@ _Returns_

- `WPElement`: The WPElement to be rendered.

<a name="PluginDocumentSettingPanel" href="#PluginDocumentSettingPanel">#</a> **PluginDocumentSettingPanel**

Renders items below the Status & Availability panel in the Document Sidebar.

_Usage_

```js
// Using ES5 syntax
var el = wp.element.createElement;
var __ = wp.i18n.__;
var registerPlugin = wp.plugins.registerPlugin;
var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;

function MyDocumentSettingPlugin() {
return el(
PluginDocumentSettingPanel,
{
className: 'my-document-setting-plugin',
},
__( 'My Document Setting Panel' )
);
}

registerPlugin( 'my-document-setting-plugin', {
render: MyDocumentSettingPlugin
} );
```

```jsx
// Using ESNext syntax
const { registerPlugin } = wp.plugins;
const { PluginDocumentSettingPanel } = wp.editPost;

const MyDocumentSettingTest = () => (
gziolo marked this conversation as resolved.
Show resolved Hide resolved
<PluginDocumentSettingPanel className="my-document-setting-plugin">
<p>My Document Setting Panel</p>
</PluginDocumentSetting>
);

registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );
```

_Parameters_

- _props_ `Object`: Component properties.
- _props.name_ `[string]`: The machine-friendly name for the panel.
- _props.className_ `[string]`: An optional class name added to the row.
- _props.title_ `[string]`: The title of the panel
- _props.icon_ `[(string|Element)]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.

_Returns_

- `WPElement`: The WPElement to be rendered.

<a name="PluginMoreMenuItem" href="#PluginMoreMenuItem">#</a> **PluginMoreMenuItem**

Renders a menu item in `Plugins` group in `More Menu` drop down, and can be used to as a button or link depending on the props provided.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Defines as extensibility slot for the Settings sidebar
*/

/**
* WordPress dependencies
*/
import { createSlotFill, PanelBody } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { withDispatch, withSelect } from '@wordpress/data';

export const { Fill, Slot } = createSlotFill( 'PluginDocumentSettingPanel' );

const PluginDocumentSettingFill = ( { isEnabled, opened, onToggle, className, title, icon, children } ) => {
if ( ! isEnabled ) {
return null;
}
return (
<Fill>
<PanelBody
className={ className }
title={ title }
icon={ icon }
opened={ opened }
onToggle={ onToggle }
>
{ children }
</PanelBody>
</Fill>
);
};

/**
* Renders items below the Status & Availability panel in the Document Sidebar.
*
* @param {Object} props Component properties.
* @param {string} [props.name] The machine-friendly name for the panel.
* @param {string} [props.className] An optional class name added to the row.
* @param {string} [props.title] The title of the panel
Copy link
Member

Choose a reason for hiding this comment

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

We should also include icon which is now supported with the default coming from the plugin's definition. This is how it's documented for the PluginSidebar:

* @param {string|Element} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

* @param {string|Element} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element, to be rendered when the sidebar is pinned to toolbar.
*
* @example <caption>ES5</caption>
* ```js
* // Using ES5 syntax
* var el = wp.element.createElement;
* var __ = wp.i18n.__;
* var registerPlugin = wp.plugins.registerPlugin;
* var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;
*
* function MyDocumentSettingPlugin() {
* return el(
* PluginDocumentSettingPanel,
* {
* className: 'my-document-setting-plugin',
* },
* __( 'My Document Setting Panel' )
* );
* }
*
* registerPlugin( 'my-document-setting-plugin', {
* render: MyDocumentSettingPlugin
* } );
* ```
*
* @example <caption>ESNext</caption>
* ```jsx
* // Using ESNext syntax
* const { registerPlugin } = wp.plugins;
* const { PluginDocumentSettingPanel } = wp.editPost;
*
* const MyDocumentSettingTest = () => (
* <PluginDocumentSettingPanel className="my-document-setting-plugin">
* <p>My Document Setting Panel</p>
* </PluginDocumentSetting>
* );
*
* registerPlugin( 'document-setting-test', { render: MyDocumentSettingTest } );
* ```
*
* @return {WPElement} The WPElement to be rendered.
*/
const PluginDocumentSettingPanel = compose(
withPluginContext( ( context, ownProps ) => {
return {
icon: ownProps.icon || context.icon,
panelName: `${ context.name }/${ ownProps.name }`,
};
} ),
withSelect( ( select, { panelName } ) => {
return (
{
opened: select( 'core/edit-post' ).isEditorPanelOpened( panelName ),
isEnabled: select( 'core/edit-post' ).isEditorPanelEnabled( panelName ),
}
);
} ),
withDispatch( ( dispatch, { panelName } ) => ( {
onToggle() {
return dispatch( 'core/edit-post' ).toggleEditorPanelOpened( panelName );
},
} ) ),
)( PluginDocumentSettingFill );

PluginDocumentSettingPanel.Slot = Slot;
export default PluginDocumentSettingPanel;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import PostLink from '../post-link';
import DiscussionPanel from '../discussion-panel';
import PageAttributes from '../page-attributes';
import MetaBoxes from '../../meta-boxes';
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';

const SettingsSidebar = ( { sidebarName } ) => (
<Sidebar
Expand All @@ -31,6 +32,7 @@ const SettingsSidebar = ( { sidebarName } ) => (
{ sidebarName === 'edit-post/document' && (
<>
<PostStatus />
<PluginDocumentSettingPanel.Slot />
<LastRevision />
<PostLink />
<PostTaxonomies />
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function initializeEditor( id, postType, postId, settings, initialEdits )
}

export { default as PluginBlockSettingsMenuItem } from './components/block-settings-menu/plugin-block-settings-menu-item';
export { default as PluginDocumentSettingPanel } from './components/sidebar/plugin-document-setting-panel';
Copy link
Contributor

Choose a reason for hiding this comment

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

@aduth any thougs on the naming?

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine to me as proposed.

export { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item';
export { default as PluginPostPublishPanel } from './components/sidebar/plugin-post-publish-panel';
export { default as PluginPostStatusInfo } from './components/sidebar/plugin-post-status-info';
Expand Down