Skip to content

Commit

Permalink
Remove unnecessary filter to inject new post link
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Apr 19, 2023
1 parent 6c25a17 commit 59bbb58
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';

const CreateNewPostLink = ( {
attributes: { query: { postType } = {} } = {},
} ) => {
if ( ! postType ) return null;
const newPostUrl = addQueryArgs( 'post-new.php', {
post_type: postType,
} );
return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
__( '<a>Add new post</a>' ),
// eslint-disable-next-line jsx-a11y/anchor-has-content
{ a: <a href={ newPostUrl } /> }
) }
</div>
);
};

export default CreateNewPostLink;
19 changes: 13 additions & 6 deletions packages/block-library/src/query/edit/inspector-controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/block-editor';
import {
InspectorControls,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { debounce } from '@wordpress/compose';
import { useEffect, useState, useCallback } from '@wordpress/element';

Expand All @@ -24,6 +27,8 @@ import AuthorControl from './author-control';
import ParentControl from './parent-control';
import { TaxonomyControls } from './taxonomy-controls';
import StickyControl from './sticky-control';
import CreateNewPostLink from './create-new-post-link';
import { unlock } from '../../../private-apis';
import {
usePostTypes,
useIsPostTypeHierarchical,
Expand All @@ -32,11 +37,10 @@ import {
useTaxonomies,
} from '../../utils';

export default function QueryInspectorControls( {
attributes,
setQuery,
setDisplayLayout,
} ) {
const { BlockInfo } = unlock( blockEditorPrivateApis );

export default function QueryInspectorControls( props ) {
const { attributes, setQuery, setDisplayLayout } = props;
const { query, displayLayout } = attributes;
const {
order,
Expand Down Expand Up @@ -127,6 +131,9 @@ export default function QueryInspectorControls( {

return (
<>
<BlockInfo>
<CreateNewPostLink { ...props } />
</BlockInfo>
{ showSettingsPanel && (
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
Expand Down
8 changes: 1 addition & 7 deletions packages/block-library/src/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { loop as icon } from '@wordpress/icons';
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
Expand All @@ -13,7 +12,6 @@ import edit from './edit';
import save from './save';
import variations from './variations';
import deprecated from './deprecated';
import queryBlockInfo from './hooks';

const { name } = metadata;
export { metadata, name };
Expand All @@ -26,8 +24,4 @@ export const settings = {
deprecated,
};

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

return initBlock( { name, metadata, settings } );
};
export const init = () => initBlock( { name, metadata, settings } );

0 comments on commit 59bbb58

Please sign in to comment.