From 59bbb5802fdecc5160d927c200d0bb5703c83aa4 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 17 Apr 2023 18:01:43 +1000 Subject: [PATCH] Remove unnecessary filter to inject new post link --- .../create-new-post-link.js | 26 +++++++++++++++++++ .../query/edit/inspector-controls/index.js | 19 +++++++++----- packages/block-library/src/query/index.js | 8 +----- 3 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 packages/block-library/src/query/edit/inspector-controls/create-new-post-link.js diff --git a/packages/block-library/src/query/edit/inspector-controls/create-new-post-link.js b/packages/block-library/src/query/edit/inspector-controls/create-new-post-link.js new file mode 100644 index 0000000000000..ac9904f0f2d51 --- /dev/null +++ b/packages/block-library/src/query/edit/inspector-controls/create-new-post-link.js @@ -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 ( +
+ { createInterpolateElement( + __( 'Add new post' ), + // eslint-disable-next-line jsx-a11y/anchor-has-content + { a: } + ) } +
+ ); +}; + +export default CreateNewPostLink; diff --git a/packages/block-library/src/query/edit/inspector-controls/index.js b/packages/block-library/src/query/edit/inspector-controls/index.js index 95ccb43e58452..2222f7d2d1eff 100644 --- a/packages/block-library/src/query/edit/inspector-controls/index.js +++ b/packages/block-library/src/query/edit/inspector-controls/index.js @@ -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'; @@ -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, @@ -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, @@ -127,6 +131,9 @@ export default function QueryInspectorControls( { return ( <> + + + { showSettingsPanel && ( diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index c109410e58c0c..8d82391923603 100644 --- a/packages/block-library/src/query/index.js +++ b/packages/block-library/src/query/index.js @@ -2,7 +2,6 @@ * WordPress dependencies */ import { loop as icon } from '@wordpress/icons'; -import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies @@ -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 }; @@ -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 } );