diff --git a/packages/editor/src/components/post-revisions-panel/index.js b/packages/editor/src/components/post-revisions-panel/index.js index 32de3d3d0efe5a..e6e20bcd37fb1f 100644 --- a/packages/editor/src/components/post-revisions-panel/index.js +++ b/packages/editor/src/components/post-revisions-panel/index.js @@ -25,30 +25,23 @@ import { unlock } from '../../lock-unlock'; const { Badge } = unlock( componentsPrivateApis ); const DAY_IN_MILLISECONDS = 86400000; const EMPTY_ARRAY = []; - -const REVISIONS_QUERY = { - per_page: 3, - orderby: 'date', - order: 'desc', - context: 'embed', - _fields: 'id,date,author', -}; const defaultLayouts = { activity: {} }; +const noop = () => {}; +const paginationInfo = {}; const view = { type: 'activity', titleField: 'date', fields: [ 'author' ], - layout: { - density: 'compact', - }, + layout: { density: 'compact' }, }; const fields = [ { id: 'date', label: __( 'Date' ), - render: ( { item } ) => { + render: ( { item, field } ) => { const dateNowInMs = getDate( null ).getTime(); - const date = getDate( item.date ?? null ); + const _value = field.getValue( { item } ); + const date = getDate( _value ?? null ); const displayDate = dateNowInMs - date.getTime() > DAY_IN_MILLISECONDS ? dateI18n( @@ -59,7 +52,7 @@ const fields = [ return ( @@ -70,36 +63,45 @@ const fields = [ }, authorField, ]; -const noop = () => {}; -const paginationInfo = {}; function PostRevisionsPanelContent() { const { setCurrentRevisionId } = unlock( useDispatch( editorStore ) ); - const { revisionsCount, revisions, isLoading, lastRevisionId } = useSelect( - ( select ) => { - const { getCurrentPostId, getCurrentPostType } = - select( editorStore ); - const { - getCurrentPostRevisionsCount, - getCurrentPostLastRevisionId, - } = select( editorStore ); - const { getRevisions, isResolving } = select( coreStore ); - const query = [ - 'postType', - getCurrentPostType(), - getCurrentPostId(), - REVISIONS_QUERY, - ]; - const _revisions = getRevisions( ...query ); - return { - revisionsCount: getCurrentPostRevisionsCount(), - lastRevisionId: getCurrentPostLastRevisionId(), - revisions: _revisions, - isLoading: isResolving( 'getRevisions', query ), - }; - }, - [] - ); + const { + revisionsCount, + revisions, + revisionKey, + isLoading, + lastRevisionId, + } = useSelect( ( select ) => { + const { getCurrentPostId, getCurrentPostType } = select( editorStore ); + const { getCurrentPostRevisionsCount, getCurrentPostLastRevisionId } = + select( editorStore ); + const { getRevisions, getEntityConfig, isResolving } = + select( coreStore ); + const _postType = getCurrentPostType(); + const entityConfig = getEntityConfig( 'postType', _postType ); + const _revisionKey = entityConfig?.revisionKey || 'id'; + const revisionsQuery = { + per_page: 3, + orderby: 'date', + order: 'desc', + _fields: `${ _revisionKey },date,author`, + }; + const query = [ + 'postType', + _postType, + getCurrentPostId(), + revisionsQuery, + ]; + const _revisions = getRevisions( ...query ); + return { + revisionsCount: getCurrentPostRevisionsCount(), + lastRevisionId: getCurrentPostLastRevisionId(), + revisions: _revisions, + revisionKey: _revisionKey, + isLoading: isResolving( 'getRevisions', query ), + }; + }, [] ); return ( item.id } + getItemId={ ( item ) => item[ revisionKey ] } isItemClickable={ () => true } onClickItem={ ( item ) => { - setCurrentRevisionId( item.id ); + setCurrentRevisionId( item[ revisionKey ] ); } } > diff --git a/packages/editor/src/components/sidebar/index.js b/packages/editor/src/components/sidebar/index.js index dee68e87a96ac7..0d45a931ad45e3 100644 --- a/packages/editor/src/components/sidebar/index.js +++ b/packages/editor/src/components/sidebar/index.js @@ -112,7 +112,13 @@ const SidebarContent = ( { { window?.__experimentalDataFormInspector && - [ 'post', 'page' ].includes( postType ) && ( + [ + 'post', + 'page', + 'wp_template', + 'wp_template_part', + 'wp_block', + ].includes( postType ) && ( <> diff --git a/packages/editor/src/components/sidebar/post-revision-summary.js b/packages/editor/src/components/sidebar/post-revision-summary.js index 35d51ee5fa622c..ce4960d2ece2a3 100644 --- a/packages/editor/src/components/sidebar/post-revision-summary.js +++ b/packages/editor/src/components/sidebar/post-revision-summary.js @@ -2,7 +2,12 @@ * WordPress dependencies */ import { useSelect } from '@wordpress/data'; -import { __experimentalVStack as VStack } from '@wordpress/components'; +import { + ExternalLink, + __experimentalVStack as VStack, +} from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { addQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -15,7 +20,6 @@ import { PostContentInformationUI } from '../post-content-information'; import RevisionFieldsDiffPanel from '../revision-fields-diff'; import PostPanelSection from '../post-panel-section'; import PostCardPanel from '../post-card-panel'; -import { OpenRevisionsClassicScreen } from './post-summary'; export default function PostRevisionSummary() { const { revisionId, postId, postContent } = useSelect( ( select ) => { @@ -40,7 +44,13 @@ export default function PostRevisionSummary() { - + + { __( 'Open classic revisions screen' ) } + diff --git a/packages/editor/src/components/sidebar/post-summary.js b/packages/editor/src/components/sidebar/post-summary.js index a154aa53f41798..b99c36b695f201 100644 --- a/packages/editor/src/components/sidebar/post-summary.js +++ b/packages/editor/src/components/sidebar/post-summary.js @@ -1,13 +1,8 @@ /** * WordPress dependencies */ -import { - __experimentalVStack as VStack, - ExternalLink, -} from '@wordpress/components'; +import { __experimentalVStack as VStack } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; -import { addQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -41,18 +36,6 @@ import PostTrash from '../post-trash'; */ const PANEL_NAME = 'post-status'; -export function OpenRevisionsClassicScreen( { revisionId } ) { - return ( - - { __( 'Open classic revisions screen' ) } - - ); -} - export default function PostSummary( { onActionPerformed } ) { const postType = useSelect( ( select ) => select( editorStore ).getCurrentPostType(),