From 33d0c43a039a23aeef95836c947c78a4889dda82 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 21 Nov 2024 10:24:39 +1100 Subject: [PATCH 1/2] For the styles panel, send the correct recordCount via optional prop to the footer component. This allows us to remove the globalstyle record selector. --- .../index.js | 7 +++--- .../index.js | 24 +++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js index 3dec3f0a7b2eb5..4a5a6175148880 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js @@ -23,6 +23,7 @@ import SidebarNavigationItem from '../sidebar-navigation-item'; export default function SidebarNavigationScreenDetailsFooter( { record, + recordCount = 0, ...otherProps } ) { /* @@ -35,9 +36,9 @@ export default function SidebarNavigationScreenDetailsFooter( { const lastRevisionId = record?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null; const revisionsCount = - record?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; - // Enable the revisions link if there is a last revision and there are more than one revisions. - if ( lastRevisionId && revisionsCount > 1 ) { + recordCount || record?._links?.[ 'version-history' ]?.[ 0 ]?.count; + // Enable the revisions link if there is a last revision and there is more than one revision. + if ( lastRevisionId && revisionsCount ) { hrefProps.href = addQueryArgs( 'revision.php', { revision: record?._links[ 'predecessor-version' ][ 0 ].id, } ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index 3dc93ff4d4df63..db0758da6dcced 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -48,24 +48,15 @@ export function SidebarNavigationItemGlobalStyles( props ) { export default function SidebarNavigationScreenGlobalStyles() { const history = useHistory(); const { params } = useLocation(); - const { revisions, isLoading: isLoadingRevisions } = - useGlobalStylesRevisions(); + const { + revisions, + isLoading: isLoadingRevisions, + revisionsCount, + } = useGlobalStylesRevisions(); const { openGeneralSidebar } = useDispatch( editSiteStore ); const { setEditorCanvasContainerView } = unlock( useDispatch( editSiteStore ) ); - const { revisionsCount } = useSelect( ( select ) => { - const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = - select( coreStore ); - const globalStylesId = __experimentalGetCurrentGlobalStylesId(); - const globalStyles = globalStylesId - ? getEntityRecord( 'root', 'globalStyles', globalStylesId ) - : undefined; - return { - revisionsCount: - globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0, - }; - }, [] ); const { set: setPreference } = useDispatch( preferencesStore ); const openGlobalStyles = useCallback( async () => { @@ -95,10 +86,10 @@ export default function SidebarNavigationScreenGlobalStyles() { }, [ openGlobalStyles, setEditorCanvasContainerView ] ); // If there are no revisions, do not render a footer. - const hasRevisions = revisionsCount > 0; const modifiedDateTime = revisions?.[ 0 ]?.modified; const shouldShowGlobalStylesFooter = - hasRevisions && ! isLoadingRevisions && modifiedDateTime; + revisionsCount && ! isLoadingRevisions && modifiedDateTime; + return ( <> ) From 409b9a3b95f4b06a9cb063a4d87d1f351ca106e8 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 22 Nov 2024 12:49:09 +1100 Subject: [PATCH 2/2] Implement feedback --- .../index.js | 21 ++++++++++++++----- .../index.js | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js index 4a5a6175148880..51833443d8d85c 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-details-footer/index.js @@ -23,7 +23,7 @@ import SidebarNavigationItem from '../sidebar-navigation-item'; export default function SidebarNavigationScreenDetailsFooter( { record, - recordCount = 0, + revisionsCount, ...otherProps } ) { /* @@ -35,10 +35,21 @@ export default function SidebarNavigationScreenDetailsFooter( { const hrefProps = {}; const lastRevisionId = record?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null; - const revisionsCount = - recordCount || record?._links?.[ 'version-history' ]?.[ 0 ]?.count; - // Enable the revisions link if there is a last revision and there is more than one revision. - if ( lastRevisionId && revisionsCount ) { + + // Use incoming prop first, then the record's version history, if available. + revisionsCount = + revisionsCount || + record?._links?.[ 'version-history' ]?.[ 0 ]?.count || + 0; + + /* + * Enable the revisions link if there is a last revision and there is more than one revision. + * This link is used for theme assets, e.g., templates, which have no database record until they're edited. + * For these files there's only a "revision" after they're edited twice, + * which means the revision.php page won't display a proper diff. + * See: https://github.com/WordPress/gutenberg/issues/49164. + */ + if ( lastRevisionId && revisionsCount > 1 ) { hrefProps.href = addQueryArgs( 'revision.php', { revision: record?._links[ 'predecessor-version' ][ 0 ].id, } ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index db0758da6dcced..772b15aec2a294 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -88,7 +88,7 @@ export default function SidebarNavigationScreenGlobalStyles() { // If there are no revisions, do not render a footer. const modifiedDateTime = revisions?.[ 0 ]?.modified; const shouldShowGlobalStylesFooter = - revisionsCount && ! isLoadingRevisions && modifiedDateTime; + revisionsCount > 0 && ! isLoadingRevisions && modifiedDateTime; return ( <> @@ -105,7 +105,7 @@ export default function SidebarNavigationScreenGlobalStyles() { shouldShowGlobalStylesFooter && ( )