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 aa03a7f7751f9..6bd0289687ad7 100644 --- a/packages/block-library/src/query/edit/inspector-controls/index.js +++ b/packages/block-library/src/query/edit/inspector-controls/index.js @@ -110,6 +110,21 @@ export default function QueryInspectorControls( { showColumnsControl || showOrderControl || showStickyControl; + const showTaxControl = + !! taxonomies?.length && + isControlAllowed( allowedControls, 'taxQuery' ); + const showAuthorControl = isControlAllowed( allowedControls, 'author' ); + const showSearchControl = isControlAllowed( allowedControls, 'search' ); + const showParentControl = + isControlAllowed( allowedControls, 'parents' ) && + isPostTypeHierarchical; + + const showFiltersPanel = + showTaxControl || + showAuthorControl || + showSearchControl || + showParentControl; + return ( <> { showSettingsPanel && ( @@ -179,98 +194,80 @@ export default function QueryInspectorControls( { ) } - { ! inherit && - ( isControlAllowed( allowedControls, 'taxQuery' ) || - isControlAllowed( allowedControls, 'author' ) || - isControlAllowed( allowedControls, 'search' ) || - isControlAllowed( allowedControls, 'parents' ) ) && ( - - { - setQuery( { - author: '', - parents: [], - search: '', - taxQuery: null, - } ); - setQuerySearch( '' ); - } } - > - { !! taxonomies?.length && - isControlAllowed( - allowedControls, - 'taxQuery' - ) && ( - - Object.values( - taxQuery || {} - ).some( - ( terms ) => !! terms.length - ) - } - onDeselect={ () => - setQuery( { taxQuery: null } ) - } - > - - - ) } - { isControlAllowed( allowedControls, 'author' ) && ( - !! authorIds } - label={ __( 'Authors' ) } - onDeselect={ () => - setQuery( { author: '' } ) - } - > - - - ) } - { isControlAllowed( allowedControls, 'search' ) && ( - !! querySearch } + { ! inherit && showFiltersPanel && ( + + { + setQuery( { + author: '', + parents: [], + search: '', + taxQuery: null, + } ); + setQuerySearch( '' ); + } } + > + { 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( '' ) } - > - - - ) } - { isPostTypeHierarchical && - isControlAllowed( - allowedControls, - 'parents' - ) && ( - !! parents?.length } - label={ __( 'Parents' ) } - onDeselect={ () => - setQuery( { parents: [] } ) - } - > - - - ) } - - - ) } + value={ querySearch } + onChange={ setQuerySearch } + /> + + ) } + { showParentControl && ( + !! parents?.length } + label={ __( 'Parents' ) } + onDeselect={ () => setQuery( { parents: [] } ) } + > + + + ) } + + + ) } ); }