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

Extensibility: Add possibility to disable document settings panels registered by plugins #16900

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/edit-post/src/components/options-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
*/
import Section from './section';
import {
EnablePluginDocumentSettingPanelOption,
EnablePublishSidebarOption,
EnableTipsOption,
EnablePanelOption,
Expand All @@ -48,6 +49,7 @@ export function OptionsModal( { isModalActive, isViewable, closeModal } ) {
<EnableTipsOption label={ __( 'Enable Tips' ) } />
</Section>
<Section title={ __( 'Document Panels' ) }>
<EnablePluginDocumentSettingPanelOption.Slot />
{ isViewable && (
<EnablePanelOption label={ __( 'Permalink' ) } panelName="post-link" />
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* WordPress dependencies
*/
import { createSlotFill } from '@wordpress/components';

/**
* Internal dependencies
*/
import { EnablePanelOption } from './index';

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

const EnablePluginDocumentSettingPanelOption = ( { label, panelName } ) => (
<Fill>
<EnablePanelOption
label={ label }
panelName={ panelName }
/>
</Fill>
);

EnablePluginDocumentSettingPanelOption.Slot = Slot;

export default EnablePluginDocumentSettingPanelOption;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as EnableCustomFieldsOption } from './enable-custom-fields';
export { default as EnablePanelOption } from './enable-panel';
export { default as EnablePluginDocumentSettingPanelOption } from './enable-plugin-document-setting-panel';
export { default as EnablePublishSidebarOption } from './enable-publish-sidebar';
export { default as EnableTipsOption } from './enable-tips';
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`OptionsModal should match snapshot when the modal is active 1`] = `
<Section
title="Document Panels"
>
<EnablePluginDocumentSettingPanelOptionSlot />
<WithSelect(PostTaxonomies)
taxonomyWrapper={[Function]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ import { compose } from '@wordpress/compose';
import { withPluginContext } from '@wordpress/plugins';
import { withDispatch, withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { EnablePluginDocumentSettingPanelOption } from '../../options-modal/options';

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

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

Expand Down Expand Up @@ -104,4 +114,5 @@ const PluginDocumentSettingPanel = compose(
)( PluginDocumentSettingFill );

PluginDocumentSettingPanel.Slot = Slot;

export default PluginDocumentSettingPanel;