From c25ae482c7d290e6f0cbeffef32a120aed8e4dc1 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:42:59 +1000 Subject: [PATCH 1/6] Move create new post link component to block editor --- .../components/create-new-post-link/index.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 packages/block-editor/src/components/create-new-post-link/index.js diff --git a/packages/block-editor/src/components/create-new-post-link/index.js b/packages/block-editor/src/components/create-new-post-link/index.js new file mode 100644 index 00000000000000..58207d640cd871 --- /dev/null +++ b/packages/block-editor/src/components/create-new-post-link/index.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( + __( 'Create a new post for this feed.' ), + // eslint-disable-next-line jsx-a11y/anchor-has-content + { a: } + ) } +
+ ); +}; + +export default CreateNewPostLink; From b815ab6382ef2409cdd10b496a03e2c0112ac57d Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:43:25 +1000 Subject: [PATCH 2/6] Remove old filter injecting create new post link --- packages/block-library/src/query/hooks.js | 53 ----------------------- packages/block-library/src/query/index.js | 8 +--- 2 files changed, 1 insertion(+), 60 deletions(-) delete mode 100644 packages/block-library/src/query/hooks.js diff --git a/packages/block-library/src/query/hooks.js b/packages/block-library/src/query/hooks.js deleted file mode 100644 index b2bb32a7be7b4e..00000000000000 --- 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 baf58470b76ac0..8d82391923603e 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 } ); From 9da619a2fcc0bc3e74258c44f203749d020e2c82 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:51:03 +1000 Subject: [PATCH 3/6] Render create new link within the block inspector --- .../src/components/block-inspector/index.js | 2 ++ .../src/components/create-new-post-link/index.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index b2fd086a2a29c7..8c7742b2e8f435 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,7 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { className={ blockInformation.isSynced && 'is-synced' } /> + { blockName === 'core/query' && } { showTabs && ( { + const postType = useSelect( ( select ) => { + const { getSelectedBlock } = select( blockEditorStore ); + return getSelectedBlock()?.attributes?.query?.postType; + } ); -const CreateNewPostLink = ( { - attributes: { query: { postType } = {} } = {}, -} ) => { if ( ! postType ) return null; const newPostUrl = addQueryArgs( 'post-new.php', { post_type: postType, } ); + return (
{ createInterpolateElement( From b62b2c1a7bf5e5b26d1a64478184a9ac73091be1 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Tue, 11 Apr 2023 09:53:31 +1000 Subject: [PATCH 4/6] Pass through clientId for attributes retrieval --- .../block-editor/src/components/block-inspector/index.js | 4 +++- .../src/components/create-new-post-link/index.js | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index 8c7742b2e8f435..59189c5b96d49c 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -327,7 +327,9 @@ const BlockInspectorSingleBlock = ( { clientId, blockName } ) => { className={ blockInformation.isSynced && 'is-synced' } /> - { blockName === 'core/query' && } + { blockName === 'core/query' && ( + + ) } { showTabs && ( { +const CreateNewPostLink = ( { clientId } ) => { const postType = useSelect( ( select ) => { - const { getSelectedBlock } = select( blockEditorStore ); - return getSelectedBlock()?.attributes?.query?.postType; + const { getBlockAttributes } = select( blockEditorStore ); + return getBlockAttributes( clientId )?.query?.postType; } ); if ( ! postType ) return null; From 3034ac4cfef53704133082ca07137422652d03b0 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:35:51 +1000 Subject: [PATCH 5/6] Reword new post link text --- .../block-editor/src/components/create-new-post-link/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/create-new-post-link/index.js b/packages/block-editor/src/components/create-new-post-link/index.js index d95a5fa80e9cd8..3145356f52aff8 100644 --- a/packages/block-editor/src/components/create-new-post-link/index.js +++ b/packages/block-editor/src/components/create-new-post-link/index.js @@ -25,7 +25,7 @@ const CreateNewPostLink = ( { clientId } ) => { return (
{ createInterpolateElement( - __( 'Create a new post for this feed.' ), + __( 'Add new post' ), // eslint-disable-next-line jsx-a11y/anchor-has-content { a: } ) } From e51184ce8d602db020b4b8d6ac2cfd591666a58a Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:13:26 +1000 Subject: [PATCH 6/6] Add missing dependency --- .../src/components/create-new-post-link/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/create-new-post-link/index.js b/packages/block-editor/src/components/create-new-post-link/index.js index 3145356f52aff8..99837ac84c0b98 100644 --- a/packages/block-editor/src/components/create-new-post-link/index.js +++ b/packages/block-editor/src/components/create-new-post-link/index.js @@ -12,10 +12,13 @@ import { useSelect } from '@wordpress/data'; import { store as blockEditorStore } from '../../store'; const CreateNewPostLink = ( { clientId } ) => { - const postType = useSelect( ( select ) => { - const { getBlockAttributes } = select( blockEditorStore ); - return getBlockAttributes( clientId )?.query?.postType; - } ); + const postType = useSelect( + ( select ) => { + const { getBlockAttributes } = select( blockEditorStore ); + return getBlockAttributes( clientId )?.query?.postType; + }, + [ clientId ] + ); if ( ! postType ) return null; const newPostUrl = addQueryArgs( 'post-new.php', {