Skip to content

Commit

Permalink
- Use rendered Theme name as the revisions button
Browse files Browse the repository at this point in the history
- Ensure that any undefined properties, e.g., styles, settings, are set as empty objects so that any theme defaults are correctly displayed by default
  • Loading branch information
ramonjd committed Jul 31, 2023
1 parent c45dd8c commit f3e39e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function ScreenRevisions() {

const selectRevision = ( revision ) => {
setGlobalStylesRevision( {
styles: revision?.styles,
settings: revision?.settings,
behaviors: revision?.behaviors,
styles: revision?.styles || {},
settings: revision?.settings || {},
behaviors: revision?.behaviors || {},
id: revision?.id,
} );
setSelectedRevisionId( revision?.id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import classnames from 'classnames';
import { __, sprintf } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

/**
* Returns a button label for the revision.
Expand All @@ -19,13 +21,18 @@ import { dateI18n, getDate, humanTimeDiff, getSettings } from '@wordpress/date';
function getRevisionLabel( revision ) {
const authorDisplayName = revision?.author?.name || __( 'User' );

if ( 'parent' === revision?.id ) {
return __( 'Reset the styles to the theme defaults' );
}

if ( 'unsaved' === revision?.id ) {
return sprintf(
/* translators: %s author display name */
__( 'Unsaved changes by %s' ),
authorDisplayName
);
}

const formattedDate = dateI18n(
getSettings().formats.datetimeAbbreviated,
getDate( revision?.modified )
Expand Down Expand Up @@ -58,6 +65,10 @@ function getRevisionLabel( revision ) {
* @return {JSX.Element} The modal component.
*/
function RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) {
const currentTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme(),
[]
);
return (
<ol
className="edit-site-global-styles-screen-revisions__revisions-list"
Expand All @@ -80,6 +91,7 @@ function RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) {
'edit-site-global-styles-screen-revisions__revision-item',
{
'is-selected': isSelected,
'is-reset': isReset,
}
) }
key={ id }
Expand All @@ -94,7 +106,11 @@ function RevisionsButtons( { userRevisions, selectedRevisionId, onChange } ) {
>
{ isReset ? (
<span className="edit-site-global-styles-screen-revisions__description">
{ __( 'Theme default styles' ) }
{ __( 'Default styles' ) }
<span className="edit-site-global-styles-screen-revisions__meta">
{ currentTheme?.name?.rendered ||
currentTheme?.stylesheet }
</span>
</span>
) : (
<span className="edit-site-global-styles-screen-revisions__description">
Expand Down

0 comments on commit f3e39e2

Please sign in to comment.