-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query Loop: Allow "enhanced pagination" only with core blocks (#54347)
* Move enhanced pagination control to its own file * Add hook to detect third-party blocks * Disable toggle when third-party blocks are found * Add modal to disable enhance pagination * Remove spokenMessage null * Check for third-party blocks inside Query Loop * Improve descriptions * Remove undo button * Open the modal with a useEffect
- Loading branch information
Showing
6 changed files
with
152 additions
and
37 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
packages/block-library/src/query/edit/enhanced-pagination-modal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Button, | ||
Modal, | ||
__experimentalVStack as VStack, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useContainsThirdPartyBlocks } from '../utils'; | ||
|
||
const disableEnhancedPaginationDescription = __( | ||
'Third-party blocks are not supported inside a Query Loop block with enhanced pagination enabled. To re-enable it, remove any third-party block and then update it in the Query Loop settings.' | ||
); | ||
|
||
const modalDescriptionId = | ||
'wp-block-query-enhanced-pagination-modal__description'; | ||
|
||
export default function EnhancedPaginationModal( { | ||
clientId, | ||
attributes: { enhancedPagination }, | ||
setAttributes, | ||
} ) { | ||
const [ isOpen, setOpen ] = useState( false ); | ||
|
||
const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId ); | ||
|
||
useEffect( () => { | ||
setOpen( containsThirdPartyBlocks && enhancedPagination ); | ||
}, [ containsThirdPartyBlocks, enhancedPagination, setOpen ] ); | ||
|
||
return ( | ||
isOpen && ( | ||
<Modal | ||
title={ __( 'Enhanced pagination will be disabled' ) } | ||
className={ 'wp-block-query-enhanced-pagination-modal' } | ||
aria={ { | ||
describedby: modalDescriptionId, | ||
} } | ||
isDismissible={ false } | ||
shouldCloseOnEsc={ false } | ||
shouldCloseOnClickOutside={ false } | ||
> | ||
<VStack alignment="right" spacing={ 8 }> | ||
<span id={ modalDescriptionId }> | ||
{ disableEnhancedPaginationDescription } | ||
</span> | ||
<Button | ||
variant="primary" | ||
onClick={ () => { | ||
setAttributes( { enhancedPagination: false } ); | ||
} } | ||
> | ||
{ __( 'OK, understood' ) } | ||
</Button> | ||
</VStack> | ||
</Modal> | ||
) | ||
); | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/block-library/src/query/edit/inspector-controls/enhanced-pagination-control.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToggleControl, Notice } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useContainsThirdPartyBlocks } from '../../utils'; | ||
|
||
export default function EnhancedPaginationControl( { | ||
enhancedPagination, | ||
setAttributes, | ||
clientId, | ||
} ) { | ||
const enhancedPaginationNotice = __( | ||
'Enhanced pagination requires all descendants to be Core blocks. If you want to enable it, you have to remove all third-party blocks contained inside the Query Loop block.' | ||
); | ||
|
||
const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId ); | ||
|
||
return ( | ||
<> | ||
<ToggleControl | ||
label={ __( 'Enhanced pagination' ) } | ||
help={ __( | ||
'Browsing between pages won’t require a full page reload.' | ||
) } | ||
checked={ !! enhancedPagination } | ||
disabled={ containsThirdPartyBlocks } | ||
onChange={ ( value ) => { | ||
setAttributes( { | ||
enhancedPagination: !! value, | ||
} ); | ||
} } | ||
/> | ||
{ containsThirdPartyBlocks && ( | ||
<div> | ||
<Notice status="warning" isDismissible={ false }> | ||
{ enhancedPaginationNotice } | ||
</Notice> | ||
</div> | ||
) } | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters