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

[Document Settings]: Add summary panel version 1 #39973

Merged
merged 17 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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
15 changes: 6 additions & 9 deletions packages/e2e-tests/specs/editor/plugins/meta-boxes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,16 @@ describe( 'Meta boxes', () => {

// Open the excerpt panel.
await openDocumentSettingsSidebar();
const excerptButton = await findSidebarPanelToggleButtonWithTitle(
'Excerpt'
const summaryButton = await findSidebarPanelToggleButtonWithTitle(
'Summary'
);
if ( excerptButton ) {
await excerptButton.click( 'button' );
if ( summaryButton ) {
await summaryButton.click( 'button' );
}

await page.waitForSelector( '.editor-post-excerpt textarea' );
await page.waitForSelector( '.editor-post-excerpt p' );

await page.type(
'.editor-post-excerpt textarea',
'Explicitly set excerpt.'
);
await page.type( '.editor-post-excerpt p', 'Explicitly set excerpt.' );

await publishPost();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ describe( 'new editor filtered state', () => {

// open the sidebar, we want to see the excerpt.
await openDocumentSettingsSidebar();
const excerptButton = await findSidebarPanelToggleButtonWithTitle(
'Excerpt'
const summaryButton = await findSidebarPanelToggleButtonWithTitle(
'Summary'
);
if ( excerptButton ) {
await excerptButton.click( 'button' );
if ( summaryButton ) {
await summaryButton.click( 'button' );
}
const excerpt = await page.$eval(
'.editor-post-excerpt textarea',
'.editor-post-excerpt p',
( element ) => element.innerHTML
);

Expand Down
68 changes: 49 additions & 19 deletions packages/e2e-tests/specs/editor/various/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ const SIDEBAR_SELECTOR = '.edit-post-sidebar';
const ACTIVE_SIDEBAR_TAB_SELECTOR = '.edit-post-sidebar__panel-tab.is-active';
const ACTIVE_SIDEBAR_BUTTON_TEXT = 'Post';

const openSidebarPanelWithTitle = async ( title ) => {
const panel = await page.waitForXPath(
`//div[contains(@class,"edit-post-sidebar")]//button[@class="components-button components-panel__body-toggle"][contains(text(),"${ title }")]`
);
const expanded = await page.evaluate(
( element ) => element.getAttribute( 'aria-expanded' ),
panel
);
if ( expanded === 'false' ) {
return panel.click();
}
};

describe( 'Sidebar', () => {
afterEach( () => {
disableFocusLossObservation();
Expand Down Expand Up @@ -123,25 +136,23 @@ describe( 'Sidebar', () => {
await createNewPost();
await enableFocusLossObservation();
await openDocumentSettingsSidebar();

expect( await findSidebarPanelWithTitle( 'Categories' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Tags' ) ).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Featured image' )
).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Excerpt' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Discussion' ) ).toBeDefined();
expect(
await findSidebarPanelWithTitle( 'Status & visibility' )
).toBeDefined();
const panelNames = [
'Summary',
'Categories',
'Tags',
'Discussion',
'Status & visibility',
];
const panels = await Promise.all(
panelNames.map( findSidebarPanelWithTitle )
);
panels.forEach( ( panel ) => expect( panel ).toBeDefined() );

await page.evaluate( () => {
const { removeEditorPanel } = wp.data.dispatch( 'core/edit-post' );

removeEditorPanel( 'taxonomy-panel-category' );
removeEditorPanel( 'taxonomy-panel-post_tag' );
removeEditorPanel( 'featured-image' );
removeEditorPanel( 'post-excerpt' );
removeEditorPanel( 'discussion-panel' );
removeEditorPanel( 'post-status' );
} );
Expand All @@ -156,17 +167,36 @@ describe( 'Sidebar', () => {
expect( await page.$x( getPanelToggleSelector( 'Tags' ) ) ).toEqual(
[]
);
expect(
await page.$x( getPanelToggleSelector( 'Featured image' ) )
).toEqual( [] );
expect( await page.$x( getPanelToggleSelector( 'Excerpt' ) ) ).toEqual(
[]
);
expect(
await page.$x( getPanelToggleSelector( 'Discussion' ) )
).toEqual( [] );
expect(
await page.$x( getPanelToggleSelector( 'Status & visibility' ) )
).toEqual( [] );
} );
describe( 'Summary panel', () => {
beforeEach( async () => {
await createNewPost();
await enableFocusLossObservation();
await openDocumentSettingsSidebar();
} );
it( 'should show all elements', async () => {
await openSidebarPanelWithTitle( 'Summary' );
const getSelector = ( cssClass ) =>
`//div[contains(@class, "edit-post-sidebar")]//div[contains(@class, "edit-post-post-summary")]//*[contains(@class, "${ cssClass }")]`;
const panelElements = await Promise.all(
[
'editor-post-featured-image',
'edit-post-post-title',
'editor-post-excerpt',
'post-author-selector',
].map( ( target ) =>
page.waitForXPath( getSelector( target ) )
)
);
panelElements.forEach( ( element ) =>
expect( element ).toBeDefined()
);
} );
} );
} );
61 changes: 9 additions & 52 deletions packages/edit-post/src/components/sidebar/featured-image/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
/**
* External dependencies
*/
import { get, partial } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import {
PostFeaturedImage,
PostFeaturedImageCheck,
store as editorStore,
} from '@wordpress/editor';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { PostFeaturedImage, PostFeaturedImageCheck } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -27,48 +14,18 @@ import { store as editPostStore } from '../../../store';
*/
const PANEL_NAME = 'featured-image';

function FeaturedImage( { isEnabled, isOpened, postType, onTogglePanel } ) {
export default function FeaturedImage() {
const isEnabled = useSelect(
( select ) =>
select( editPostStore ).isEditorPanelEnabled( PANEL_NAME ),
[]
);
if ( ! isEnabled ) {
return null;
}

return (
<PostFeaturedImageCheck>
<PanelBody
title={ get(
postType,
[ 'labels', 'featured_image' ],
__( 'Featured image' )
) }
opened={ isOpened }
onToggle={ onTogglePanel }
>
<PostFeaturedImage />
</PanelBody>
<PostFeaturedImage />
</PostFeaturedImageCheck>
);
}

const applyWithSelect = withSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const { getPostType } = select( coreStore );
const { isEditorPanelEnabled, isEditorPanelOpened } = select(
editPostStore
);

return {
postType: getPostType( getEditedPostAttribute( 'type' ) ),
isEnabled: isEditorPanelEnabled( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
};
} );

const applyWithDispatch = withDispatch( ( dispatch ) => {
const { toggleEditorPanelOpened } = dispatch( editPostStore );

return {
onTogglePanel: partial( toggleEditorPanelOpened, PANEL_NAME ),
};
} );

export default compose( applyWithSelect, applyWithDispatch )( FeaturedImage );
39 changes: 8 additions & 31 deletions packages/edit-post/src/components/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import {
PostExcerpt as PostExcerptForm,
PostExcerptCheck,
} from '@wordpress/editor';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -20,38 +17,18 @@ import { store as editPostStore } from '../../../store';
*/
const PANEL_NAME = 'post-excerpt';

function PostExcerpt( { isEnabled, isOpened, onTogglePanel } ) {
export default function PostExcerpt( { isMinimal } ) {
const isEnabled = useSelect(
( select ) =>
select( editPostStore ).isEditorPanelEnabled( PANEL_NAME ),
[]
);
if ( ! isEnabled ) {
return null;
}

return (
<PostExcerptCheck>
<PanelBody
title={ __( 'Excerpt' ) }
opened={ isOpened }
onToggle={ onTogglePanel }
>
<PostExcerptForm />
</PanelBody>
<PostExcerptForm isMinimal={ isMinimal } />
</PostExcerptCheck>
);
}

export default compose( [
withSelect( ( select ) => {
return {
isEnabled: select( editPostStore ).isEditorPanelEnabled(
PANEL_NAME
),
isOpened: select( editPostStore ).isEditorPanelOpened( PANEL_NAME ),
};
} ),
withDispatch( ( dispatch ) => ( {
onTogglePanel() {
return dispatch( editPostStore ).toggleEditorPanelOpened(
PANEL_NAME
);
},
} ) ),
] )( PostExcerpt );
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import PostVisibility from '../post-visibility';
import PostTrash from '../post-trash';
import PostSchedule from '../post-schedule';
import PostSticky from '../post-sticky';
import PostAuthor from '../post-author';
import PostSlug from '../post-slug';
import PostFormat from '../post-format';
import PostPendingStatus from '../post-pending-status';
Expand Down Expand Up @@ -42,7 +41,6 @@ function PostStatus( { isOpened, onTogglePanel } ) {
<PostSticky />
<PostPendingStatus />
<PostSlug />
<PostAuthor />
{ fills }
<PostTrash />
</>
Expand Down
47 changes: 47 additions & 0 deletions packages/edit-post/src/components/sidebar/post-summary/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { PanelBody, PanelRow } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { PostAuthor } from '@wordpress/editor';

/**
* Internal dependencies
*/
import PostTitle from '../post-title';
import FeaturedImage from '../featured-image';
import PostExcerpt from '../post-excerpt';
import { store as editPostStore } from '../../../store';

/**
* Module Constants
*/
const PANEL_NAME = 'post-summary';

function PostSummary() {
const isOpened = useSelect(
( select ) => select( editPostStore ).isEditorPanelOpened( PANEL_NAME ),
[]
);
const { toggleEditorPanelOpened } = useDispatch( editPostStore );
return (
<PanelBody
className="edit-post-post-summary"
title={ __( 'Summary' ) }
opened={ isOpened }
onToggle={ () => toggleEditorPanelOpened( PANEL_NAME ) }
>
<FeaturedImage />
<PanelRow>
<PostTitle />
</PanelRow>
<PostExcerpt isMinimal />
<PanelRow>
<PostAuthor labelPosition="side" />
</PanelRow>
</PanelBody>
);
}

export default PostSummary;
27 changes: 27 additions & 0 deletions packages/edit-post/src/components/sidebar/post-title/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import { PlainText } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { store as editorStore } from '@wordpress/editor';
import { useSelect, useDispatch } from '@wordpress/data';

function PostTitle() {
const { editPost } = useDispatch( editorStore );
const postTitle = useSelect(
( select ) => select( editorStore ).getEditedPostAttribute( 'title' ),
[]
);
return (
<PlainText
className="edit-post-post-title"
tagName="span"
placeholder={ __( 'Add title' ) }
value={ postTitle }
onChange={ ( title ) => editPost( { title } ) }
__experimentalVersion={ 2 }
/>
);
}

export default PostTitle;
17 changes: 17 additions & 0 deletions packages/edit-post/src/components/sidebar/post-title/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.edit-post-post-title {
font-size: 16px;
line-height: 1.6;
font-weight: 500;
margin: $grid-unit-15 0;

// Focus style
width: 100%;
border-radius: $radius-block-ui - $border-width;

&:focus-within {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
}
}
Loading