-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Styles Screen: Add link to global styles revisions #51149
Merged
andrewserong
merged 11 commits into
trunk
from
add/revisions-button-to-styles-screen-in-browse-mode
Jun 6, 2023
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9bc196c
Styles Screen: Add link to global styles revisions
andrewserong 9cb3091
Add button label
andrewserong e915ba9
Update packages/edit-site/src/components/global-styles/ui.js
andrewserong e196939
Small code quality improvements
andrewserong cee7081
Try sticking the navigation screen footer to the bottom of the screen…
andrewserong 9a6b0db
Add as span to the HStack
andrewserong 6abbc06
Update border radius and left padding so that the button lines up
andrewserong 9ca113c
Remove classnames call
andrewserong 51e26bc
Add redirect for style book, too
andrewserong 8ae9c7a
Only redirect to root when opening the style book on the revisions sc…
andrewserong e35f61b
Use truthy check for editor canvas container when redirecting from th…
andrewserong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,19 @@ | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { edit, seen } from '@wordpress/icons'; | ||
import { backup, edit, seen } from '@wordpress/icons'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components'; | ||
import { | ||
Icon, | ||
__experimentalNavigatorButton as NavigatorButton, | ||
__experimentalVStack as HStack, | ||
__experimentalVStack as VStack, | ||
} from '@wordpress/components'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { BlockEditorProvider } from '@wordpress/block-editor'; | ||
import { humanTimeDiff } from '@wordpress/date'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -19,6 +26,7 @@ import { store as editSiteStore } from '../../store'; | |
import SidebarButton from '../sidebar-button'; | ||
import SidebarNavigationItem from '../sidebar-navigation-item'; | ||
import StyleBook from '../style-book'; | ||
import useGlobalStylesRevisions from '../global-styles/screen-revisions/use-global-styles-revisions'; | ||
|
||
const noop = () => {}; | ||
|
||
|
@@ -74,13 +82,64 @@ function SidebarNavigationScreenGlobalStylesContent() { | |
onChange={ noop } | ||
onInput={ noop } | ||
> | ||
<div className="edit-site-sidebar-navigation-screen-global-styles__content"> | ||
<StyleVariationsContainer /> | ||
</div> | ||
<StyleVariationsContainer /> | ||
</BlockEditorProvider> | ||
); | ||
} | ||
|
||
function SidebarNavigationScreenGlobalStylesFooter( { onClickRevisions } ) { | ||
const { revisions, isLoading } = useGlobalStylesRevisions(); | ||
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 hasRevisions = revisionsCount >= 2; | ||
const modified = revisions?.[ 0 ]?.modified; | ||
|
||
if ( ! hasRevisions || isLoading || ! modified ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<VStack className="edit-site-sidebar-navigation-screen-global-styles__footer"> | ||
<SidebarNavigationItem | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
className="edit-site-sidebar-navigation-screen-global-styles__revisions" | ||
label={ __( 'Revisions' ) } | ||
onClick={ onClickRevisions } | ||
> | ||
<HStack | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically we need phrasing content elements inside |
||
as="span" | ||
alignment="center" | ||
spacing={ 5 } | ||
direction="row" | ||
justify="space-between" | ||
> | ||
<span className="edit-site-sidebar-navigation-screen-global-styles__revisions__label"> | ||
{ __( 'Last modified' ) } | ||
</span> | ||
<span> | ||
<time dateTime={ modified }> | ||
{ humanTimeDiff( modified ) } | ||
</time> | ||
</span> | ||
<Icon icon={ backup } style={ { fill: 'currentcolor' } } /> | ||
</HStack> | ||
</SidebarNavigationItem> | ||
</VStack> | ||
); | ||
} | ||
|
||
export default function SidebarNavigationScreenGlobalStyles() { | ||
const { openGeneralSidebar } = useDispatch( editSiteStore ); | ||
const isMobileViewport = useViewportMatch( 'medium', '<' ); | ||
|
@@ -95,19 +154,31 @@ export default function SidebarNavigationScreenGlobalStyles() { | |
[] | ||
); | ||
|
||
const openGlobalStyles = async () => | ||
Promise.all( [ | ||
setCanvasMode( 'edit' ), | ||
openGeneralSidebar( 'edit-site/global-styles' ), | ||
] ); | ||
const openGlobalStyles = useCallback( | ||
async () => | ||
Promise.all( [ | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setCanvasMode( 'edit' ), | ||
openGeneralSidebar( 'edit-site/global-styles' ), | ||
] ), | ||
[ setCanvasMode, openGeneralSidebar ] | ||
); | ||
|
||
const openStyleBook = async () => { | ||
const openStyleBook = useCallback( async () => { | ||
await openGlobalStyles(); | ||
// Open the Style Book once the canvas mode is set to edit, | ||
// and the global styles sidebar is open. This ensures that | ||
// the Style Book is not prematurely closed. | ||
setEditorCanvasContainerView( 'style-book' ); | ||
}; | ||
}, [ openGlobalStyles, setEditorCanvasContainerView ] ); | ||
|
||
const openRevisions = useCallback( async () => { | ||
await openGlobalStyles(); | ||
// Open the global styles revisions once the canvas mode is set to edit, | ||
// and the global styles sidebar is open. The global styles UI is responsible | ||
// for redirecting to the revisions screen once the editor canvas container | ||
// has been set to 'global-styles-revisions'. | ||
setEditorCanvasContainerView( 'global-styles-revisions' ); | ||
}, [ openGlobalStyles, setEditorCanvasContainerView ] ); | ||
|
||
return ( | ||
<> | ||
|
@@ -117,6 +188,11 @@ export default function SidebarNavigationScreenGlobalStyles() { | |
'Choose a different style combination for the theme styles.' | ||
) } | ||
content={ <SidebarNavigationScreenGlobalStylesContent /> } | ||
footer={ | ||
<SidebarNavigationScreenGlobalStylesFooter | ||
onClickRevisions={ openRevisions } | ||
/> | ||
} | ||
actions={ | ||
<> | ||
{ ! isMobileViewport && ( | ||
|
15 changes: 15 additions & 0 deletions
15
packages/edit-site/src/components/sidebar-navigation-screen-global-styles/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.edit-site-sidebar-navigation-screen-global-styles__footer { | ||
padding-left: $grid-unit-15; | ||
} | ||
|
||
.edit-site-sidebar-navigation-screen-global-styles__revisions { | ||
border-radius: $radius-block-ui; | ||
|
||
&:not(:hover) { | ||
color: $gray-200; | ||
|
||
.edit-site-sidebar-navigation-screen-global-styles__revisions__label { | ||
color: $gray-600; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working this one out! I can now switch between views.
Do you think it would be okay to keep it generic, that is, if any container view is open? I'm wondering in case another container view is added down the road.
I tested and it appears to work for this situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Yes, keeping it generic will help if and when we add any other container views as this logic should redirect away from the revisions screen if the container view is anything other than revisions and we're on the revisions screen 👍
That appears to work well to me, too, so I've committed in e35f61b with a slightly updated comment.