From 97e1803bb9cc9502929d94c9828aba44f5521513 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 18 Jan 2024 23:11:08 +0100 Subject: [PATCH 1/4] Template Part & Query: avoid server requests on mount --- .../query/edit/inspector-controls/index.js | 283 +++++++++--------- .../src/query/edit/query-content.js | 16 +- .../template-part/edit/advanced-controls.js | 5 +- .../src/template-part/edit/index.js | 19 +- 4 files changed, 159 insertions(+), 164 deletions(-) diff --git a/packages/block-library/src/query/edit/inspector-controls/index.js b/packages/block-library/src/query/edit/inspector-controls/index.js index 398016728c499..eb5abe9c24d98 100644 --- a/packages/block-library/src/query/edit/inspector-controls/index.js +++ b/packages/block-library/src/query/edit/inspector-controls/index.js @@ -12,10 +12,7 @@ import { __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { - InspectorControls, - privateApis as blockEditorPrivateApis, -} from '@wordpress/block-editor'; +import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; import { debounce } from '@wordpress/compose'; import { useEffect, useState, useCallback } from '@wordpress/element'; @@ -138,156 +135,150 @@ export default function QueryInspectorControls( props ) { { showSettingsPanel && ( - - - { showInheritControl && ( - - setQuery( { inherit: !! value } ) - } - /> - ) } - { showPostTypeControl && ( - + { showInheritControl && ( + + setQuery( { inherit: !! value } ) + } + /> + ) } + { showPostTypeControl && ( + + ) } + { showColumnsControl && ( + <> + - ) } - { showColumnsControl && ( - <> - - setDisplayLayout( { - columns: value, - } ) - } - min={ 2 } - max={ Math.max( 6, displayLayout.columns ) } - /> - { displayLayout.columns > 6 && ( - - { __( - 'This column count exceeds the recommended amount and may cause visual breakage.' - ) } - - ) } - - ) } - { showOrderControl && ( - - ) } - { showStickyControl && ( - - setQuery( { sticky: value } ) + setDisplayLayout( { + columns: value, + } ) } + min={ 2 } + max={ Math.max( 6, displayLayout.columns ) } /> - ) } - 6 && ( + + { __( + 'This column count exceeds the recommended amount and may cause visual breakage.' + ) } + + ) } + + ) } + { showOrderControl && ( + + ) } + { showStickyControl && ( + + setQuery( { sticky: value } ) + } /> - - + ) } + + ) } { ! inherit && showFiltersPanel && ( - - { - setQuery( { - author: '', - parents: [], - search: '', - taxQuery: null, - } ); - setQuerySearch( '' ); - } } - dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS } - > - { showTaxControl && ( - - Object.values( taxQuery || {} ).some( - ( terms ) => !! terms.length - ) - } - onDeselect={ () => - setQuery( { taxQuery: null } ) - } - > - - - ) } - { showAuthorControl && ( - !! authorIds } - label={ __( 'Authors' ) } - onDeselect={ () => setQuery( { author: '' } ) } - > - - - ) } - { showSearchControl && ( - !! querySearch } + { + setQuery( { + author: '', + parents: [], + search: '', + taxQuery: null, + } ); + setQuerySearch( '' ); + } } + dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS } + > + { showTaxControl && ( + + Object.values( taxQuery || {} ).some( + ( terms ) => !! terms.length + ) + } + onDeselect={ () => setQuery( { taxQuery: null } ) } + > + + + ) } + { showAuthorControl && ( + !! authorIds } + label={ __( 'Authors' ) } + onDeselect={ () => setQuery( { author: '' } ) } + > + + + ) } + { showSearchControl && ( + !! querySearch } + label={ __( 'Keyword' ) } + onDeselect={ () => setQuerySearch( '' ) } + > + setQuerySearch( '' ) } - > - - - ) } - { showParentControl && ( - !! parents?.length } - label={ __( 'Parents' ) } - onDeselect={ () => setQuery( { parents: [] } ) } - > - - - ) } - - + value={ querySearch } + onChange={ setQuerySearch } + /> + + ) } + { showParentControl && ( + !! parents?.length } + label={ __( 'Parents' ) } + onDeselect={ () => setQuery( { parents: [] } ) } + > + + + ) } + ) } ); diff --git a/packages/block-library/src/query/edit/query-content.js b/packages/block-library/src/query/edit/query-content.js index 4d9b8885cb15e..77f9fb211e335 100644 --- a/packages/block-library/src/query/edit/query-content.js +++ b/packages/block-library/src/query/edit/query-content.js @@ -112,13 +112,15 @@ export default function QueryContent( { setAttributes={ setAttributes } clientId={ clientId } /> - + + + + <> { isEntityAvailable && ( <> ) } - + ); } diff --git a/packages/block-library/src/template-part/edit/index.js b/packages/block-library/src/template-part/edit/index.js index 888f767635924..ec92996978bd6 100644 --- a/packages/block-library/src/template-part/edit/index.js +++ b/packages/block-library/src/template-part/edit/index.js @@ -9,6 +9,7 @@ import { store as blockEditorStore, __experimentalRecursionProvider as RecursionProvider, __experimentalUseHasRecursion as useHasRecursion, + InspectorControls, } from '@wordpress/block-editor'; import { Spinner, Modal, MenuItem } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; @@ -159,14 +160,16 @@ export default function TemplatePartEdit( { return ( <> - 0 } - /> + + 0 } + /> + { isPlaceholder && ( Date: Thu, 18 Jan 2024 23:39:31 +0100 Subject: [PATCH 2/4] Also EditTemplatePartMenuItem --- .../edit-site/src/hooks/template-part-edit.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/edit-site/src/hooks/template-part-edit.js b/packages/edit-site/src/hooks/template-part-edit.js index e60b7945448e7..cc5d2fc411cf3 100644 --- a/packages/edit-site/src/hooks/template-part-edit.js +++ b/packages/edit-site/src/hooks/template-part-edit.js @@ -52,16 +52,14 @@ function EditTemplatePartMenuItem( { attributes } ) { } return ( - - { - linkProps.onClick( event ); - } } - > - { __( 'Edit' ) } - - + { + linkProps.onClick( event ); + } } + > + { __( 'Edit' ) } + ); } @@ -74,7 +72,9 @@ export const withEditBlockControls = createHigherOrderComponent( <> { isDisplayed && ( - + + + ) } ); From 027341142cf4ea9fc52e9dda031028dcc0e69614 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 19 Jan 2024 09:25:12 +0100 Subject: [PATCH 3/4] Avoid BlockControls mount for all blocks --- packages/edit-site/src/hooks/template-part-edit.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/edit-site/src/hooks/template-part-edit.js b/packages/edit-site/src/hooks/template-part-edit.js index cc5d2fc411cf3..234a2ba356ee1 100644 --- a/packages/edit-site/src/hooks/template-part-edit.js +++ b/packages/edit-site/src/hooks/template-part-edit.js @@ -68,14 +68,16 @@ export const withEditBlockControls = createHigherOrderComponent( const { attributes, name } = props; const isDisplayed = name === 'core/template-part' && attributes.slug; + if ( ! isDisplayed ) { + return ; + } + return ( <> - { isDisplayed && ( - - - - ) } + + + ); }, From b20a1146f2c0e1235e5904a2c5a1fdfcff4e818e Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 19 Jan 2024 11:14:33 +0100 Subject: [PATCH 4/4] Address remounting concern --- packages/edit-site/src/hooks/template-part-edit.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/edit-site/src/hooks/template-part-edit.js b/packages/edit-site/src/hooks/template-part-edit.js index 234a2ba356ee1..1c5c47a68fbfb 100644 --- a/packages/edit-site/src/hooks/template-part-edit.js +++ b/packages/edit-site/src/hooks/template-part-edit.js @@ -68,16 +68,14 @@ export const withEditBlockControls = createHigherOrderComponent( const { attributes, name } = props; const isDisplayed = name === 'core/template-part' && attributes.slug; - if ( ! isDisplayed ) { - return ; - } - return ( <> - - - - + + { isDisplayed && ( + + + + ) } ); },