Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Revisions: Remove style revisions dropdown menu #56454

Merged
merged 8 commits into from
Nov 27, 2023
14 changes: 14 additions & 0 deletions packages/edit-site/src/components/global-styles/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ import {
__experimentalView as View,
__experimentalNavigatorToParentButton as NavigatorToParentButton,
} from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { isRTL, __ } from '@wordpress/i18n';
import { chevronRight, chevronLeft } from '@wordpress/icons';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

function ScreenHeader( { title, description } ) {
const { setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);

return (
<VStack spacing={ 0 }>
<View>
Expand All @@ -27,6 +38,9 @@ function ScreenHeader( { title, description } ) {
icon={ isRTL() ? chevronRight : chevronLeft }
isSmall
aria-label={ __( 'Navigate to the previous view' ) }
onClick={ () =>
setEditorCanvasContainerView( undefined )
}
apeatling marked this conversation as resolved.
Show resolved Hide resolved
/>
<Spacer>
<Heading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function ScreenRevisions() {

const onCloseRevisions = () => {
goTo( '/' ); // Return to global styles main panel.
setEditorCanvasContainerView( undefined );
};

const restoreRevision = ( revision ) => {
Expand Down Expand Up @@ -116,10 +117,18 @@ function ScreenRevisions() {
!! currentlySelectedRevisionId && ! selectedRevisionMatchesEditorStyles;
const shouldShowRevisions = ! isLoading && revisions.length;

const revisionsCountBadge = () => {
if ( revisions.length ) {
apeatling marked this conversation as resolved.
Show resolved Hide resolved
return ' (' + revisions.length + ')';
}

return '';
};

return (
<>
<ScreenHeader
title={ __( 'Revisions' ) }
title={ __( 'Revisions' ) + revisionsCountBadge() }
apeatling marked this conversation as resolved.
Show resolved Hide resolved
description={ __(
'Click on previously saved styles to preview them. To restore a selected version to the editor, hit "Apply." When you\'re ready, use the Save button to save your changes.'
) }
Expand Down
133 changes: 59 additions & 74 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -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 } =
Expand All @@ -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 (
<GlobalStylesMenuFill>
<DropdownMenu icon={ moreVertical } label={ __( 'More' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ canEditCSS && (
<MenuItem onClick={ loadCustomCSS }>
{ __( 'Additional CSS' ) }
<>
<MenuGroup>
{ canEditCSS && (
<MenuItem onClick={ loadCustomCSS }>
{ __( 'Additional CSS' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
toggle(
'core/edit-site',
'welcomeGuideStyles'
);
onClose();
} }
>
{ __( 'Welcome Guide' ) }
</MenuItem>
</MenuGroup>
<MenuGroup>
<MenuItem
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! canReset }
>
{ __( 'Reset styles' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
toggle(
'core/edit-site',
'welcomeGuideStyles'
);
onClose();
} }
>
{ __( 'Welcome Guide' ) }
</MenuItem>
</MenuGroup>
</MenuGroup>
</>
) }
</DropdownMenu>
</GlobalStylesMenuFill>
);
}

function RevisionsCountBadge( { className, children } ) {
return (
<span
className={ classnames(
className,
'edit-site-global-styles-sidebar__revisions-count-badge'
) }
apeatling marked this conversation as resolved.
Show resolved Hide resolved
>
{ children }
</span>
);
}
function GlobalStylesRevisionsMenu() {
const { setIsListViewOpened } = useDispatch( editSiteStore );
const { revisionsCount } = useSelect( ( select ) => {
Expand All @@ -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 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;
const isRevisionsOpened = useSelect(
( select ) =>
apeatling marked this conversation as resolved.
Show resolved Hide resolved
'global-styles-revisions' ===
unlock( select( editSiteStore ) ).getEditorCanvasContainerView(),
[]
);

return (
<GlobalStylesMenuFill>
{ canReset || hasRevisions ? (
<DropdownMenu icon={ backup } label={ __( 'Revisions' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ hasRevisions && (
<MenuItem
onClick={ loadRevisions }
icon={
<RevisionsCountBadge>
{ revisionsCount }
</RevisionsCountBadge>
}
>
{ __( 'Revision history' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! canReset }
>
{ __( 'Reset to defaults' ) }
</MenuItem>
</MenuGroup>
) }
</DropdownMenu>
) : (
<Button
label={ __( 'Revisions' ) }
icon={ backup }
disabled
__experimentalIsFocusable
/>
) }
<Button
label={ __( 'Revisions' ) }
icon={ backup }
onClick={ loadRevisions }
disabled={ ! hasRevisions }
isPressed={ isRevisionsOpened }
/>
</GlobalStylesMenuFill>
);
}
Expand Down
Loading