Skip to content

Commit

Permalink
Migrating DownloadableBlocksList to use updated Composite impleme…
Browse files Browse the repository at this point in the history
…ntation (#55272)

Migrating `DownloadableBlocksList`
 - Removes `__unstableComposite` imports from `@wordpress/components`
 - Adds private `Composite*` exports from `@wordpress/components`
 - Refactors `DownloadableBlocksList` and `DownloadableBlockListItem` to use updated `Composite` components
  • Loading branch information
Andrew Hayward authored Oct 12, 2023
1 parent 6afcd18 commit 235a9da
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block-directory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@wordpress/icons": "file:../icons",
"@wordpress/notices": "file:../notices",
"@wordpress/plugins": "file:../plugins",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/url": "file:../url",
"change-case": "^4.1.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Button,
Spinner,
VisuallyHidden,
__unstableCompositeItem as CompositeItem,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { decodeEntities } from '@wordpress/html-entities';
Expand All @@ -20,6 +20,9 @@ import BlockRatings from '../block-ratings';
import DownloadableBlockIcon from '../downloadable-block-icon';
import DownloadableBlockNotice from '../downloadable-block-notice';
import { store as blockDirectoryStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { CompositeItemV2: CompositeItem } = unlock( componentsPrivateApis );

// Return the appropriate block item label, given the block data and status.
function getDownloadableBlockLabel(
Expand Down Expand Up @@ -91,24 +94,28 @@ function DownloadableBlockListItem( { composite, item, onClick } ) {

return (
<CompositeItem
__experimentalIsFocusable
role="option"
as={ Button }
{ ...composite }
className="block-directory-downloadable-block-list-item"
onClick={ ( event ) => {
event.preventDefault();
onClick();
} }
isBusy={ isInstalling }
render={
<Button
__experimentalIsFocusable
type="button"
role="option"
className="block-directory-downloadable-block-list-item"
isBusy={ isInstalling }
onClick={ ( event ) => {
event.preventDefault();
onClick();
} }
label={ getDownloadableBlockLabel( item, {
hasNotice,
isInstalled,
isInstalling,
} ) }
showTooltip
tooltipPosition="top center"
/>
}
store={ composite }
disabled={ isInstalling || ! isInstallable }
label={ getDownloadableBlockLabel( item, {
hasNotice,
isInstalled,
isInstalling,
} ) }
showTooltip={ true }
tooltipPosition="top center"
>
<div className="block-directory-downloadable-block-list-item__icon">
<DownloadableBlockIcon icon={ icon } title={ title } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
} from '@wordpress/components';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { getBlockType } from '@wordpress/blocks';
import { useDispatch } from '@wordpress/data';

Expand All @@ -14,11 +11,14 @@ import { useDispatch } from '@wordpress/data';
*/
import DownloadableBlockListItem from '../downloadable-block-list-item';
import { store as blockDirectoryStore } from '../../store';
import { unlock } from '../../lock-unlock';

const { CompositeV2: Composite, useCompositeStoreV2: useCompositeStore } =
unlock( componentsPrivateApis );
const noop = () => {};

function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
const composite = useCompositeState();
const composite = useCompositeStore();
const { installBlockType } = useDispatch( blockDirectoryStore );

if ( ! items.length ) {
Expand All @@ -27,7 +27,7 @@ function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {

return (
<Composite
{ ...composite }
store={ composite }
role="listbox"
className="block-directory-downloadable-blocks-list"
aria-label={ __( 'Blocks available for install' ) }
Expand Down
10 changes: 10 additions & 0 deletions packages/block-directory/src/lock-unlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'@wordpress/block-directory'
);
1 change: 1 addition & 0 deletions packages/private-apis/src/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* The list of core modules allowed to opt-in to the private APIs.
*/
const CORE_MODULES_USING_PRIVATE_APIS = [
'@wordpress/block-directory',
'@wordpress/block-editor',
'@wordpress/block-library',
'@wordpress/blocks',
Expand Down

1 comment on commit 235a9da

@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 235a9da.
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/6496626296
📝 Reported issues:

Please sign in to comment.