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

Update/refactor converters #7885

Merged
merged 6 commits into from
Jul 12, 2018
Merged

Update/refactor converters #7885

merged 6 commits into from
Jul 12, 2018

Conversation

oandregal
Copy link
Member

Follows up #7667

  • Refactors converters to share common UI functionality
  • Delete some unused properties (postType)

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

We try to keep one component per file whenever it makes sense. In 99% of cases it does. We can refactor this PR to follow the same principle.

What do you think about having the following structure instead:

-- block-setting-menu
    -- converter.js
    -- html-converter.js
    -- unknown-converter.js

We can also use ifCondition HOC to make those implementation components really simple:

//  unknown-converter.js
/**
 * WordPress dependencies
 */
import { ifCondition } from '@wordpress/components';

/**
 * Internal dependencies
 */
import Converter from './converter';

export ifCondition(
   ( { block } ) => block && block.name === getUnknownTypeHandlerName()
)( Converter );

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
Copy link
Member

Choose a reason for hiding this comment

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

This is a nice example of how much you can achieve using only packages offered by Gutenberg 💯

Copy link
Member Author

@oandregal oandregal Jul 11, 2018

Choose a reason for hiding this comment

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

Didn't realize that! :gutenberg-power:

shouldRender: ( block && block.name === getUnknownTypeHandlerName() ),
};
} ),
withDispatch( ( dispatch, { block, canUserUseUnfilteredHTML } ) => ( {
Copy link
Member

Choose a reason for hiding this comment

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

Please note that withSelect and withDispatch differ only in one line:

shouldRender: ( block && block.name === getUnknownTypeHandlerName() ),
// vs
shouldRender: ( block && block.name === 'core/html' ),

onClick: () => dispatch( 'core/editor' ).replaceBlocks(
block.uid,
rawHandler( {
HTML: serialize( block ),
Copy link
Member

Choose a reason for hiding this comment

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

I now see:
serialize vs getBlockContent

Copy link
Member

Choose a reason for hiding this comment

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

it might be more difficult to refactor the way I proposed, having two withDispatch implementation is also the way to go.

@oandregal
Copy link
Member Author

@gziolo components live now in their own file, is there anything else we can do to improve this or would this be ready to merge?

@@ -21,8 +21,8 @@ import BlockDuplicateButton from './block-duplicate-button';
import BlockRemoveButton from './block-remove-button';
import SharedBlockConvertButton from './shared-block-convert-button';
import SharedBlockDeleteButton from './shared-block-delete-button';
import UnknownConverter from './unknown-converter';
import HTMLConverter from './html-converter';
import ConvertToBlocksFromHTMLButton from './convertToBlocksFromHTML';
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that file names use camel case notation, which differs from all other files as you can see above. Other file names also end with -button which aligns with the component name.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! Will fix when we agree on the names.

import UnknownConverter from './unknown-converter';
import HTMLConverter from './html-converter';
import ConvertToBlocksFromHTMLButton from './convertToBlocksFromHTML';
import ConvertToBlocksFromUnknownButton from './convertToBlocksFromUnknown';
Copy link
Member

Choose a reason for hiding this comment

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

ConvertToBlocksFromUnknownButton - it would be nice to find a different name. At the moment the colocation of unknown and button is a bit unfortunate :(

HtmlToBlocksConvertButton - how about this?

Copy link
Member

@gziolo gziolo Jul 12, 2018

Choose a reason for hiding this comment

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

According to our updated coding guidelines:
https://github.com/WordPress/gutenberg/blob/4263e556fc889206fee5b22d54a1cd910f4e586b/docs/reference/coding-guidelines.md#abbreviations-and-acronyms

It would be: HTMLToBlocksConvertButton and UnknownToBlocksConvertButton.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to find a name that collocates the three components together, like SharedBlockConvertButton and SharedBlockConvertButton convey that they act on shared blocks.

Not sure how to improve the current ones 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

How about BlockConverterFromHTMLButton and BlockConverterFromUnknownButton? That way we follow the current naming schema (other files either start by block or shared-block).

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

My point was that it reads as:
from HTML button and from unknown button
vs
blocks convert button

Your call really. It's not a blocker for me, just my observation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I appreciate the time you've invested to share that observation and to help me figure out this!

In 0327937 I decided for BlockUnknownConvertButton and BlockHTMLConvertButton which addresses the concerns and is more in line with our current naming schema. We can iterate later if necessary.

@gziolo
Copy link
Member

gziolo commented Jul 12, 2018

😃

@oandregal oandregal merged commit 0eb1d6d into master Jul 12, 2018
@oandregal oandregal deleted the update/refactor-converters branch July 12, 2018 09:14
@mtias mtias added this to the 3.3 milestone Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants