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

Embed block refactor and tidy #10958

Merged
merged 10 commits into from
Nov 1, 2018
Merged

Embed block refactor and tidy #10958

merged 10 commits into from
Nov 1, 2018

Conversation

notnownikki
Copy link
Member

@notnownikki notnownikki commented Oct 23, 2018

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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@notnownikki notnownikki added the [Status] In Progress Tracking issues with work in progress label Oct 23, 2018
@notnownikki notnownikki removed the [Status] In Progress Tracking issues with work in progress label Oct 29, 2018
Copy link
Contributor

@talldan talldan left a 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 ),
Copy link
Contributor

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.

Copy link
Member Author

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 />
Copy link
Contributor

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 ) {
Copy link
Contributor

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.

Copy link
Member Author

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 = () => (
Copy link
Contributor

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 ) => {
Copy link
Contributor

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( '' );
Copy link
Contributor

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.
Copy link
Contributor

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:

/**
* 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
*/

Copy link
Contributor

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 🤦‍♂️

@notnownikki
Copy link
Member Author

@talldan thanks! Those points look simple enough to address. Will get on it!

@notnownikki
Copy link
Member Author

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.

@notnownikki
Copy link
Member Author

@talldan could you give this a quick look over before I merge? Just want to make sure I haven't introduced any other problems :)

Copy link
Contributor

@talldan talldan left a 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';
Copy link
Contributor

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 }
Copy link
Contributor

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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@notnownikki notnownikki merged commit 52119c3 into master Nov 1, 2018
daniloercoli added a commit that referenced this pull request Nov 1, 2018
…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
@talldan talldan deleted the update/embed-block-refactor branch November 2, 2018 03:14
@mtias mtias added this to the 4.3 milestone Nov 12, 2018
@mtias mtias added [Block] Embed Affects the Embed Block [Type] Code Quality Issues or PRs that relate to code quality labels Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants