From 6db0fd730ea2cae2208091792c45a9eea215dc96 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 9 Dec 2024 19:18:31 -0500 Subject: [PATCH 1/2] Add more whitespace. --- src/variations/controls.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/variations/controls.js b/src/variations/controls.js index 5120681..7c91067 100644 --- a/src/variations/controls.js +++ b/src/variations/controls.js @@ -6,6 +6,7 @@ import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { createBlock } from '@wordpress/blocks'; + /** * Internal dependencies */ From 0e94613ec489f7b8e10a6676c0fa9436503f264c Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 9 Dec 2024 19:19:44 -0500 Subject: [PATCH 2/2] Derive whether to disable pagination based on the existence of the core/pagination block. --- src/components/pagination-toggle.js | 56 ++++++++++++++++------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/components/pagination-toggle.js b/src/components/pagination-toggle.js index d39c149..0c41066 100644 --- a/src/components/pagination-toggle.js +++ b/src/components/pagination-toggle.js @@ -1,31 +1,39 @@ /** * WordPress dependencies */ -import { ToggleControl } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; +import { store as blockEditorStore } from '@wordpress/block-editor'; +import { useEffect } from '@wordpress/element'; -export const PaginationToggle = ( { attributes, setAttributes } ) => { - const { query: { disable_pagination: disablePagination } = {} } = - attributes; +/** + * Check for the core/query-pagination block. + * + * @param {Array} blocks The array of innerBlocks + * @return {string|boolean} Return either the clientId or false if not found. + */ +const getPaginationBlockClientId = ( blocks ) => { + return blocks.find( ( block ) => block.name === 'core/query-pagination' ) + ?.clientId; +}; - return ( - { - setAttributes( { - query: { - ...attributes.query, - disable_pagination: ! disablePagination, - }, - } ); - } } - __nextHasNoMarginBottom - /> +export const PaginationToggle = ( { attributes, setAttributes, clientId } ) => { + const innerBlocks = useSelect( + ( select ) => + select( blockEditorStore ).getBlocksByClientId( clientId )[ 0 ] + ?.innerBlocks ); + + useEffect( () => { + setAttributes( { + query: { + ...attributes.query, + disable_pagination: ! getPaginationBlockClientId( innerBlocks ) + ? true + : false, + }, + } ); + }, [ innerBlocks, setAttributes ] ); + + // There is no UI for component. + return null; };