Skip to content

Commit f2dd6de

Browse files
DAreRodzSiobhyB
authored andcommitted
Query Loop: Disallow "enhanced pagination" with core blocks that may contain third-party blocks (#55539)
* Update useContainsThirdPartyBlocks and texts * Improve texts a bit * Show the list of unsupported blocks * Use the BlockTitle component instead * Simplify modal text
1 parent 4024d1a commit f2dd6de

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

packages/block-library/src/query/edit/enhanced-pagination-modal.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { useState, useEffect } from '@wordpress/element';
1212
/**
1313
* Internal dependencies
1414
*/
15-
import { useContainsThirdPartyBlocks } from '../utils';
15+
import { useUnsupportedBlockList } from '../utils';
1616

1717
const disableEnhancedPaginationDescription = __(
18-
'Plugin blocks are not supported yet. For the enhanced pagination to work, remove the plugin block, then re-enable "Enhanced pagination" in the Query Block settings.'
18+
'You have added unsupported blocks. For the enhanced pagination to work, remove them, then re-enable "Enhanced pagination" in the Query Block settings.'
1919
);
2020

2121
const modalDescriptionId =
@@ -28,11 +28,11 @@ export default function EnhancedPaginationModal( {
2828
} ) {
2929
const [ isOpen, setOpen ] = useState( false );
3030

31-
const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
31+
const unsupported = useUnsupportedBlockList( clientId );
3232

3333
useEffect( () => {
34-
setOpen( containsThirdPartyBlocks && enhancedPagination );
35-
}, [ containsThirdPartyBlocks, enhancedPagination, setOpen ] );
34+
setOpen( !! unsupported.length && enhancedPagination );
35+
}, [ unsupported.length, enhancedPagination, setOpen ] );
3636

3737
return (
3838
isOpen && (

packages/block-library/src/query/edit/inspector-controls/enhanced-pagination-control.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
*/
44
import { ToggleControl, Notice } from '@wordpress/components';
55
import { __ } from '@wordpress/i18n';
6+
import { BlockTitle } from '@wordpress/block-editor';
67

78
/**
89
* Internal dependencies
910
*/
10-
import { useContainsThirdPartyBlocks } from '../../utils';
11+
import { useUnsupportedBlockList } from '../../utils';
1112

1213
export default function EnhancedPaginationControl( {
1314
enhancedPagination,
1415
setAttributes,
1516
clientId,
1617
} ) {
17-
const enhancedPaginationNotice = __(
18-
"Enhanced pagination doesn't support plugin blocks yet. If you want to enable it, you have to remove all plugin blocks from the Query Loop."
19-
);
20-
21-
const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
18+
const unsupported = useUnsupportedBlockList( clientId );
2219

2320
return (
2421
<>
@@ -28,20 +25,32 @@ export default function EnhancedPaginationControl( {
2825
'Browsing between pages won’t require a full page reload.'
2926
) }
3027
checked={ !! enhancedPagination }
31-
disabled={ containsThirdPartyBlocks }
28+
disabled={ unsupported.length }
3229
onChange={ ( value ) => {
3330
setAttributes( {
3431
enhancedPagination: !! value,
3532
} );
3633
} }
3734
/>
38-
{ containsThirdPartyBlocks && (
35+
{ !! unsupported.length && (
3936
<Notice
4037
status="warning"
4138
isDismissible={ false }
4239
className="wp-block-query__enhanced-pagination-notice"
4340
>
44-
{ enhancedPaginationNotice }
41+
{ __(
42+
"Enhanced pagination doesn't support the following blocks:"
43+
) }
44+
<ul>
45+
{ unsupported.map( ( id ) => (
46+
<li key={ id }>
47+
<BlockTitle clientId={ id } />
48+
</li>
49+
) ) }
50+
</ul>
51+
{ __(
52+
'If you want to enable it, you have to remove all unsupported blocks first.'
53+
) }
4554
</Notice>
4655
) }
4756
</>

packages/block-library/src/query/utils.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,28 @@ export const usePatterns = ( clientId, name ) => {
346346
};
347347

348348
/**
349-
* Hook that returns whether the Query Loop with the given `clientId` contains
350-
* any third-party block.
349+
* Hook that returns a list of unsupported blocks inside the Query Loop with the
350+
* given `clientId`.
351351
*
352352
* @param {string} clientId The block's client ID.
353-
* @return {boolean} True if it contains third-party blocks.
353+
* @return {string[]} List of block titles.
354354
*/
355-
export const useContainsThirdPartyBlocks = ( clientId ) => {
355+
export const useUnsupportedBlockList = ( clientId ) => {
356356
return useSelect(
357357
( select ) => {
358358
const { getClientIdsOfDescendants, getBlockName } =
359359
select( blockEditorStore );
360360

361-
return getClientIdsOfDescendants( clientId ).some(
362-
( descendantClientId ) =>
363-
! getBlockName( descendantClientId ).startsWith( 'core/' )
361+
return getClientIdsOfDescendants( clientId ).filter(
362+
( descendantClientId ) => {
363+
const blockName = getBlockName( descendantClientId );
364+
return (
365+
! blockName.startsWith( 'core/' ) ||
366+
blockName === 'core/post-content' ||
367+
blockName === 'core/template-part' ||
368+
blockName === 'core/block'
369+
);
370+
}
364371
);
365372
},
366373
[ clientId ]

0 commit comments

Comments
 (0)