Skip to content

Commit

Permalink
Migrating AddCustomTemplateModalContent to use updated Composite
Browse files Browse the repository at this point in the history
…implementation (#55256)

Migrating `AddCustomTemplateModalContent`
 - Removes `__unstableComposite` imports from `@wordpress/components`
 - Adds private `Composite*` exports from `@wordpress/components`
 - Refactors `SuggestionList` and `SuggestionListItem` to use updated `Composite` components
  • Loading branch information
Andrew Hayward authored Oct 12, 2023
1 parent 0e2e554 commit 1e5ab30
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,50 @@ import {
FlexItem,
SearchControl,
TextHighlight,
privateApis as componentsPrivateApis,
__experimentalText as Text,
__experimentalVStack as VStack,
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
} from '@wordpress/components';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import useDebouncedInput from '../../utils/use-debounced-input';
import { mapToIHasNameAndId } from './utils';

const {
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
useCompositeStoreV2: useCompositeStore,
} = unlock( componentsPrivateApis );

const EMPTY_ARRAY = [];

function SuggestionListItem( {
suggestion,
search,
onSelect,
entityForSuggestions,
composite,
} ) {
const baseCssClass =
'edit-site-custom-template-modal__suggestions_list__list-item';
return (
<CompositeItem
role="option"
as={ Button }
{ ...composite }
className={ baseCssClass }
onClick={ () =>
onSelect(
entityForSuggestions.config.getSpecificTemplate(
suggestion
)
)
render={
<Button
role="option"
className={ baseCssClass }
onClick={ () =>
onSelect(
entityForSuggestions.config.getSpecificTemplate(
suggestion
)
)
}
/>
}
>
<Text
Expand Down Expand Up @@ -112,7 +118,7 @@ function useSearchSuggestions( entityForSuggestions, search ) {
}

function SuggestionList( { entityForSuggestions, onSelect } ) {
const composite = useCompositeState( { orientation: 'vertical' } );
const composite = useCompositeStore( { orientation: 'vertical' } );
const [ search, setSearch, debouncedSearch ] = useDebouncedInput();
const suggestions = useSearchSuggestions(
entityForSuggestions,
Expand All @@ -136,7 +142,7 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
) }
{ !! suggestions?.length && (
<Composite
{ ...composite }
store={ composite }
role="listbox"
className="edit-site-custom-template-modal__suggestions_list"
aria-label={ __( 'Suggestions list' ) }
Expand All @@ -148,7 +154,6 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
search={ debouncedSearch }
onSelect={ onSelect }
entityForSuggestions={ entityForSuggestions }
composite={ composite }
/>
) ) }
</Composite>
Expand Down

1 comment on commit 1e5ab30

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 1e5ab30.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6495589883
📝 Reported issues:

Please sign in to comment.