diff --git a/packages/edit-site/src/components/global-styles/header.js b/packages/edit-site/src/components/global-styles/header.js index f62820653ff925..e6da4115217f57 100644 --- a/packages/edit-site/src/components/global-styles/header.js +++ b/packages/edit-site/src/components/global-styles/header.js @@ -12,7 +12,7 @@ import { import { isRTL, __ } from '@wordpress/i18n'; import { chevronRight, chevronLeft } from '@wordpress/icons'; -function ScreenHeader( { title, description } ) { +function ScreenHeader( { title, description, onBack } ) { return ( @@ -27,6 +27,7 @@ function ScreenHeader( { title, description } ) { icon={ isRTL() ? chevronRight : chevronLeft } isSmall aria-label={ __( 'Navigate to the previous view' ) } + onClick={ onBack } /> { - return { - editorCanvasContainerView: unlock( - select( editSiteStore ) - ).getEditorCanvasContainerView(), - blocks: select( blockEditorStore ).getBlocks(), - }; - }, [] ); + const { blocks, editorCanvasContainerView, revisionsCount } = useSelect( + ( select ) => { + const { + getEntityRecord, + __experimentalGetCurrentGlobalStylesId, + __experimentalGetDirtyEntityRecords, + } = select( coreStore ); + const isDirty = __experimentalGetDirtyEntityRecords().length > 0; + const globalStylesId = __experimentalGetCurrentGlobalStylesId(); + const globalStyles = globalStylesId + ? getEntityRecord( 'root', 'globalStyles', globalStylesId ) + : undefined; + let _revisionsCount = + globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count || 0; + // one for the reset item. + _revisionsCount++; + // one for any dirty changes (unsaved). + if ( isDirty ) { + _revisionsCount++; + } + return { + editorCanvasContainerView: unlock( + select( editSiteStore ) + ).getEditorCanvasContainerView(), + blocks: select( blockEditorStore ).getBlocks(), + revisionsCount: _revisionsCount, + }; + }, + [] + ); const { revisions, isLoading, hasUnsavedChanges } = useGlobalStylesRevisions(); const [ currentlySelectedRevision, setCurrentlySelectedRevision ] = @@ -61,6 +84,7 @@ function ScreenRevisions() { const onCloseRevisions = () => { goTo( '/' ); // Return to global styles main panel. + setEditorCanvasContainerView( undefined ); }; const restoreRevision = ( revision ) => { @@ -119,10 +143,15 @@ function ScreenRevisions() { return ( <> { isLoading && ( diff --git a/packages/edit-site/src/components/global-styles/style.scss b/packages/edit-site/src/components/global-styles/style.scss index 3560ef139fa3fe..a899495cc332b7 100644 --- a/packages/edit-site/src/components/global-styles/style.scss +++ b/packages/edit-site/src/components/global-styles/style.scss @@ -191,14 +191,3 @@ .edit-site-global-styles-sidebar__panel .block-editor-block-icon svg { fill: currentColor; } - -[class][class].edit-site-global-styles-sidebar__revisions-count-badge { - align-items: center; - background: $gray-800; - border-radius: 2px; - color: $white; - display: inline-flex; - justify-content: center; - min-height: $icon-size; - min-width: $icon-size; -} diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js index 2e33d4b599b7b9..c8d72205c3bed8 100644 --- a/packages/edit-site/src/components/global-styles/ui.js +++ b/packages/edit-site/src/components/global-styles/ui.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ @@ -55,6 +50,7 @@ const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } = createSlotFill( SLOT_FILL_NAME ); function GlobalStylesActionMenu() { + const [ canReset, onReset ] = useGlobalStylesReset(); const { toggle } = useDispatch( preferencesStore ); const { canEditCSS } = useSelect( ( select ) => { const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = @@ -69,49 +65,56 @@ function GlobalStylesActionMenu() { canEditCSS: !! globalStyles?._links?.[ 'wp:action-edit-css' ], }; }, [] ); + const { setEditorCanvasContainerView } = unlock( + useDispatch( editSiteStore ) + ); const { goTo } = useNavigator(); - const loadCustomCSS = () => goTo( '/css' ); + const loadCustomCSS = () => { + setEditorCanvasContainerView( 'global-styles-css' ); + goTo( '/css' ); + }; return ( { ( { onClose } ) => ( - - { canEditCSS && ( - - { __( 'Additional CSS' ) } + <> + + { canEditCSS && ( + + { __( 'Additional CSS' ) } + + ) } + { + toggle( + 'core/edit-site', + 'welcomeGuideStyles' + ); + onClose(); + } } + > + { __( 'Welcome Guide' ) } + + + + { + onReset(); + onClose(); + } } + disabled={ ! canReset } + > + { __( 'Reset styles' ) } - ) } - { - toggle( - 'core/edit-site', - 'welcomeGuideStyles' - ); - onClose(); - } } - > - { __( 'Welcome Guide' ) } - - + + ) } ); } -function RevisionsCountBadge( { className, children } ) { - return ( - - { children } - - ); -} function GlobalStylesRevisionsMenu() { const { setIsListViewOpened } = useDispatch( editSiteStore ); const { revisionsCount } = useSelect( ( select ) => { @@ -128,56 +131,38 @@ function GlobalStylesRevisionsMenu() { globalStyles?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0, }; }, [] ); - const [ canReset, onReset ] = useGlobalStylesReset(); const { goTo } = useNavigator(); const { setEditorCanvasContainerView } = unlock( useDispatch( editSiteStore ) ); + const isRevisionsOpened = useSelect( + ( select ) => + 'global-styles-revisions' === + unlock( select( editSiteStore ) ).getEditorCanvasContainerView(), + [] + ); const loadRevisions = () => { setIsListViewOpened( false ); - goTo( '/revisions' ); - setEditorCanvasContainerView( 'global-styles-revisions' ); + + if ( ! isRevisionsOpened ) { + goTo( '/revisions' ); + setEditorCanvasContainerView( 'global-styles-revisions' ); + } else { + goTo( '/' ); + setEditorCanvasContainerView( undefined ); + } }; const hasRevisions = revisionsCount > 0; return ( - { canReset || hasRevisions ? ( - - { ( { onClose } ) => ( - - { hasRevisions && ( - - { revisionsCount } - - } - > - { __( 'Revision history' ) } - - ) } - { - onReset(); - onClose(); - } } - disabled={ ! canReset } - > - { __( 'Reset to defaults' ) } - - - ) } - - ) : ( -