diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/index.js b/packages/edit-site/src/components/global-styles/screen-revisions/index.js index 92d5ae7d2bb68b..8a3e84e0ee41eb 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/index.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/index.js @@ -42,19 +42,11 @@ function ScreenRevisions() { blocks: select( blockEditorStore ).getBlocks(), }; }, [] ); - const { revisions, isLoading, hasUnsavedChanges } = useGlobalStylesRevisions(); + const [ selectedRevisionId, setSelectedRevisionId ] = useState(); const [ globalStylesRevision, setGlobalStylesRevision ] = useState( userConfig ); - - const [ currentRevisionId, setCurrentRevisionId ] = useState( - /* - * We need this for the first render, - * otherwise the unsaved changes haven't been merged into the revisions array yet. - */ - hasUnsavedChanges ? 'unsaved' : revisions?.[ 0 ]?.id - ); const [ isLoadingRevisionWithUnsavedChanges, setIsLoadingRevisionWithUnsavedChanges, @@ -89,7 +81,7 @@ function ScreenRevisions() { settings: revision?.settings, id: revision?.id, } ); - setCurrentRevisionId( revision?.id ); + setSelectedRevisionId( revision?.id ); }; const isLoadButtonEnabled = @@ -117,7 +109,7 @@ function ScreenRevisions() {
{ isLoadButtonEnabled && ( diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js b/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js index c4d624bf1727e2..f32441f6a41b06 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/revisions-buttons.js @@ -18,9 +18,8 @@ import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date'; */ function getRevisionLabel( revision ) { const authorDisplayName = revision?.author?.name || __( 'User' ); - const isUnsaved = 'unsaved' === revision?.id; - if ( isUnsaved ) { + if ( 'unsaved' === revision?.id ) { return sprintf( /* translators: %(name)s author display name */ __( 'Unsaved changes by %(name)s' ), @@ -57,45 +56,42 @@ function getRevisionLabel( revision ) { * Returns a rendered list of revisions buttons. * * @typedef {Object} props - * @property {Array} userRevisions A collection of user revisions. - * @property {number} currentRevisionId Callback fired when the modal is closed or action cancelled. - * @property {Function} onChange Callback fired when a revision is selected. + * @property {Array} userRevisions A collection of user revisions. + * @property {number} selectedRevisionId The id of the currently-selected revision. + * @property {Function} onChange Callback fired when a revision is selected. * - * @param {props} Component props. + * @param {props} Component props. * @return {JSX.Element} The modal component. */ -function RevisionsButtons( { userRevisions, currentRevisionId, onChange } ) { +function RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) { return (
    - { userRevisions.map( ( revision ) => { - const { id, author, isLatest, modified } = revision; + { userRevisions.map( ( revision, index ) => { + const { id, author, modified } = revision; const authorDisplayName = author?.name || __( 'User' ); const authorAvatar = author?.avatar_urls?.[ '48' ]; - /* - * If the currentId hasn't been selected yet, the first revision is - * the current one so long as the API returns revisions in descending order. - */ - const isActive = !! currentRevisionId - ? id === currentRevisionId - : isLatest; + const isUnsaved = 'unsaved' === revision?.id; + const isSelected = selectedRevisionId + ? selectedRevisionId === revision?.id + : index === 0; return (