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/use unfiltered html selector #7865

Merged
merged 2 commits into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 4 additions & 10 deletions editor/components/block-edit/index.js
@@ -1,14 +1,13 @@
/**
* External dependencies
*/
import { noop, get } from 'lodash';
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { Component, compose } from '@wordpress/element';
import { withAPIData } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -27,13 +26,10 @@ export class BlockEdit extends Component {
}

getChildContext() {
const { user } = this.props;
const { canUserUseUnfilteredHTML } = this.props;

return {
canUserUseUnfilteredHTML: get( user.data, [
'capabilities',
'unfiltered_html',
], false ),
canUserUseUnfilteredHTML,
};
}

Expand Down Expand Up @@ -72,8 +68,6 @@ BlockEdit.childContextTypes = {
export default compose( [
withSelect( ( select ) => ( {
postType: select( 'core/editor' ).getEditedPostAttribute( 'type' ),
} ) ),
withAPIData( ( { postType } ) => ( {
user: `/wp/v2/users/me?post_type=${ postType }&context=edit`,
canUserUseUnfilteredHTML: select( 'core/editor' ).canUserUseUnfilteredHTML(),
} ) ),
] )( BlockEdit );
17 changes: 5 additions & 12 deletions editor/components/block-settings-menu/unknown-converter.js
@@ -1,18 +1,13 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { IconButton, withAPIData } from '@wordpress/components';
import { IconButton } from '@wordpress/components';
import { getUnknownTypeHandlerName, rawHandler, serialize } from '@wordpress/blocks';
import { compose } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';

export function UnknownConverter( { block, onReplace, small, user, role } ) {
export function UnknownConverter( { block, onReplace, small, canUserUseUnfilteredHTML, role } ) {
if ( ! block || getUnknownTypeHandlerName() !== block.name ) {
return null;
}
Expand All @@ -23,7 +18,7 @@ export function UnknownConverter( { block, onReplace, small, user, role } ) {
onReplace( block.uid, rawHandler( {
HTML: serialize( block ),
mode: 'BLOCKS',
canUserUseUnfilteredHTML: get( user, [ 'data', 'capabilities', 'unfiltered_html' ], false ),
canUserUseUnfilteredHTML,
} ) );
};

Expand All @@ -42,16 +37,14 @@ export function UnknownConverter( { block, onReplace, small, user, role } ) {

export default compose(
withSelect( ( select, { uid } ) => {
const { getBlock, getCurrentPostType } = select( 'core/editor' );
const { canUserUseUnfilteredHTML, getBlock, getCurrentPostType } = select( 'core/editor' );
return {
block: getBlock( uid ),
postType: getCurrentPostType(),
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(),
};
} ),
withDispatch( ( dispatch ) => ( {
onReplace: dispatch( 'core/editor' ).replaceBlocks,
} ) ),
withAPIData( ( { postType } ) => ( {
user: `/wp/v2/users/me?post_type=${ postType }&context=edit`,
} ) ),
)( UnknownConverter );