Repository navigation
Revisions screen with picker-activity layout #77333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
008cc9a
WIP: Try revisions with picker-activity layout
ntsekouras 39f014e
revert revisions panel changes for this PR
ntsekouras 77bf886
try dropdown for meta field changes
ntsekouras 496f9d2
remove orphaned components
ntsekouras 16a4c8c
use same revisions query with slider
ntsekouras f76ef8a
fixed DV, Aki's suggestion + stable instances returned from useSelect
ntsekouras f749d73
use humanized label for revisions date for friendlier screen readers'…
ntsekouras beaf2e3
try keeping the meta panel on top, outside timeline
ntsekouras 8b908dc
revert diff panel changes that are not needed now
ntsekouras 6e55152
cap the post-meta diff content
ntsekouras acec1cb
create DataViewsPickerBulkActionToolbar and export taViewsPicker.Footer
ntsekouras ded2623
use Aki's style suggestion
ntsekouras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
186 changes: 186 additions & 0 deletions
186
packages/editor/src/components/post-revisions-timeline/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| 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
43
packages/editor/src/components/post-revisions-timeline/style.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
36
packages/editor/src/components/revision-author-panel/index.js
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
packages/editor/src/components/revision-created-panel/index.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
metapanel that is now showing in trunk, above the revisions list (timeline). Could that work UX wise?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Is there any reason it couldn't just stay in the Block tab?
There was a problem hiding this comment.
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:
You can test by adding
footnotesto some text e.g. in a paragraph.There was a problem hiding this comment.
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.