-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query block enhanced pagination: Detect inner plugin blocks during re…
…nder (#55714) * Flag inner plugin blocks inside query loop * Improve PHP logic a little * Only disallow plugin blocks and post content * Get rid of global variables * Fix returned content from render callback * Handle composed query stacks * Disable navigation on the browser * Replace `count` with `empty` * Add PHPdocs and improve var naming * Lint PHP * Clarify docs a little * Move the disable check before preventDefault * Restore previous navigate logic * Set filter priorities back to 10 * Basic inspector warnings * Make render query filter static * Add stable modal logic * Switch back to ToggleControl * Auto remove filter when query stack is empty * Add first unit tests * Switch to inverse control * Add test case for nested queries * Prevent passing `null` to the Tag Processr * Get rid of explicit auto mode and notices * Test directives in the Pagination Previous block * Minor typos and improvements * Improve modal texts * Fix WPCS * Reorder teardowns * Reset the dirty flag after it's used * Prevent usage of post content block --------- Co-authored-by: David Arenas <[email protected]>
- Loading branch information
1 parent
16367dc
commit b483df2
Showing
8 changed files
with
439 additions
and
69 deletions.
There are no files selected for viewing
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
51 changes: 19 additions & 32 deletions
51
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 |
---|---|---|
@@ -1,58 +1,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToggleControl, Notice } from '@wordpress/components'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { BlockTitle } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useUnsupportedBlockList } from '../../utils'; | ||
import { useUnsupportedBlocks } from '../../utils'; | ||
|
||
export default function EnhancedPaginationControl( { | ||
enhancedPagination, | ||
setAttributes, | ||
clientId, | ||
} ) { | ||
const unsupported = useUnsupportedBlockList( clientId ); | ||
const { hasUnsupportedBlocks } = useUnsupportedBlocks( clientId ); | ||
|
||
let help = __( 'Browsing between pages requires a full page reload.' ); | ||
if ( enhancedPagination ) { | ||
help = __( | ||
"Browsing between pages won't require a full page reload, unless non-compatible blocks are detected." | ||
); | ||
} else if ( hasUnsupportedBlocks ) { | ||
help = __( | ||
"Force page reload can't be disabled because there are non-compatible blocks inside the Query block." | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<ToggleControl | ||
label={ __( 'Enhanced pagination' ) } | ||
help={ __( | ||
'Browsing between pages won’t require a full page reload.' | ||
) } | ||
checked={ !! enhancedPagination } | ||
disabled={ unsupported.length } | ||
label={ __( 'Force page reload' ) } | ||
help={ help } | ||
checked={ ! enhancedPagination } | ||
disabled={ hasUnsupportedBlocks } | ||
onChange={ ( value ) => { | ||
setAttributes( { | ||
enhancedPagination: !! value, | ||
enhancedPagination: ! value, | ||
} ); | ||
} } | ||
/> | ||
{ !! unsupported.length && ( | ||
<Notice | ||
status="warning" | ||
isDismissible={ false } | ||
className="wp-block-query__enhanced-pagination-notice" | ||
> | ||
{ __( | ||
"Enhanced pagination doesn't support the following blocks:" | ||
) } | ||
<ul> | ||
{ unsupported.map( ( id ) => ( | ||
<li key={ id }> | ||
<BlockTitle clientId={ id } /> | ||
</li> | ||
) ) } | ||
</ul> | ||
{ __( | ||
'If you want to enable it, you have to remove all unsupported blocks first.' | ||
) } | ||
</Notice> | ||
) } | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.