From 5556a41bbf25c04991bfec5173f91a51fe82674b Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 15 Dec 2023 11:29:57 +1100 Subject: [PATCH] Styling pagination buttons Shifting "Apply" button to the single item so that we don't have to deal with it being next to the pagination row. --- .../global-styles/screen-revisions/index.js | 35 +++++-------------- .../screen-revisions/revisions-buttons.js | 26 ++++++++++---- .../global-styles/screen-revisions/style.scss | 23 ++++++------ .../use-global-styles-revisions.js | 19 ++++++---- .../src/components/page-patterns/style.scss | 10 ++++++ .../src/components/pagination/index.js | 9 ++--- .../src/components/pagination/style.scss | 19 +++------- 7 files changed, 68 insertions(+), 73 deletions(-) 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 56d994e40a814f..2d5d55a6f885b4 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 @@ -21,7 +21,6 @@ import { import ScreenHeader from '../header'; import { unlock } from '../../../lock-unlock'; import Revisions from '../../revisions'; -import SidebarFixedBottom from '../../sidebar-edit-mode/sidebar-fixed-bottom'; import { store as editSiteStore } from '../../../store'; import useGlobalStylesRevisions from './use-global-styles-revisions'; import RevisionsButtons from './revisions-buttons'; @@ -134,7 +133,9 @@ function ScreenRevisions() { // Only display load button if there is a revision to load, // and it is different from the current editor styles. const isLoadButtonEnabled = - !! currentlySelectedRevisionId && ! selectedRevisionMatchesEditorStyles; + !! currentlySelectedRevisionId && + currentlySelectedRevisionId !== 'unsaved' && + ! selectedRevisionMatchesEditorStyles; const hasRevisions = !! currentRevisions.length; return ( @@ -167,35 +168,15 @@ function ScreenRevisions() { selectedRevisionId={ currentlySelectedRevisionId } userRevisions={ currentRevisions } canApplyRevision={ isLoadButtonEnabled } + onApplyRevision={ () => + hasUnsavedChanges + ? setIsLoadingRevisionWithUnsavedChanges( true ) + : restoreRevision( currentlySelectedRevision ) + } /> { hasRevisions && (
- { isLoadButtonEnabled && ( - - ) } { numPages > 1 && ( { const { getCurrentTheme, getCurrentUser } = select( coreStore ); @@ -208,6 +209,13 @@ function RevisionsButtons( { { displayDate } ) } + + { + { authorDisplayName } + { isSelected && ( ) } - - { - { authorDisplayName } - ) } + { canApplyRevision && isSelected && ( + + ) } ); } ) } diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/style.scss b/packages/edit-site/src/components/global-styles/screen-revisions/style.scss index aeab634f7c2b6c..b0e34306509628 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/style.scss +++ b/packages/edit-site/src/components/global-styles/screen-revisions/style.scss @@ -93,10 +93,15 @@ } } -.edit-site-global-styles-screen-revisions__button { +.edit-site-global-styles-screen-revisions__apply-button.is-secondary { justify-content: center; - width: 100%; - margin-bottom: $grid-unit-20; + height: $button-size-small; + background: $white; + margin: 0 $grid-unit-15 $grid-unit-15 $grid-unit-30; + padding: $grid-unit-15 $grid-unit-20; + &:hover:not(:disabled) { + background-color: rgba(var(--wp-admin-theme-color--rgb), 0.04); + } } .edit-site-global-styles-screen-revisions__description { @@ -117,8 +122,9 @@ display: flex; justify-content: start; width: 100%; - align-items: center; + align-items: flex-start; font-size: 12px; + text-align: left; img { width: $grid-unit-20; height: $grid-unit-20; @@ -165,14 +171,5 @@ width: $button-size-small; height: $button-size-small; outline: 1px solid; - - &:disabled { - color: $gray-600; - background: none; - } - - &:hover:not(:disabled) { - background-color: $gray-700; - } } } diff --git a/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js b/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js index d532d367ea43ae..b51ac149f19fee 100644 --- a/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +++ b/packages/edit-site/src/components/global-styles/screen-revisions/use-global-styles-revisions.js @@ -48,14 +48,19 @@ export default function useGlobalStylesRevisions( { const globalStyles = globalStylesId ? getEntityRecord( 'root', 'globalStyles', globalStylesId ) : undefined; - let _revisionsCount = + const _revisionsCount = globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0; - // one for the reset item. - _revisionsCount++; - // one for any dirty changes (unsaved). - if ( _isDirty ) { - _revisionsCount++; - } + // Commenting out for now as we need to ensure + // that the right revisionsCount is use to calculate numPages. + // E.g., there might be a single, trailing 'reset' item, tricking the + // pagination into thinking there's an extra page, + // but there are no more revisions in the database. + // // one for the reset item. + // _revisionsCount++; + // // one for any dirty changes (unsaved). + // if ( _isDirty ) { + // _revisionsCount++; + // } const globalStylesRevisions = getRevisions( 'root', 'globalStyles', globalStylesId, query ) || EMPTY_ARRAY; diff --git a/packages/edit-site/src/components/page-patterns/style.scss b/packages/edit-site/src/components/page-patterns/style.scss index b815fc536c4acf..8995a0d25c96cf 100644 --- a/packages/edit-site/src/components/page-patterns/style.scss +++ b/packages/edit-site/src/components/page-patterns/style.scss @@ -211,5 +211,15 @@ z-index: z-index(".edit-site-patterns__grid-pagination"); .components-button.is-tertiary { background-color: $gray-800; + color: $gray-100; + + &:disabled { + color: $gray-600; + background: none; + } + + &:hover:not(:disabled) { + background-color: $gray-700; + } } } diff --git a/packages/edit-site/src/components/pagination/index.js b/packages/edit-site/src/components/pagination/index.js index 795324b532e09d..e7e40366fd7d30 100644 --- a/packages/edit-site/src/components/pagination/index.js +++ b/packages/edit-site/src/components/pagination/index.js @@ -20,6 +20,7 @@ export default function Pagination( { totalItems, className, disabled = false, + buttonVariant = 'tertiary', } ) { return (