-
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
Embed block refactor and tidy #10958
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.
❤️ This is looking really tidy! Would be really happy to see this merged as is, though I left a few minor comments.
|
||
this.props.setAttributes( | ||
{ | ||
allowResponsive: ! allowResponsive, | ||
className: classnames( className, responsiveClassNames ), | ||
className: getClassNames( html, className, responsive && ! allowResponsive ), |
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.
Just wondering what the responsive
variable is, is it whether the type of embed supports responsiveness?
On a separate note, it might be nice to extract ! allowResponsive
into a separate variable so that it doesn't have to be repeated.
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, responsive
is a flag for if the block allows responsive content or not.
<Spinner /> | ||
<p>{ __( 'Embedding…' ) }</p> | ||
</div> | ||
<EmbedLoading /> |
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.
❤️ that these are now separate components, makes the rendering logic so much more understandable.
@@ -90,7 +90,8 @@ export function getEmbedEditComponent( title, icon, responsive = true ) { | |||
previewDocument.body.innerHTML = html; | |||
const iframe = previewDocument.body.querySelector( 'iframe' ); | |||
|
|||
if ( ! isFromWordPress( html ) && iframe && iframe.height && iframe.width ) { | |||
// If we have a fixed aspect iframe, and it's a responsive embed block. | |||
if ( responsive && iframe && iframe.height && iframe.width ) { |
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.
Looks like the ! isFromWordPress( html )
was lost in the merge, not sure if that's an issue or if it has been replace by the responsive variable.
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.
Replaced by the responsive flag :)
} from '@wordpress/components'; | ||
import { RichText, BlockControls, BlockIcon, InspectorControls } from '@wordpress/editor'; | ||
|
||
export const EmbedLoading = () => ( |
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.
Massive improvement that these are extracted, though I think now they could go in their own files 😄
); | ||
}; | ||
|
||
export const EmbedEditUrl = ( props ) => { |
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 could potentially be called EmbedPlaceholder, which would make it consistent with the MediaPlaceholder that's used in the various media blocks.
* @return {string} Deduped class names. | ||
*/ | ||
export function getClassNames( html, existingClassNames = '', allowResponsive = true ) { | ||
const previewDocument = document.implementation.createHTMLDocument( '' ); |
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 suppose one future improvement is that this function is quite expensive when allowResponsive
is false, when really all it has to do is strip the responsive classnames out of the string.
/** | ||
* Returns class names with any relevant responsive aspect ratio names. | ||
* | ||
* @param {string} html The preview HTML that possibly contains an iframe with width and height set. |
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.
Nitpick, I think the params are supposed to be lined up like they are here:
gutenberg/packages/core-data/src/entities.js
Lines 57 to 66 in 55d5aac
/** | |
* Returns the entity's getter method name given its kind and name. | |
* | |
* @param {string} kind Entity kind. | |
* @param {string} name Entity name. | |
* @param {string} prefix Function prefix. | |
* @param {boolean} usePlural Whether to use the plural form or not. | |
* | |
* @return {string} Method name | |
*/ |
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.
Although it's actually really hard to find a good example of this, and I'm sure I just created some doc blocks where they weren't lined up myself 🤦♂️
@talldan thanks! Those points look simple enough to address. Will get on it! |
All these should be addressed now. I also renamed some variables in the controls component to make it clear when responsive support was at the theme and block level. |
@talldan could you give this a quick look over before I merge? Just want to make sure I haven't introduced any other problems :) |
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.
@notnownikki Changes look really good 👍
The only minor comment is that It'd be nice to remove the components.js file and import the components directly in edit.js.
</Placeholder> | ||
); | ||
}; | ||
export { default as EmbedControls } from './embed-controls'; |
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.
Don't really need this file anymore, since the components can be imported directly from their own files in embed/edit.js
@@ -166,7 +167,8 @@ export function getEmbedEditComponent( title, icon, responsive = true ) { | |||
<Fragment> | |||
<EmbedControls | |||
showEditButton={ preview && ! cannotEmbed } | |||
supportsResponsive={ supportsResponsive } | |||
themeSupportsResponsive={ themeSupportsResponsive } | |||
blockSupportsResponsive={ responsive } |
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 like these new names 👍
* @return {string} Deduped class names. | ||
*/ | ||
export function getClassNames( html, existingClassNames = '', allowResponsive = true ) { | ||
if ( ! allowResponsive ) { |
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.
👍
…rnmobile/port-quote-block-step-1 * 'master' of https://github.com/WordPress/gutenberg: (22 commits) Add removed periods to block descriptions. (#11367) Remove findDOMNode usage from the inserter (#11363) Remove deprecated componentWillReceiveProps from TinyMCE component (#11368) Create file blocks when dropping multiple files at once (#11297) Try avoiding the deprecated findDOMNode API from DropZone Provider (#11168) Fix: make meta+A behaviour of selecting all blocks work on safari and firefox. (#8180) Remove _wpGutenbergCodeEditorSettings and wp.codeEditor assets (#11342) Remove the Cloudflare warning (#11350) Image Block: Use source_url for media file link (#11254) Enhance styling of nextpage block using the Hr element (#11354) Embed block refactor and tidy (#10958) Nonce Middleware: Wrap the nonce middleware function into it's own function that isn't regenerated on every API request. (#11347) Fix RTL block alignments (#11293) RichText: fix buggy enter/delete behaviour (#11287) Remove code coverage setup (#11198) Parser: Runs all parser implementations against the same tests (#11320) Stop trying to autosave when title and classic block content both are empty. (#10404) Fix "Mac OS" typo + use fancy quotes consistently (#11310) Update documentation link paths (#11324) Editor: Reshape blocks state under own key (#11315) ... # Conflicts: # gutenberg-mobile
Description
Refactor to use components, rename the
maybeSwitchBlock
method, and move class name calculations into a util function.How has this been tested?
e2e tests pass, new unit tests pass.
Types of changes
Refactor
Checklist: