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
186 changes: 186 additions & 0 deletions packages/editor/src/components/post-revisions-timeline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { DataViewsPicker, filterSortAndPaginate } from '@wordpress/dataviews';
import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
import { useCallback, useEffect, useMemo, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { authorField } from '@wordpress/fields';
import { Text } from '@wordpress/ui';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { PostContentInformationUI } from '../post-content-information';

const PAGE_SIZE = 10;
const EMPTY_ARRAY = [];
const defaultLayouts = { pickerActivity: true };
const baseView = {
type: 'pickerActivity',
titleField: 'date',
descriptionField: 'details',
fields: [ 'author' ],
layout: { density: 'compact' },
page: 1,
perPage: PAGE_SIZE,
};

const DAY_IN_MILLISECONDS = 86400000;

function getDisplayDate( value ) {
const dateNowInMs = getDate( null ).getTime();
const date = getDate( value ?? null );
return dateNowInMs - date.getTime() > DAY_IN_MILLISECONDS
? dateI18n( getSettings().formats.datetimeAbbreviated, date )
: humanTimeDiff( date );
}

export default function PostRevisionsTimeline() {
const { setCurrentRevisionId } = unlock( useDispatch( editorStore ) );
const [ view, setView ] = useState( baseView );

const { revisions, revisionKey, currentRevisionId, currentRevision } =
useSelect( ( select ) => {
const { getCurrentPostType } = select( editorStore );
const {
getCurrentRevisionId: _getCurrentRevisionId,
getCurrentRevision,
getRevisionPage,
getPageRevisions,
} = unlock( select( editorStore ) );
const { getEntityConfig } = select( coreStore );

const _postType = getCurrentPostType();
const entityConfig = getEntityConfig( 'postType', _postType );
const _revisionKey = entityConfig?.revisionKey || 'id';
const _currentRevisionId = _getCurrentRevisionId();

return {
// Same desc-ordered window the header slider renders (warm cache).
revisions: getPageRevisions( getRevisionPage() ),
revisionKey: _revisionKey,
currentRevisionId: _currentRevisionId,
currentRevision: _currentRevisionId
? getCurrentRevision()
: undefined,
};
}, [] );

const postContent = currentRevision?.content?.raw;

const isLoading = ! revisions;

const fields = useMemo(
() => [
{
id: 'date',
label: __( 'Date' ),
// Return the humanized label the row renders so the picker
// option's accessible name announces e.g. "5 minutes ago"
// instead of the raw ISO timestamp.
getValue: ( { item } ) => getDisplayDate( item.date ),
render: ( { item } ) => (
<Text
variant="heading-sm"
render={ <time dateTime={ item.date } /> }
>
{ getDisplayDate( item.date ) }
</Text>
),
enableSorting: false,
enableHiding: false,
},
authorField,
{
id: 'details',

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.

Could this be removed? According to the comments below, the summary of this change doesn't seem useful at the moment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TBH I don't think we should remove it entirely here. We could remove the PostContentInformationUI (time to read) but hiding the post meta diff, even if the current presentation is not that useful, it would still be a regression from current screen.

For now I've added an info icon that renders the diff of post meta in a dialog, which reduces the UI surface for that.

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.

The placement of the icon looks a little strange. Should this be an action (assuming the activity picker supports actions)?

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 structure feels like an HTML violation. My understanding is that an item with role=option should be an interactive element, and nesting an interactive element like a button inside it is not allowed.

nested-intaractive-elements

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This can't be an action because of the listbox/option model Aki mentioned above. So this button and similar solutions cannot be kept.

An option could be to preserve the collapse meta panel that is now showing in trunk, above the revisions list (timeline). Could that work UX wise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed the changes with my above suggestion (preserve meta panel above) for easier testing. Let me know how it feels.

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.

Do you mean this one?

Screenshot 2026-06-09 at 16 06 15

Is there any reason it couldn't just stay in the Block tab?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope. The one I'm referring is about post meta like this:

Screenshot 2026-06-09 at 7 11 22 PM

You can test by adding footnotes to some text e.g. in a paragraph.

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.

Ah, thanks for pointing that out. This is a tricky problem to solve given the current tooling. For now I suppose this is acceptable, but it's probably something we'd want to revisit. I'm still unsure how useful the information is in its current format.

label: __( 'Details' ),
render: ( { item } ) => {
if (
String( item[ revisionKey ] ) !==
String( currentRevisionId )
) {
return null;
}
return (
<PostContentInformationUI postContent={ postContent } />
);
},
enableSorting: false,
enableHiding: false,
},
],
[ revisionKey, currentRevisionId, postContent ]
);

const { data: shownRevisions, paginationInfo } = useMemo(
() => filterSortAndPaginate( revisions || EMPTY_ARRAY, view, fields ),
[ revisions, view, fields ]
);

// Keep the selected revision visible: when it changes (e.g. the slider
// scrubs), jump to the client-side page that contains it. Keyed on the
// selection/data, not view.page, so manual paging stays free browsing.
useEffect( () => {
if ( ! currentRevisionId || ! revisions ) {
return;
}
const index = revisions.findIndex(
( r ) => String( r[ revisionKey ] ) === String( currentRevisionId )
);
if ( index < 0 ) {
return;
}
const page = Math.floor( index / view.perPage ) + 1;
setView( ( v ) => ( v.page === page ? v : { ...v, page } ) );
}, [ currentRevisionId, revisions, revisionKey, view.perPage ] );

const selection = useMemo(
() =>
currentRevisionId ? [ String( currentRevisionId ) ] : EMPTY_ARRAY,
[ currentRevisionId ]
);

const onChangeSelection = useCallback(
( newSelection ) => {
// Revisions mode always keeps one revision selected. Clicking the
// active revision yields an empty selection, which we ignore so the
// timeline never ends up with nothing selected.
if ( newSelection.length === 0 ) {
return;
}
const selectedId = newSelection[ newSelection.length - 1 ];
setCurrentRevisionId( Number( selectedId ) );
},
[ setCurrentRevisionId ]
);

const getItemId = useCallback(
( item ) => String( item[ revisionKey ] ),
[ revisionKey ]
);

return (
<div className="editor-post-revisions-timeline">
<DataViewsPicker
view={ view }
onChangeView={ setView }
fields={ fields }
data={ shownRevisions }
isLoading={ isLoading }
paginationInfo={ paginationInfo }
defaultLayouts={ defaultLayouts }
getItemId={ getItemId }
selection={ selection }
onChangeSelection={ onChangeSelection }
>
<DataViewsPicker.Layout />
<DataViewsPicker.Footer />
</DataViewsPicker>
</div>
);
}
43 changes: 43 additions & 0 deletions packages/editor/src/components/post-revisions-timeline/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Give the revisions inspector a bounded height so the timeline scrolls
// internally and the picker's pagination stays pinned to the bottom.
//
// The timeline only renders in revisions mode, so its ancestors are scoped
// with `:has()` — keeping this layout out of the generic editor sidebar.
.interface-complementary-area:has(.editor-post-revisions-timeline) {
display: flex;
flex-direction: column;
overflow: hidden;

// The tabs header keeps its natural height.
.editor-sidebar__panel-tabs {
flex-shrink: 0;
}
}

.editor-sidebar__panel:has(.editor-post-revisions-timeline) {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;

// The document tab panel hands its bounded height down to the timeline.
[role="tabpanel"]:has(.editor-post-revisions-timeline) {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
}

// Cap only the post-meta diff content so a large
// diff (e.g. footnotes) can't dominate the column.
.editor-revision-meta-diff__content {
max-height: 80px;
overflow-y: auto;
}

// timeline grows to fill the leftover space and scrolls internally.
.editor-post-revisions-timeline {
flex: 1;
min-height: 0;
}
}
36 changes: 0 additions & 36 deletions packages/editor/src/components/revision-author-panel/index.js

This file was deleted.

36 changes: 0 additions & 36 deletions packages/editor/src/components/revision-created-panel/index.js

This file was deleted.

10 changes: 8 additions & 2 deletions packages/editor/src/components/revision-diff-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ import PostPanelRow from '../post-panel-row';
* @param {string} props.title Panel title.
* @param {Object} props.entries Map of key → diffWords parts arrays.
* @param {boolean} props.initialOpen Whether the panel starts open.
* @param {string} [props.className] Optional class for the content wrapper.
*/
export default function RevisionDiffPanel( { title, entries, initialOpen } ) {
export default function RevisionDiffPanel( {
title,
entries,
initialOpen,
className,
} ) {
if ( ! entries ) {
return null;
}
Expand Down Expand Up @@ -53,7 +59,7 @@ export default function RevisionDiffPanel( { title, entries, initialOpen } ) {

return (
<PanelBody title={ title } initialOpen={ initialOpen }>
{ fields }
<div className={ className }>{ fields }</div>
</PanelBody>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default function RevisionFieldsDiffPanel() {
title={ __( 'Meta' ) }
entries={ entries }
initialOpen={ false }
className="editor-revision-meta-diff__content"
/>
);
}
23 changes: 8 additions & 15 deletions packages/editor/src/components/sidebar/post-revision-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ import { addQueryArgs } from '@wordpress/url';
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import RevisionAuthorPanel from '../revision-author-panel';
import RevisionCreatedPanel from '../revision-created-panel';
import { PostContentInformationUI } from '../post-content-information';
import RevisionFieldsDiffPanel from '../revision-fields-diff';
import PostRevisionsTimeline from '../post-revisions-timeline';
import PostPanelSection from '../post-panel-section';
import PostCardPanel from '../post-card-panel';
import RevisionFieldsDiffPanel from '../revision-fields-diff';

export default function PostRevisionSummary() {
const { revisionId, postId, postContent } = useSelect( ( select ) => {
const { getCurrentRevisionId, getCurrentRevision, getCurrentPostId } =
unlock( select( editorStore ) );
const _revisionId = getCurrentRevisionId();
const { revisionId, postId } = useSelect( ( select ) => {
const { getCurrentRevisionId, getCurrentPostId } = unlock(
select( editorStore )
);
return {
revisionId: _revisionId,
revisionId: getCurrentRevisionId(),
postId: getCurrentPostId(),
postContent: _revisionId && getCurrentRevision()?.content?.raw,
};
}, [] );
if ( ! revisionId ) {
Expand All @@ -40,21 +37,17 @@ export default function PostRevisionSummary() {
<PostPanelSection className="editor-post-summary">
<VStack spacing={ 4 }>
<PostCardPanel postId={ postId } hideActions />
<VStack spacing={ 1 }>
<PostContentInformationUI postContent={ postContent } />
<RevisionCreatedPanel />
</VStack>
<ExternalLink
href={ addQueryArgs( 'revision.php', {
revision: revisionId,
} ) }
>
{ __( 'Open classic revisions screen' ) }
</ExternalLink>
<RevisionAuthorPanel />
</VStack>
</PostPanelSection>
<RevisionFieldsDiffPanel />
<PostRevisionsTimeline />
</>
);
}
1 change: 1 addition & 0 deletions packages/editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@use "./components/post-publish-panel/style.scss" as *;
@use "./components/post-revisions-panel/style.scss" as *;
@use "./components/post-revisions-preview/style.scss" as *;
@use "./components/post-revisions-timeline/style.scss" as *;
@use "./components/revision-diff-panel/style.scss" as *;
@use "./components/post-saved-state/style.scss" as *;
@use "./components/post-schedule/style.scss" as *;
Expand Down
Loading