Skip to content

Commit

Permalink
Editor: Update and simplify the Post Summary and Post Card section in…
Browse files Browse the repository at this point in the history
… the document sidebar (#61624)

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
4 people authored May 14, 2024
1 parent 70576a7 commit 2010994
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 178 deletions.
124 changes: 39 additions & 85 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import {
Icon,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalText as Text,
PanelBody,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand All @@ -25,89 +18,50 @@ import { store as editorStore } from '../../store';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
} from '../../store/constants';
import { PrivatePostExcerptPanel } from '../post-excerpt/panel';
import PostLastEditedPanel from '../post-last-edited-panel';
import { unlock } from '../../lock-unlock';
import TemplateAreas from '../template-areas';

export default function PostCardPanel( { className, actions } ) {
const { title, showPostContentPanels, icon, postType } = useSelect(
( select ) => {
const {
getEditedPostAttribute,
getCurrentPostType,
getCurrentPostId,
__experimentalGetTemplateInfo,
} = select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const _type = getCurrentPostType();
const _id = getCurrentPostId();
const _record = getEditedEntityRecord( 'postType', _type, _id );
const _templateInfo =
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(
_type
) && __experimentalGetTemplateInfo( _record );
return {
title:
_templateInfo?.title || getEditedPostAttribute( 'title' ),
id: _id,
postType: _type,
icon: unlock( select( editorStore ) ).getPostIcon( _type, {
area: _record?.area,
} ),
// Post excerpt panel and Last Edited info are rendered in different place depending on the post type.
// So we cannot make this check inside the PostExcerpt or PostLastEditedPanel component based on the current edited entity.
showPostContentPanels: [
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
].includes( _type ),
};
},
[]
);
export default function PostCardPanel( { actions } ) {
const { title, icon } = useSelect( ( select ) => {
const {
getEditedPostAttribute,
getCurrentPostType,
getCurrentPostId,
__experimentalGetTemplateInfo,
} = select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const _type = getCurrentPostType();
const _id = getCurrentPostId();
const _record = getEditedEntityRecord( 'postType', _type, _id );
const _templateInfo =
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes( _type ) &&
__experimentalGetTemplateInfo( _record );
return {
title: _templateInfo?.title || getEditedPostAttribute( 'title' ),
icon: unlock( select( editorStore ) ).getPostIcon( _type, {
area: _record?.area,
} ),
};
}, [] );
return (
<PanelBody>
<div
className={ clsx( 'editor-post-card-panel', className, {
'has-description': showPostContentPanels,
} ) }
<div className="editor-post-card-panel">
<HStack
spacing={ 2 }
className="editor-post-card-panel__header"
align="flex-start"
>
<HStack
spacing={ 2 }
className="editor-post-card-panel__header"
align="flex-start"
<Icon className="editor-post-card-panel__icon" icon={ icon } />
<Text
numberOfLines={ 2 }
truncate
className="editor-post-card-panel__title"
weight={ 500 }
as="h2"
>
<Icon
className="editor-post-card-panel__icon"
icon={ icon }
/>
<Text
numberOfLines={ 2 }
truncate
className="editor-post-card-panel__title"
weight={ 500 }
as="h2"
>
{ title ? decodeEntities( title ) : __( 'No Title' ) }
</Text>
{ actions }
</HStack>
<VStack className="editor-post-card-panel__content">
{ showPostContentPanels && (
<VStack
className="editor-post-card-panel__description"
spacing={ 2 }
>
<PrivatePostExcerptPanel />
<PostLastEditedPanel />
</VStack>
) }
{ postType === TEMPLATE_POST_TYPE && <TemplateAreas /> }
</VStack>
</div>
</PanelBody>
{ title ? decodeEntities( title ) : __( 'No Title' ) }
</Text>
{ actions }
</HStack>
</div>
);
}
19 changes: 19 additions & 0 deletions packages/editor/src/components/post-panel-section/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* External dependencies
*/
import clsx from 'clsx';

/**
* WordPress dependencies
*/
import { __experimentalVStack as VStack } from '@wordpress/components';

function PostPanelSection( { className, children } ) {
return (
<VStack className={ clsx( 'editor-post-panel__section', className ) }>
{ children }
</VStack>
);
}

export default PostPanelSection;
3 changes: 3 additions & 0 deletions packages/editor/src/components/post-panel-section/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.editor-post-panel__section {
padding: $grid-unit-20;
}
12 changes: 1 addition & 11 deletions packages/editor/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import PageAttributesPanel from '../page-attributes/panel';
import PatternOverridesPanel from '../pattern-overrides-panel';
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
import PluginSidebar from '../plugin-sidebar';
import PostActions from '../post-actions';
import PostCardPanel from '../post-card-panel';
import PostDiscussionPanel from '../post-discussion/panel';
import PostLastRevisionPanel from '../post-last-revision/panel';
import PostSummary from './post-summary';
Expand Down Expand Up @@ -58,7 +56,6 @@ const SidebarContent = ( {
renderingMode,
onActionPerformed,
extraPanels,
showSummary = true,
} ) => {
const tabListRef = useRef( null );
// Because `PluginSidebar` renders a `ComplementaryArea`, we
Expand Down Expand Up @@ -115,14 +112,7 @@ const SidebarContent = ( {
>
<Tabs.Context.Provider value={ tabsContextValue }>
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
<PostCardPanel
actions={
<PostActions
onActionPerformed={ onActionPerformed }
/>
}
/>
{ showSummary && <PostSummary /> }
<PostSummary onActionPerformed={ onActionPerformed } />
<PluginDocumentSettingPanel.Slot />
{ renderingMode !== 'post-only' && (
<TemplateContentPanel />
Expand Down
128 changes: 57 additions & 71 deletions packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,102 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
PanelBody,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __experimentalVStack as VStack } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PluginPostStatusInfo from '../plugin-post-status-info';
import PostActions from '../post-actions';
import PostAuthorPanel from '../post-author/panel';
import PostCardPanel from '../post-card-panel';
import PostContentInformation from '../post-content-information';
import { PrivatePostExcerptPanel as PostExcerptPanel } from '../post-excerpt/panel';
import PostFeaturedImagePanel from '../post-featured-image/panel';
import PostFormatPanel from '../post-format/panel';
import PostLastEditedPanel from '../post-last-edited-panel';
import PostPanelSection from '../post-panel-section';
import PostSchedulePanel from '../post-schedule/panel';
import PostSlugPanel from '../post-slug/panel';
import PostStatusPanel from '../post-status';
import PostStickyPanel from '../post-sticky';
import PostSyncStatus from '../post-sync-status';
import PostTemplatePanel from '../post-template/panel';
import PostTrashPanel from '../post-trash/panel';
import PostURLPanel from '../post-url/panel';
import { store as editorStore } from '../../store';
import { PATTERN_POST_TYPE } from '../../store/constants';
import {
NAVIGATION_POST_TYPE,
PATTERN_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
} from '../../store/constants';
import TemplateAreas from '../template-areas';

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

export default function PostSummary() {
const { isOpened, isRemoved, isPattern } = useSelect( ( select ) => {
export default function PostSummary( { onActionPerformed } ) {
const { isRemovedPostStatusPanel, postType } = useSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
const {
isEditorPanelRemoved,
isEditorPanelOpened,
getCurrentPostType,
} = select( editorStore );
const postType = getCurrentPostType();
const { isEditorPanelRemoved, getCurrentPostType } =
select( editorStore );
return {
isRemoved: isEditorPanelRemoved( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
// Post excerpt panel is rendered in different place depending on the post type.
// So we cannot make this check inside the PostExcerpt component based on the current edited entity.
isPattern: postType === PATTERN_POST_TYPE,
isRemovedPostStatusPanel: isEditorPanelRemoved( PANEL_NAME ),
postType: getCurrentPostType(),
};
}, [] );
const { toggleEditorPanelOpened } = useDispatch( editorStore );

if ( isRemoved ) {
return null;
}
const isPattern = postType === PATTERN_POST_TYPE;
const isTemplate = postType === TEMPLATE_POST_TYPE;
const isTemplatePart = postType === TEMPLATE_PART_POST_TYPE;
const isNavigation = postType === NAVIGATION_POST_TYPE;

return (
<PanelBody
title={ __( 'Summary' ) }
opened={ isOpened }
onToggle={ () => toggleEditorPanelOpened( PANEL_NAME ) }
>
<PostPanelSection className="editor-post-summary">
<PluginPostStatusInfo.Slot>
{ ( fills ) => (
<>
{ ! isPattern && (
<VStack
spacing={ 3 }
// TODO: this needs to be consolidated with the panel in site editor, when we unify them.
style={ { marginBlockEnd: '24px' } }
>
<PostFeaturedImagePanel
withPanelBody={ false }
/>
<PostExcerptPanel />
<VStack spacing={ 1 }>
<PostContentInformation />
<PostLastEditedPanel />
</VStack>
<VStack spacing={ 4 }>
<PostCardPanel
actions={
<PostActions
onActionPerformed={ onActionPerformed }
/>
}
/>
<PostFeaturedImagePanel withPanelBody={ false } />
<PostExcerptPanel />
<VStack spacing={ 1 }>
<PostContentInformation />
<PostLastEditedPanel />
</VStack>
) }
<VStack
spacing={ 1 }
style={ { marginBlockEnd: '12px' } }
>
<PostStatusPanel />
<PostSchedulePanel />
<PostTemplatePanel />
<PostURLPanel />
<PostSyncStatus />
{ ! isRemovedPostStatusPanel && (
<VStack spacing={ 2 }>
<VStack spacing={ 1 }>
<PostStatusPanel />
<PostSchedulePanel />
<PostTemplatePanel />
<PostURLPanel />
<PostSyncStatus />
</VStack>
<PostStickyPanel />
<PostFormatPanel />
<PostAuthorPanel />
{ isTemplate && <TemplateAreas /> }
{ fills }
{ ! isPattern &&
! isTemplate &&
! isTemplatePart &&
! isNavigation && <PostTrashPanel /> }
</VStack>
) }
</VStack>
<PostStickyPanel />
<PostFormatPanel />
<PostSlugPanel />
<PostAuthorPanel />
{ fills }
{ ! isPattern && (
<HStack
style={ {
marginTop: '16px',
} }
>
<PostTrashPanel />
</HStack>
) }
</>
) }
</PluginPostStatusInfo.Slot>
</PanelBody>
</PostPanelSection>
);
}
4 changes: 4 additions & 0 deletions packages/editor/src/components/sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
}
}
}

.editor-post-summary .components-v-stack:empty {
display: none;
}
1 change: 0 additions & 1 deletion packages/editor/src/components/template-areas/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.editor-template-areas {
margin-top: $grid-unit-20;
&__list {
margin: 0;
> li {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import "./components/post-last-revision/style.scss";
@import "./components/post-locked-modal/style.scss";
@import "./components/post-panel-row/style.scss";
@import "./components/post-panel-section/style.scss";
@import "./components/post-publish-panel/style.scss";
@import "./components/post-saved-state/style.scss";
@import "./components/post-schedule/style.scss";
Expand Down
Loading

0 comments on commit 2010994

Please sign in to comment.