Skip to content

Commit

Permalink
Style panel: use correct revisions count (#67180)
Browse files Browse the repository at this point in the history
* For the styles panel, send the correct recordCount via optional prop to the footer component.
This allows us to remove the globalstyle record selector.

* Implement feedback

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: afercia <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2024
1 parent 326589d commit 2c5421d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SidebarNavigationItem from '../sidebar-navigation-item';

export default function SidebarNavigationScreenDetailsFooter( {
record,
revisionsCount,
...otherProps
} ) {
/*
Expand All @@ -34,9 +35,20 @@ export default function SidebarNavigationScreenDetailsFooter( {
const hrefProps = {};
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.

// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 > 0 && ! isLoadingRevisions && modifiedDateTime;

return (
<>
<SidebarNavigationScreen
Expand All @@ -114,6 +105,7 @@ export default function SidebarNavigationScreenGlobalStyles() {
shouldShowGlobalStylesFooter && (
<SidebarNavigationScreenDetailsFooter
record={ revisions?.[ 0 ] }
revisionsCount={ revisionsCount }
onClick={ openRevisions }
/>
)
Expand Down

1 comment on commit 2c5421d

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 2c5421d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11994304184
📝 Reported issues:

Please sign in to comment.