-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Site Editor: add preview options component #21309
Conversation
e975a96
to
ad6e08f
Compare
Size Change: -152 B (0%) Total Size: 845 kB
ℹ️ View Unchanged
|
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.
(edit: whooops! I missed the in progress
tag and just starting going with the review request 😆 )
There are 2 things that catch my eye testing:
-
These changes seem to make the 'Preview in a new tab' link disabled in places they used to be usable. This example is taken from the standard editor for one of my pages:
Looking at the code, I'm not quite sure what would cause this. -
I'm not sure if we are missing some necessary styles in the site editor to highlight the previews, but in the standard editor we see the gray background:
This gray background isn't apparent in the site editor, which makes it difficult to determine where the preview starts:
I can't speak to what packages which things belong in, but these changes seem to make sense so far.
That's fine, I'm mostly looking for reviews to see if the approach makes sense before diving into the more details.
I noticed that too and at this point I'm not sure either.
I don't think that was the case initially in my testing but I can reproduce it now. Maybe related to some of the newer changes that I picked up with the rebase. |
e21ee4b
to
4921851
Compare
After chatting about this with @youknowriad I changed the approach and extracted the relevant components and moved them to
@Addison-Stavlo this should be resolved with latest changes.
The gray background has also been added now. |
forceIsAutosaveable={ hasActiveMetaboxes } | ||
forcePreviewLink={ isSaving ? null : undefined } | ||
/> | ||
<PostPreviewButton |
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 the old preview button and I couldn't see the use for it here since it seems to be hidden. It would be nice if someone with more experience with this code could check it out and make sure that this removal won't break something.
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.
The old preview button is shown on small screens, as indicated by the CSS you removed above, which initially sets editor-post-preview__dropdown
to display: none
, and then sets editor-post-preview
to display: none
on the small
breakpoint.
The reason for this is that the resizable previews are still not optimised to work on mobile devices, so we opted to only show them on larger screens.
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 @tellthemachines, I'll look into bringing it back.
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.
@tellthemachines I brought the old preview button back along with the required styles in dcbaf85.
a25e1ad
to
74e33ab
Compare
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! I left a couple of comments below. Also, you'll need to pop into the e2e tests and change the classnames used for targeting this component to match your changes 🙂
forceIsAutosaveable={ hasActiveMetaboxes } | ||
forcePreviewLink={ isSaving ? null : undefined } | ||
/> | ||
<PostPreviewButton |
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.
The old preview button is shown on small screens, as indicated by the CSS you removed above, which initially sets editor-post-preview__dropdown
to display: none
, and then sets editor-post-preview
to display: none
on the small
breakpoint.
The reason for this is that the resizable previews are still not optimised to work on mobile devices, so we opted to only show them on larger screens.
packages/block-editor/src/style.scss
Outdated
@@ -36,6 +36,7 @@ | |||
@import "./components/media-placeholder/style.scss"; | |||
@import "./components/multi-selection-inspector/style.scss"; | |||
@import "./components/plain-text/style.scss"; | |||
@import "./components/preview-options/style.scss"; |
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 should be moved to beneath line 55, under the marker for resizable styles, so that its contents aren't impacted by the device preview style manipulation.
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.
Updated in dcbaf85.
import { __ } from '@wordpress/i18n'; | ||
import { check } from '@wordpress/icons'; | ||
|
||
const downArrow = ( |
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.
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.
No, that one looks different, you can check it out here (also the path
value was different in that code compared to what we have 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.
So this is chevronDown
right?
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.
So this is chevronDown right?
Oh right, missed that one. Updated in 42e6399.
7b03bc2
to
dcbaf85
Compare
@tellthemachines the e2e tests are fixed now. This should be ready for another pass. :) |
dc50eb9
to
4fd6036
Compare
4fd6036
to
3e3f130
Compare
1f63e54
to
1cd4b07
Compare
> | ||
{ __( 'Mobile' ) } | ||
</MenuItem> | ||
</MenuGroup> |
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 wonder this component should just render the MenuGroup and not the whole dropdown, I guess you did it this way because you wanted to share dropdown code but it does seem like it reduces the semantic value of the component a bit. I don't see this as a blocker or anything for now, just something to think about.
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 guess you did it this way because you wanted to share dropdown code but it does seem like it reduces the semantic value of the component a bit.
Right, I didn't want to duplicate that code, but also it's somewhat coupled with useResizeCanvas
now in terms of what device strings it sets in the store. Until that is reworked somehow, I think it makes sense to keep it as is.
@include break-small() { | ||
.editor-post-preview { | ||
display: none; | ||
} | ||
|
||
.editor-post-preview__dropdown { | ||
.block-editor-post-preview__dropdown { | ||
display: flex; | ||
} | ||
} |
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 component seem to have a lot of custom styles, It looks very similar to "More Menus" or "Block Settings Menus" so I wonder why it needs all these styles and can't just rely on the default UI components styles. Maybe our UI components styles are not well thought in 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.
My aim here was to preserve the current way it looks in edit-post
completely. I think we could consider removing these, but I also think it would be better to tackle that in a separate PR.
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.
Though some of these styles exist, they are currently component-specific: that's the case with the "more menu" buttons and their selected state. The original PR to implement this was already huge, so I optimistically 😁 thought to tackle those improvements later. Other styles, such as the dropdown toggle, don't exist anywhere else afaik. Agree this should be addressed in a separate PR.
return select( 'core/edit-post' ).__experimentalGetPreviewDeviceType(); | ||
}, [] ); | ||
|
||
export default function useResizeCanvas( deviceType ) { |
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.
Should this be use-resize-canvas.js
in a "hooks" folder instead of "components"?
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'm not sure but I can look into it more. I placed it in components since that's where it was in edit-post
.
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.
yeah weird for me, we do have "hooks" folder in some packages.
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 tried to rework it here as suggested 9b90de0, not sure if it's the right way to go about it though. :)
> | ||
<MenuGroup> | ||
<div className="edit-post-header-preview__grouping-external"> | ||
<PostPreviewButton |
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.
Nit: Potentially, we could extract this to a small component somewhere ini edit-post to avoid having to add selectors... specific to this component 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 think this would make sense for the whole PreviewOptions
section here too. 🤔
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.
Refactored in 2376bfd.
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.
Left a few questions but this is looking good for me.
@@ -68,3 +70,9 @@ export function useResizeCanvas() { | |||
|
|||
return contentInlineStyles( deviceType ); | |||
} | |||
|
|||
addFilter( |
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.
Is this a new filter, did we have it before?
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.
Yes, it's a new filter.
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.
We've been avoiding adding new filters in Gutenberg as we figured that filters and hooks are not the best API for extensibility in JS.
Could you clarify why this filter is needed and do you think we should have it added in its own PR instead? We could discuss alternatives... for your use 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.
I don't think it's needed, it's just that I noticed that that's how hooks are usually organized/used (haven't worked with them so far in Gutenberg), so I figured that a request to move this to hooks folder would imply a filter.
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.
Ohhh, I guess we have a naming conflicts (react hooks vs WP hooks) 🤔
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.
But now I realize that my assumption has been wrong 😅. I pushed a revert for that in 09cfe0e.
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 good!
For some weird reason, the popover on the site editor is now opening towards the right, whereas on the post editor it still opens to the left. Might be worth setting an explicit position
value in the Dropdown component so it is consistent in both places. (How it looks on post editor seems less ambiguous as to what its parent is.)
@include break-small() { | ||
.editor-post-preview { | ||
display: none; | ||
} | ||
|
||
.editor-post-preview__dropdown { | ||
.block-editor-post-preview__dropdown { | ||
display: flex; | ||
} | ||
} |
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.
Though some of these styles exist, they are currently component-specific: that's the case with the "more menu" buttons and their selected state. The original PR to implement this was already huge, so I optimistically 😁 thought to tackle those improvements later. Other styles, such as the dropdown toggle, don't exist anywhere else afaik. Agree this should be addressed in a separate PR.
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.
Nice
Good catch @tellthemachines, I updated this in 35b9bdf. |
Description
Integrates the PreviewOptions component from the post editor in site editor context.
I extracted the
UseResizeCanvas
andPreviewOptions
component toblock-editor
package and it now only contains the devices menu, while thePreview in new tab
can be optionally added in contexts where it makes sense, like the post editor.Part of #19253.
How has this been tested?
Tested with Twenty Twenty theme.
Screenshots
Types of changes
Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist: