From 5e2328a0af15527726dd0175cdd944a01b107db8 Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 1 Nov 2024 15:35:08 +0000 Subject: [PATCH 1/2] Remove postTypeFromContext --- .../block-library/src/post-template/edit.js | 6 +----- .../query/edit/inspector-controls/index.js | 20 ++----------------- .../src/query/edit/query-content.js | 3 +-- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/packages/block-library/src/post-template/edit.js b/packages/block-library/src/post-template/edit.js index b28c726acfc77e..a9e279ee2c3052 100644 --- a/packages/block-library/src/post-template/edit.js +++ b/packages/block-library/src/post-template/edit.js @@ -100,7 +100,6 @@ export default function PostTemplateEdit( { } = {}, templateSlug, previewPostType, - postType: postTypeFromContext, }, attributes: { layout }, __unstableLayoutClassNames, @@ -187,10 +186,7 @@ export default function PostTemplateEdit( { } // When we preview Query Loop blocks we should prefer the current // block's postType, which is passed through block context. - const usedPostType = - postTypeFromContext && postTypeFromContext !== 'page' - ? postTypeFromContext - : previewPostType || postType; + const usedPostType = previewPostType || postType; return { posts: getEntityRecords( 'postType', usedPostType, { ...query, 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 bc900c073f648d..7d5745e190c9a7 100644 --- a/packages/block-library/src/query/edit/inspector-controls/index.js +++ b/packages/block-library/src/query/edit/inspector-controls/index.js @@ -45,15 +45,9 @@ import { useToolsPanelDropdownMenuProps } from '../../../utils/hooks'; const { BlockInfo } = unlock( blockEditorPrivateApis ); export default function QueryInspectorControls( props ) { - const { - attributes, - setQuery, - setDisplayLayout, - postTypeFromContext, - isSingular, - } = props; + const { attributes, setQuery, setDisplayLayout, isSingular } = props; const { query, displayLayout } = attributes; - let { + const { order, orderBy, author: authorIds, @@ -67,16 +61,6 @@ export default function QueryInspectorControls( props ) { parents, format, } = query; - // If a post type is set in context, update `postType` to match it, - // unless the post type is `page`, as it usually doesn't make sense to loop - // through pages. - if ( - postTypeFromContext && - postTypeFromContext !== 'page' && - postTypeFromContext !== postType - ) { - postType = postTypeFromContext; - } const allowedControls = useAllowedControls( attributes ); const showSticky = postType === 'post'; const { diff --git a/packages/block-library/src/query/edit/query-content.js b/packages/block-library/src/query/edit/query-content.js index bdfcbe0498ec4a..17eea9337823c5 100644 --- a/packages/block-library/src/query/edit/query-content.js +++ b/packages/block-library/src/query/edit/query-content.js @@ -43,7 +43,7 @@ export default function QueryContent( { tagName: TagName = 'div', query: { inherit } = {}, } = attributes; - const { templateSlug, postType } = context; + const { templateSlug } = context; const { isSingular } = getQueryContextFromTemplate( templateSlug ); const { __unstableMarkNextChangeAsNotPersistent } = useDispatch( blockEditorStore ); @@ -159,7 +159,6 @@ export default function QueryContent( { setDisplayLayout={ updateDisplayLayout } setAttributes={ setAttributes } clientId={ clientId } - postTypeFromContext={ postType } isSingular={ isSingular } /> From 08dd890c6b360aa932b335ed2cccc94a72f6316e Mon Sep 17 00:00:00 2001 From: Sarah Norris Date: Fri, 1 Nov 2024 20:19:32 +0000 Subject: [PATCH 2/2] Remove postType from Query Loop context --- packages/block-library/src/query/block.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index 2379a1d1da53cf..6ccafc50c82017 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -42,7 +42,7 @@ "default": false } }, - "usesContext": [ "postType", "templateSlug" ], + "usesContext": [ "templateSlug" ], "providesContext": { "queryId": "queryId", "query": "query",