Skip to content

Commit 4afd85c

Browse files
committed
Query Loop: Don't overwrite the 'query.inherit' attribute value
1 parent e21e46a commit 4afd85c

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

packages/block-library/src/query/edit/query-content.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { useEffect, useCallback } from '@wordpress/element';
77
import {
88
BlockControls,
99
InspectorControls,
10+
Warning,
1011
useBlockProps,
1112
store as blockEditorStore,
1213
useInnerBlocksProps,
1314
} from '@wordpress/block-editor';
14-
import { SelectControl } from '@wordpress/components';
15+
import { Button, SelectControl } from '@wordpress/components';
1516
import { __ } from '@wordpress/i18n';
1617
import { store as coreStore } from '@wordpress/core-data';
1718

@@ -98,21 +99,15 @@ export default function QueryContent( {
9899
} else if ( ! query.perPage && postsPerPage ) {
99100
newQuery.perPage = postsPerPage;
100101
}
101-
// We need to reset the `inherit` value if in a singular template, as queries
102-
// are not inherited when in singular content (e.g. post, page, 404, blank).
103-
if ( isSingular && query.inherit ) {
104-
newQuery.inherit = false;
105-
}
102+
106103
if ( !! Object.keys( newQuery ).length ) {
107104
__unstableMarkNextChangeAsNotPersistent();
108105
updateQuery( newQuery );
109106
}
110107
}, [
111108
query.perPage,
112-
query.inherit,
113-
postsPerPage,
114109
inherit,
115-
isSingular,
110+
postsPerPage,
116111
__unstableMarkNextChangeAsNotPersistent,
117112
updateQuery,
118113
] );
@@ -134,6 +129,8 @@ export default function QueryContent( {
134129
displayLayout: { ...displayLayout, ...newDisplayLayout },
135130
} );
136131

132+
const hasInheritanceWarning = isSingular && inherit;
133+
137134
return (
138135
<>
139136
<EnhancedPaginationModal
@@ -178,7 +175,30 @@ export default function QueryContent( {
178175
clientId={ clientId }
179176
/>
180177
</InspectorControls>
181-
<TagName { ...innerBlocksProps } />
178+
{ hasInheritanceWarning ? (
179+
<div { ...blockProps }>
180+
<Warning
181+
actions={ [
182+
<Button
183+
__next40pxDefaultSize
184+
key="switch"
185+
onClick={ () =>
186+
updateQuery( { inherit: false } )
187+
}
188+
variant="primary"
189+
>
190+
{ __( 'Switch to Custom' ) }
191+
</Button>,
192+
] }
193+
>
194+
{ __(
195+
'Cannot inherit the global queries when placed inside the singular content'
196+
) }
197+
</Warning>
198+
</div>
199+
) : (
200+
<TagName { ...innerBlocksProps } />
201+
) }
182202
</>
183203
);
184204
}

0 commit comments

Comments
 (0)