Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating DownloadableBlocksList to use updated Composite implementation #55272

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading