-
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
Update/refactor converters #7885
Changes from 4 commits
e43de24
c0b7cb5
21e0327
8c8d9fe
cb4e630
0327937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { IconButton } from '@wordpress/components'; | ||
|
||
export default function ConvertToBlocks( { shouldRender, onClick, small, role } ) { | ||
if ( ! shouldRender ) { | ||
return null; | ||
} | ||
|
||
const label = __( 'Convert to Blocks' ); | ||
return ( | ||
<IconButton | ||
className="editor-block-settings-menu__control" | ||
onClick={ onClick } | ||
icon="screenoptions" | ||
label={ small ? label : undefined } | ||
role={ role } | ||
> | ||
{ ! small && label } | ||
</IconButton> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { rawHandler, getBlockContent } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/element'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ConvertToBlocks from './convertToBlocks'; | ||
|
||
export default compose( | ||
withSelect( ( select, { uid } ) => { | ||
const { getBlock, canUserUseUnfilteredHTML } = select( 'core/editor' ); | ||
const block = getBlock( uid ); | ||
return { | ||
block, | ||
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), | ||
shouldRender: ( block && block.name === 'core/html' ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { block, canUserUseUnfilteredHTML } ) => ( { | ||
onClick: () => dispatch( 'core/editor' ).replaceBlocks( | ||
block.uid, | ||
rawHandler( { | ||
HTML: getBlockContent( block ), | ||
mode: 'BLOCKS', | ||
canUserUseUnfilteredHTML, | ||
} ), | ||
), | ||
} ) ), | ||
)( ConvertToBlocks ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getUnknownTypeHandlerName, rawHandler, serialize } from '@wordpress/blocks'; | ||
import { compose } from '@wordpress/element'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ConvertToBlocks from './convertToBlocks'; | ||
|
||
export default compose( | ||
withSelect( ( select, { uid } ) => { | ||
const { canUserUseUnfilteredHTML, getBlock } = select( 'core/editor' ); | ||
const block = getBlock( uid ); | ||
return { | ||
block, | ||
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(), | ||
shouldRender: ( block && block.name === getUnknownTypeHandlerName() ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { block, canUserUseUnfilteredHTML } ) => ( { | ||
onClick: () => dispatch( 'core/editor' ).replaceBlocks( | ||
block.uid, | ||
rawHandler( { | ||
HTML: serialize( block ), | ||
mode: 'BLOCKS', | ||
canUserUseUnfilteredHTML, | ||
} ) | ||
), | ||
} ) ), | ||
)( ConvertToBlocks ); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
import ConvertToBlocksFromUnknownButton from './convertToBlocksFromUnknown'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. According to our updated coding guidelines: It would be: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Not sure how to improve the current ones 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. My point was that it reads as: Your call really. It's not a blocker for me, just my observation. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
import _BlockSettingsMenuFirstItem from './block-settings-menu-first-item'; | ||
|
||
export class BlockSettingsMenu extends Component { | ||
|
@@ -95,8 +95,8 @@ export class BlockSettingsMenu extends Component { | |
<NavigableMenu className="editor-block-settings-menu__content"> | ||
<_BlockSettingsMenuFirstItem.Slot fillProps={ { onClose } } /> | ||
{ count === 1 && <BlockModeToggle uid={ firstBlockUID } onToggle={ onClose } role="menuitem" /> } | ||
{ count === 1 && <UnknownConverter uid={ firstBlockUID } role="menuitem" /> } | ||
{ count === 1 && <HTMLConverter uid={ firstBlockUID } role="menuitem" /> } | ||
{ count === 1 && <ConvertToBlocksFromUnknownButton uid={ firstBlockUID } role="menuitem" /> } | ||
{ count === 1 && <ConvertToBlocksFromHTMLButton uid={ firstBlockUID } role="menuitem" /> } | ||
<BlockDuplicateButton uids={ uids } rootUID={ rootUID } role="menuitem" /> | ||
{ count === 1 && <SharedBlockConvertButton uid={ firstBlockUID } onToggle={ onClose } itemsRole="menuitem" /> } | ||
<div className="editor-block-settings-menu__separator" /> | ||
|
This file was deleted.
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 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.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.
good catch! Will fix when we agree on the names.