diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index b2fd086a2a29c..59189c5b96d49 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -37,6 +37,7 @@ import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-c import AdvancedControls from '../inspector-controls-tabs/advanced-controls-panel'; import PositionControls from '../inspector-controls-tabs/position-controls-panel'; import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSettings'; +import CreateNewPostLink from '../create-new-post-link'; function useContentBlocks( blockTypes, block ) { const contentBlocksObjectAux = useMemo( () => { @@ -326,6 +327,9 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { className={ blockInformation.isSynced && 'is-synced' } /> + { blockName === 'core/query' && ( + + ) } { showTabs && ( { + const postType = useSelect( + ( select ) => { + const { getBlockAttributes } = select( blockEditorStore ); + return getBlockAttributes( clientId )?.query?.postType; + }, + [ clientId ] + ); + + 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/hooks.js b/packages/block-library/src/query/hooks.js deleted file mode 100644 index b2bb32a7be7b4..0000000000000 --- a/packages/block-library/src/query/hooks.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * WordPress dependencies - */ -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'; - -const CreateNewPostLink = ( { - attributes: { query: { postType } = {} } = {}, -} ) => { - if ( ! postType ) return null; - const newPostUrl = addQueryArgs( 'post-new.php', { - post_type: postType, - } ); - return ( -
- { createInterpolateElement( - __( 'Create a new post for this feed.' ), - // eslint-disable-next-line jsx-a11y/anchor-has-content - { a: } - ) } -
- ); -}; - -/** - * Override the default edit UI to include layout controls - * - * @param {Function} BlockEdit Original component - * @return {Function} Wrapped component - */ -const queryTopInspectorControls = createHigherOrderComponent( - ( BlockEdit ) => ( props ) => { - const { name, isSelected } = props; - if ( name !== 'core/query' || ! isSelected ) { - return ; - } - - return ( - <> - - - - - - ); - }, - 'withInspectorControls' -); - -export default queryTopInspectorControls; diff --git a/packages/block-library/src/query/index.js b/packages/block-library/src/query/index.js index baf58470b76ac..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 queryInspectorControls from './hooks'; const { name } = metadata; export { metadata, name }; @@ -26,8 +24,4 @@ export const settings = { deprecated, }; -export const init = () => { - addFilter( 'editor.BlockEdit', 'core/query', queryInspectorControls ); - - return initBlock( { name, metadata, settings } ); -}; +export const init = () => initBlock( { name, metadata, settings } );