Skip to content

Commit

Permalink
Check presence of instant search experiment in addition to the checki…
Browse files Browse the repository at this point in the history
…ng if enhancedPagination is enabled
  • Loading branch information
michalczaplinski committed Dec 30, 2024
1 parent 4fcb01b commit 15b80fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-page-client-side-navigation' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalFullPageClientSideNavigation = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-search-query-block', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableSearchQueryBlock = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-comment', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableBlockComment = true', 'before' );
}
Expand Down
29 changes: 8 additions & 21 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,12 @@ export default function SearchEdit( {
style,
} = attributes;

const isEnhancedPagination = context?.enhancedPagination;

useEffect( () => {
if ( isEnhancedPagination ) {
// Add the name to the metadata
setAttributes( { metadata: { name: 'Instant Search' } } );
} else {
// Remove the name from the metadata
const { name, ...metadata } = attributes.metadata || {};
setAttributes( { metadata } );
}

// We disable the exhaustive-deps warning because the effect should not depend
// on the attributes.metadata value. We only want to re-run the effect when the
// isEnhancedPagination value changes.

// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ isEnhancedPagination, setAttributes ] );
// Check if the block is inside a Query block with enhanced pagination enabled
// and if the `__experimentalEnableSearchQueryBlock` flag is enabled.
const hasInstantSearch = !! (
context?.enhancedPagination &&
window?.__experimentalEnableSearchQueryBlock
);

const wasJustInsertedIntoNavigationBlock = useSelect(
( select ) => {
Expand Down Expand Up @@ -406,7 +393,7 @@ export default function SearchEdit( {
} }
className={ showLabel ? 'is-pressed' : undefined }
/>
{ ! isEnhancedPagination && (
{ ! hasInstantSearch && (
<>
<ToolbarDropdownMenu
icon={ getButtonPositionIcon() }
Expand Down Expand Up @@ -621,7 +608,7 @@ export default function SearchEdit( {
} }
showHandle={ isSelected }
>
{ isEnhancedPagination ? (
{ hasInstantSearch ? (
renderTextField()
) : (
<>
Expand Down

0 comments on commit 15b80fe

Please sign in to comment.