-
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
Style Book: Close list view when opening the style book. #50438
Style Book: Close list view when opening the style book. #50438
Conversation
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 on this! Code-wise this is looking pretty good to me.
One question it raises is what to do for folks who use the Always open list view
preferences setting:
For some users, they'd like the list view to be open pretty much all the time, and it could be frustrating if the list view closes and they need to re-open it again. An example of this use case is this issue: #50141 (always keep the sidebar open)
Would it be worth adding a check for the showListViewByDefault
preferences setting, and only closing the list view if that value is falsy?
Thanks so much for the review, Andrew!
I think that setting is meant to work (have an effect) while being in edit mode and having access to blocks. So, I'm adding a check to respect the setting when "closing" the style book and returning to "edit mode". And also respecting things when the X is clicked. Screen.Recording.2023-05-12.at.10.26.16.movWhen the user is in the "style book" context, the list view doesn't affect the canvas, and as a result, it becomes useless. That was my interpretation of the issue, and that's why I'm closing it in that state. |
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.
Nicely thought through @juanfra! I think that behaviour addresses the main concern that I had, and it's testing well for me with Always open list view
switched on, and switched off 👍
Just left a question about the addition of the setCanvasMode( 'edit' );
line, as it could wind up conflicting with other explorations into rendering the EditorCanvasContainer
in browse mode. What do you think?
@@ -66,6 +66,7 @@ function EditorCanvasContainer( { children, closeButtonLabel, onClose } ) { | |||
if ( typeof onClose === 'function' ) { | |||
onClose(); | |||
} | |||
setCanvasMode( 'edit' ); |
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.
Switching to editor mode when the container is closed might not always be desirable. Separately to this PR, oven in #50566, I'm exploring rendering the Style Book via the editor canvas container, but not within the edit
mode. In that case, closing the Style Book shouldn't switch modes.
Is it possible to otherwise retain the behaviour in this PR without having to explicitly set the mode here?
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.
I agree with @andrewserong - the editor canvas container component should be able to function in any editor "mode", and shouldn't therefore affect how other components use it.
What about passing your desired functionality in the onClose
prop?
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.
Thank you! sure, I will update the PR. I was trying to avoid having to duplicate code
Thank you, @andrewserong! Yes, I added that, so it also respects the sidebar setting when the stylebook was "closed" by clicking the X. As setting the canvas mode to edit will perform the check for the sidebar setting. I thought the editor canvas container was always invoked in the edit context, and that's why I chose to set the canvas mode to edit on close. I wasn't aware that the work for having the style book opener on the sidebar took that direction; I see some requests to change the current behavior of having the tabs and X there; maybe it's better to wait and see the final direction there to finally adjust this one. |
Thanks, yes, it sounds like we'll most likely be hiding the tabs / close button in that PR based on feedback. If you don't mind waiting a day or two, we might have a better idea of what we need there. On the other hand, if we merge this PR as-is, it shouldn't be too hard to make subsequent changes if we need to expand the close button to work outside of the edit mode. I don't feel too strongly about it one way or the other. I might just add @ramonjd as a reviewer here, too, in case he has opinions as he's done a bunch of work on the editor canvas container lately 🙂 |
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.
This is looking very close to me, now! Looks like it might need a rebase due to #50682 landing.
One wrinkle this introduces, with the logic occurring in EditorCanvasContainer
is that now, when the the revisions view is closed, it also closes the list view. The global styles revisions view is also a feature where the list view isn't useful (clicking on a block closes the revisions view). Would it also be worth hiding the list view when the revisions container is opened? Or, would we prefer to ignore the revisions screen altogether?
Personally, I quite like the idea of keeping consistency between the style book and global styles revisions if we can, since they use similar interfaces.
What do folks think? I might just add a couple of designers as reviewers who've been active with reviewing other style book PRs, too 🙂
Thanks for working on this @juanfra
This is a tricky one! I also noticed that, if I close the list view before opening the style book, the list view will reopen when I close the style book One option that might simplify things would be to just close the list view when the container opens all the time (and not try to reinstate it). That would just required a 🤷 I tried to check for the state of the list view in function EditorCanvasContainer( { children, closeButtonLabel, onClose } ) {
const { editorCanvasContainerView, isListViewOpened } = useSelect(
( select ) => ( {
editorCanvasContainerView: unlock(
select( editSiteStore )
).getEditorCanvasContainerView(),
isListViewOpened: select( editSiteStore ).isListViewOpened(),
} ),
[]
);
const { setIsListViewOpened } = useDispatch( editSiteStore );
setIsListViewOpened( false );
const [ shouldReopenListView, setShouldReopenListView ] =
useState( isListViewOpened );
useEffect( () => {
return () => {
if ( shouldReopenListView ) {
setShouldReopenListView( false );
setIsListViewOpened( true );
}
};
}, [ shouldReopenListView ] );
...
} And it works for style book and revisions, but there's a pesky render error ( |
Thanks for the PR. I would agree that the list view isn't that useful when you're perusing the style book. I also understand that the "Always show the list view" toggle is causing some headaches here. But we also close the list view for mobile contexts. So regardless of the toggle, perhaps it's fine to just force it off? Mainly we should be careful adding too much complex code to handle the edgecase for the non-default toggle. I wonder, does #50564 change any of the math here? |
Since @andrewserong linked my issue #50141 I'd like to chime in and agree with @jasmussen that in that case it'd be totally fine to force the list view to close. However, after closing the style book the list view should be open automatically again (it it was opened before). |
While Style Book is currently only accessed via edit view, that won't always be the case. That is to say, it is helpful to think about it (and Styles in general) as a more independent feature. So +1 from me, the list view has no relation to the Style Book, so we should hide it accordingly. |
Thanks y'all for chiming in! I'm AFK until Tuesday next week, I'll return to this then and make the proper changes. |
# Conflicts: # packages/edit-site/src/components/editor-canvas-container/index.js
I came back to this one, and I think it's ready for a new review: Screen.Recording.2023-06-08.at.11.43.49.movI adjusted things so that it closes the list view when opening the stylebook in all the scenarios I could see, and then when closing the stylebook it'll open the list view only if the setting is on. |
onClick={ () => | ||
onClick={ () => { | ||
setIsListViewOpened( | ||
isStyleBookOpened && showListViewByDefault |
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.
This PR is working well for the style book for me. Thank you!
I was wondering if, while we're at it, we could give the same treatment to the revisions panel.
I think, along with the changes in this PR, the following would do it:
diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js
index 218665c682..bd73785e44 100644
--- a/packages/edit-site/src/components/global-styles/ui.js
+++ b/packages/edit-site/src/components/global-styles/ui.js
@@ -47,6 +47,7 @@ const { Slot: GlobalStylesMenuSlot, Fill: GlobalStylesMenuFill } =
function GlobalStylesActionMenu() {
const { toggle } = useDispatch( preferencesStore );
+ const { setIsListViewOpened } = useDispatch( editSiteStore );
const { canEditCSS, revisionsCount } = useSelect( ( select ) => {
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } =
select( coreStore );
@@ -71,6 +72,7 @@ function GlobalStylesActionMenu() {
);
const loadCustomCSS = () => goTo( '/css' );
const loadRevisions = () => {
+ setIsListViewOpened( false );
goTo( '/revisions' );
setEditorCanvasContainerView( 'global-styles-revisions' );
};
If it ends up causing other problems, then don't worry about it :)
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 looking into this. Sure, I will add those changes.
Working well for me, thanks for working on this @juanfra For the revisions & style book views: Checked from styles sidebar (LHS in view mode) and in edit mode in the RHS settings sidebar. I think it's good to go, but might double check with @andrewserong, who is an expert at finding edge cases 😄 |
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 the ping, this is testing nicely for me, too!
✅ When opening Revisions or Style Book, the list view closes
✅ When clicking the close button or toggling the Style Book icon, closing respects the list view display setting in preferences
There are a couple of cases that aren't covered for the always open list view setting (closing the global styles sidebar via the toggle button in the top toolbar, or via the close button in the right hand sidebar), but I think the current functionality in this PR is a good place to land, as I don't think it's really worth it to add more complexity for handling that case. The current behaviour captures the main closure behaviour, and in practice, it's feeling quite nice to use to me.
LGTM, thanks for persisting with this one! ✨
Thank you for the thoughtful reviews ✨ I'm merging this one now. Maybe an audit for the "always open" list view setting, and how it behaves in different flows could be a nice next step |
…0438) * Close list view when opening the style book. * Respect the preference for showing the list view by default when toggling the style book. * Set canvas mode to edit on close. * Use `get` instead of `isFeatureActive` which is deprecated. * Apply suggestions from code review. * Force closing list view when opening stylebook from site navigation. * Close the list view when opening the revisions.
What?
Closing the list block when opening the style book.
Fixes: #50409
Why?
List view is not accessible when Style Book is opened (which is good, as it's irrelevant to Style Book).
How?
Testing Instructions
Screenshots or screencast
Screen.Recording.2023-05-08.at.17.04.56.mov