Skip to content

Commit

Permalink
DataViews Quick Edit: Add Post Card to the quick edit panel (#64365)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored and getdave committed Aug 14, 2024
1 parent 24c5f44 commit fd68da5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
7 changes: 7 additions & 0 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import {
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useState, useMemo } from '@wordpress/element';
import { privateApis as editorPrivateApis } from '@wordpress/editor';

/**
* Internal dependencies
*/
import Page from '../page';
import usePostFields from '../post-fields';
import { unlock } from '../../lock-unlock';

const { PostCardPanel } = unlock( editorPrivateApis );

function PostEditForm( { postType, postId } ) {
const ids = useMemo( () => postId.split( ',' ), [ postId ] );
Expand Down Expand Up @@ -76,6 +80,9 @@ function PostEditForm( { postType, postId } ) {
const isUpdateDisabled = ! isItemValid( itemWithEdits, fields, form );
return (
<VStack as="form" onSubmit={ onSubmit } spacing={ 4 }>
{ ids.length === 1 && (
<PostCardPanel postType={ postType } postId={ ids[ 0 ] } />
) }
<DataForm
data={ itemWithEdits }
fields={ fields }
Expand Down
42 changes: 17 additions & 25 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,47 @@ import {
} from '../../store/constants';
import { unlock } from '../../lock-unlock';

export default function PostCardPanel( { actions } ) {
export default function PostCardPanel( { postType, postId, actions } ) {
const { isFrontPage, isPostsPage, title, icon, isSync } = useSelect(
( select ) => {
const {
getEditedPostAttribute,
getCurrentPostType,
getCurrentPostId,
__experimentalGetTemplateInfo,
} = select( editorStore );
const { canUser } = select( coreStore );
const { getEditedEntityRecord } = select( coreStore );
const { __experimentalGetTemplateInfo } = select( editorStore );
const { canUser, getEditedEntityRecord } = select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getEditedEntityRecord( 'root', 'site' )
: undefined;
const _type = getCurrentPostType();
const _id = getCurrentPostId();
const _record = getEditedEntityRecord( 'postType', _type, _id );
const _record = getEditedEntityRecord(
'postType',
postType,
postId
);
const _templateInfo =
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(
_type
postType
) && __experimentalGetTemplateInfo( _record );
let _isSync = false;
if ( GLOBAL_POST_TYPES.includes( _type ) ) {
if ( PATTERN_POST_TYPE === _type ) {
if ( GLOBAL_POST_TYPES.includes( postType ) ) {
if ( PATTERN_POST_TYPE === postType ) {
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
const currentSyncStatus =
getEditedPostAttribute( 'meta' )
?.wp_pattern_sync_status === 'unsynced'
_record?.meta?.wp_pattern_sync_status === 'unsynced'
? 'unsynced'
: getEditedPostAttribute(
'wp_pattern_sync_status'
);
: _record?.wp_pattern_sync_status;
_isSync = currentSyncStatus !== 'unsynced';
} else {
_isSync = true;
}
}
return {
title:
_templateInfo?.title || getEditedPostAttribute( 'title' ),
icon: unlock( select( editorStore ) ).getPostIcon( _type, {
title: _templateInfo?.title || _record?.title,
icon: unlock( select( editorStore ) ).getPostIcon( postType, {
area: _record?.area,
} ),
isSync: _isSync,
isFrontPage: siteSettings?.page_on_front === _id,
isPostsPage: siteSettings?.page_for_posts === _id,
isFrontPage: siteSettings?.page_on_front === postId,
isPostsPage: siteSettings?.page_for_posts === postId,
};
},
[]
Expand Down
29 changes: 19 additions & 10 deletions packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ import { PrivatePostLastRevision } from '../post-last-revision';
const PANEL_NAME = 'post-status';

export default function PostSummary( { onActionPerformed } ) {
const { isRemovedPostStatusPanel } = 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, getCurrentPostType } =
select( editorStore );
return {
isRemovedPostStatusPanel: isEditorPanelRemoved( PANEL_NAME ),
postType: getCurrentPostType(),
};
}, [] );
const { isRemovedPostStatusPanel, postType, postId } = 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,
getCurrentPostType,
getCurrentPostId,
} = select( editorStore );
return {
isRemovedPostStatusPanel: isEditorPanelRemoved( PANEL_NAME ),
postType: getCurrentPostType(),
postId: getCurrentPostId(),
};
},
[]
);

return (
<PostPanelSection className="editor-post-summary">
Expand All @@ -54,6 +61,8 @@ export default function PostSummary( { onActionPerformed } ) {
<>
<VStack spacing={ 4 }>
<PostCardPanel
postType={ postType }
postId={ postId }
actions={
<PostActions
onActionPerformed={ onActionPerformed }
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import BackButton from './components/header/back-button';
import CreateTemplatePartModal from './components/create-template-part-modal';
import Editor from './components/editor';
import PluginPostExcerpt from './components/post-excerpt/plugin';
import PostCardPanel from './components/post-card-panel';
import PreferencesModal from './components/preferences-modal';
import { usePostActions } from './components/post-actions/actions';
import ToolsMoreMenuGroup from './components/more-menu/tools-more-menu-group';
Expand All @@ -40,6 +41,7 @@ lock( privateApis, {
GlobalStylesProvider,
mergeBaseAndUserConfigs,
PluginPostExcerpt,
PostCardPanel,
PreferencesModal,
usePostActions,
ToolsMoreMenuGroup,
Expand Down

0 comments on commit fd68da5

Please sign in to comment.