From fd68da5565bf36b4c926b7fc7644d79eb17a41f4 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 9 Aug 2024 10:49:31 +0200 Subject: [PATCH] DataViews Quick Edit: Add Post Card to the quick edit panel (#64365) Co-authored-by: youknowriad Co-authored-by: oandregal Co-authored-by: jameskoster --- .../src/components/post-edit/index.js | 7 ++++ .../src/components/post-card-panel/index.js | 42 ++++++++----------- .../src/components/sidebar/post-summary.js | 29 ++++++++----- packages/editor/src/private-apis.js | 2 + 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index 03158e00862154..35141f743cd2e3 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -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 ] ); @@ -76,6 +80,9 @@ function PostEditForm( { postType, postId } ) { const isUpdateDisabled = ! isItemValid( itemWithEdits, fields, form ); return ( + { ids.length === 1 && ( + + ) } { - 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, }; }, [] diff --git a/packages/editor/src/components/sidebar/post-summary.js b/packages/editor/src/components/sidebar/post-summary.js index a6a95d36388ba5..573a59de827188 100644 --- a/packages/editor/src/components/sidebar/post-summary.js +++ b/packages/editor/src/components/sidebar/post-summary.js @@ -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 ( @@ -54,6 +61,8 @@ export default function PostSummary( { onActionPerformed } ) { <>