Skip to content

Commit

Permalink
Update Query to use BlockInfo for new post link
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Apr 14, 2023
1 parent 04c6a5d commit e46f7af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions packages/block-library/src/query/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import { createHigherOrderComponent } from '@wordpress/compose';
import { InspectorControls } from '@wordpress/block-editor';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { unlock } from '../private-apis';

const { BlockInfo } = unlock( blockEditorPrivateApis );
const CreateNewPostLink = ( {
attributes: { query: { postType } = {} } = {},
} ) => {
Expand All @@ -17,7 +23,7 @@ const CreateNewPostLink = ( {
return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
__( '<a>Create a new post</a> for this feed.' ),
__( '<a>Add new post</a>' ),
// eslint-disable-next-line jsx-a11y/anchor-has-content
{ a: <a href={ newPostUrl } /> }
) }
Expand All @@ -31,7 +37,7 @@ const CreateNewPostLink = ( {
* @param {Function} BlockEdit Original component
* @return {Function} Wrapped component
*/
const queryTopInspectorControls = createHigherOrderComponent(
const queryTopBlockInfo = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name, isSelected } = props;
if ( name !== 'core/query' || ! isSelected ) {
Expand All @@ -40,14 +46,14 @@ const queryTopInspectorControls = createHigherOrderComponent(

return (
<>
<InspectorControls>
<BlockInfo>
<CreateNewPostLink { ...props } />
</InspectorControls>
</BlockInfo>
<BlockEdit key="edit" { ...props } />
</>
);
},
'withInspectorControls'
'withBlockInfo'
);

export default queryTopInspectorControls;
export default queryTopBlockInfo;
4 changes: 2 additions & 2 deletions packages/block-library/src/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import edit from './edit';
import save from './save';
import variations from './variations';
import deprecated from './deprecated';
import queryInspectorControls from './hooks';
import queryBlockInfo from './hooks';

const { name } = metadata;
export { metadata, name };
Expand All @@ -27,7 +27,7 @@ export const settings = {
};

export const init = () => {
addFilter( 'editor.BlockEdit', 'core/query', queryInspectorControls );
addFilter( 'editor.BlockEdit', 'core/query', queryBlockInfo );

return initBlock( { name, metadata, settings } );
};

0 comments on commit e46f7af

Please sign in to comment.