Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 7 additions & 21 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
__experimentalText as Text,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { moreVertical, close } from '@wordpress/icons';
import { close } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function PostCardPanel( {
() => ( Array.isArray( postId ) ? postId : [ postId ] ),
[ postId ]
);
const { postTitle, icon, labels, isRevision } = useSelect(
const { postTitle, icon, labels } = useSelect(
( select ) => {
const { getEditedEntityRecord, getCurrentTheme, getPostType } =
select( coreStore );
Expand All @@ -75,7 +75,6 @@ export default function PostCardPanel( {
area: _record?.area,
} ),
labels: getPostType( parentPostType )?.labels,
isRevision: true,
};
}

Expand Down Expand Up @@ -146,24 +145,11 @@ export default function PostCardPanel( {
) }
</Text>
{ ! hideActions && postIds.length === 1 && (
<>
{ isRevision ? (
<Button
size="small"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled
accessibleWhenDisabled
className="editor-all-actions-button"
/>
) : (
<PostActions
postType={ postType }
postId={ postIds[ 0 ] }
onActionPerformed={ onActionPerformed }
/>
) }
</>
<PostActions
postType={ postType }
postId={ postIds[ 0 ] }
onActionPerformed={ onActionPerformed }
/>
) }
{ onClose && (
<Button
Expand Down
21 changes: 5 additions & 16 deletions packages/editor/src/components/post-content-information/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
Expand All @@ -23,19 +22,9 @@ const AVERAGE_READING_RATE = 189;

// This component renders the wordcount and reading time for the post.
export default function PostContentInformation() {
const { postContent } = useSelect( ( select ) => {
const postContent = useSelect( ( select ) => {
const { getEditedPostAttribute, getCurrentPostType, getCurrentPostId } =
select( editorStore );
const { getCurrentRevision, isRevisionsMode } = unlock(
select( editorStore )
);

if ( isRevisionsMode() ) {
return {
postContent: getCurrentRevision()?.content?.raw,
};
}

const { canUser } = select( coreStore );
const { getEntityRecord } = select( coreStore );
const siteSettings = canUser( 'read', {
Expand All @@ -52,12 +41,12 @@ export default function PostContentInformation() {
! [ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(
postType
);
return {
postContent:
showPostContentInfo && getEditedPostAttribute( 'content' ),
};
return showPostContentInfo && getEditedPostAttribute( 'content' );
}, [] );
return <PostContentInformationUI postContent={ postContent } />;
}

export function PostContentInformationUI( { postContent } ) {
/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
Expand Down
151 changes: 151 additions & 0 deletions packages/editor/src/components/post-revisions-panel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* WordPress dependencies
*/
import {
PanelBody,
Button,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { DataViews } from '@wordpress/dataviews';
import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { authorField } from '@wordpress/fields';

/**
* Internal dependencies
*/
import PostLastRevisionCheck from '../post-last-revision/check';
import { store as editorStore } from '../../store';
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 view = {
type: 'activity',
titleField: 'date',
fields: [ 'author' ],
layout: {
density: 'compact',
},
};
const fields = [
{
id: 'date',
label: __( 'Date' ),
render: ( { item } ) => {
const dateNowInMs = getDate( null ).getTime();
const date = getDate( item.date ?? null );
const displayDate =
dateNowInMs - date.getTime() > DAY_IN_MILLISECONDS
? dateI18n(
getSettings().formats.datetimeAbbreviated,
date
)
: humanTimeDiff( date );
return (
<time
className="editor-post-revisions-panel__revision-date"
dateTime={ item.date }
>
{ displayDate }
</time>
);
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine rendering dates in "human time diff" is a common use case. Checked the datetime format but it doesn't offer mechanics for this.

I wonder if there're ways to incorporate this into the Field API.

enableSorting: false,
enableHiding: false,
},
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 );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This request is only necessary for the data view, but I suspect it will execute even when the panel is closed. Should we create a child component to handle this request to improve performance?

Copy link
Copy Markdown
Contributor Author

@ntsekouras ntsekouras Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good thought! I'll update later, as there are ongoing design discussions right now.

return {
revisionsCount: getCurrentPostRevisionsCount(),
lastRevisionId: getCurrentPostLastRevisionId(),
revisions: _revisions,
isLoading: isResolving( 'getRevisions', query ),
};
},
[]
);
return (
<PanelBody
title={
<HStack justify="space-between" align="center" as="span">
<span>{ __( 'Revisions' ) }</span>
<Badge className="editor-post-revisions-panel__revisions-count">
{ revisionsCount }
</Badge>
</HStack>
}
initialOpen={ false }
>
<VStack className="editor-post-revisions-panel">
<DataViews
view={ view }
onChangeView={ noop }
fields={ fields }
data={ revisions || EMPTY_ARRAY }
isLoading={ isLoading }
paginationInfo={ paginationInfo }
defaultLayouts={ defaultLayouts }
getItemId={ ( item ) => item.id }
isItemClickable={ () => true }
onClickItem={ ( item ) => {
setCurrentRevisionId( item.id );
} }
>
<DataViews.Layout />
</DataViews>
<Button
className="editor-post-revisions-panel__view-all"
__next40pxDefaultSize
variant="secondary"
onClick={ () => setCurrentRevisionId( lastRevisionId ) }
>
{ __( 'View all revisions' ) }
</Button>
</VStack>
</PanelBody>
);
}

export default function PostRevisionsPanel() {
return (
<PostLastRevisionCheck>
<PostRevisionsPanelContent />
</PostLastRevisionCheck>
);
}
16 changes: 16 additions & 0 deletions packages/editor/src/components/post-revisions-panel/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.editor-post-revisions-panel {
.editor-post-revisions-panel__view-all {
justify-content: center;
}

.editor-post-revisions-panel__revision-date {
text-transform: uppercase;
font-weight: 600;
font-size: 12px;
}
Comment on lines +6 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be overriding Dataviews styles like this.

}

.editor-post-revisions-panel__revisions-count {
margin-top: -4.5px;
margin-bottom: -4.5px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import PostPanelSection from '../post-panel-section';
import { store as editorStore } from '../../store';
import PostTrash from '../post-trash';
import usePostFields from '../post-fields';
import { unlock } from '../../lock-unlock';
import { usePostTemplatePanelMode } from '../post-template/hooks';

const form = {
Expand Down Expand Up @@ -72,15 +71,12 @@ const form = {

export default function DataFormPostSummary( { onActionPerformed } ) {
const { postType, postId } = useSelect( ( select ) => {
const { getCurrentPostType, getCurrentPostId } = unlock(
select( editorStore )
);
const { getCurrentPostType, getCurrentPostId } = select( editorStore );
return {
postType: getCurrentPostType(),
postId: getCurrentPostId(),
};
}, [] );

const record = useSelect(
( select ) => {
if ( ! postType || ! postId ) {
Expand Down Expand Up @@ -173,7 +169,6 @@ export default function DataFormPostSummary( { onActionPerformed } ) {

editEntityRecord( 'postType', postType, postId, edits );
};

return (
<PostPanelSection className="editor-post-summary">
<VStack spacing={ 4 }>
Expand Down
59 changes: 32 additions & 27 deletions packages/editor/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import PatternOverridesPanel from '../pattern-overrides-panel';
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
import PluginSidebar from '../plugin-sidebar';
import PostSummary from './post-summary';
import PostRevisionSummary from './post-revision-summary';
import PostTaxonomiesPanel from '../post-taxonomies/panel';
import RevisionFieldsDiffPanel from '../revision-fields-diff';
import PostTransformPanel from '../post-transform-panel';
import SidebarHeader from './header';
import TemplateActionsPanel from '../template-actions-panel';
import TemplateContentPanel from '../template-content-panel';
import TemplatePartContentPanel from '../template-part-content-panel';
import { MediaMetadataPanel } from '../media';
import PostRevisionsPanel from '../post-revisions-panel';
import RevisionBlockDiffPanel from '../revision-block-diff';
import useAutoSwitchEditorSidebars from '../provider/use-auto-switch-editor-sidebars';
import { sidebars } from './constants';
Expand Down Expand Up @@ -97,6 +98,35 @@ const SidebarContent = ( {
}
}, [ tabName ] );

let tabContent;
if ( isAttachment ) {
tabContent = (
<MediaMetadataPanel onActionPerformed={ onActionPerformed } />
);
} else if ( isRevisionsMode ) {
tabContent = <PostRevisionSummary />;
} else {
tabContent = (
<>
<PostSummary onActionPerformed={ onActionPerformed } />
<PluginDocumentSettingPanel.Slot />
<TemplateContentPanel />
{ window?.__experimentalDataFormInspector &&
[ 'post', 'page' ].includes( postType ) && (
<>
<TemplateActionsPanel />
<PostRevisionsPanel />
</>
) }
<TemplatePartContentPanel />
<PostTransformPanel />
<PostTaxonomiesPanel />
<PatternOverridesPanel />
{ extraPanels }
</>
);
}

return (
<PluginSidebar
identifier={ tabName }
Expand All @@ -121,32 +151,7 @@ const SidebarContent = ( {
>
<Tabs.Context.Provider value={ tabsContextValue }>
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
{ isAttachment ? (
<MediaMetadataPanel
onActionPerformed={ onActionPerformed }
/>
) : (
<>
<PostSummary
onActionPerformed={ onActionPerformed }
/>
{ isRevisionsMode && <RevisionFieldsDiffPanel /> }
{ ! isRevisionsMode && (
<>
<PluginDocumentSettingPanel.Slot />
<TemplateContentPanel />
{ window?.__experimentalDataFormInspector && (
<TemplateActionsPanel />
) }
<TemplatePartContentPanel />
<PostTransformPanel />
<PostTaxonomiesPanel />
<PatternOverridesPanel />
{ extraPanels }
</>
) }
</>
) }
{ tabContent }
</Tabs.TabPanel>
{ ! isAttachment && (
<Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
Expand Down
Loading
Loading