Skip to content

Commit

Permalink
Block Directory: Optimize DownloadableBlocksPanel (#47679)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Feb 2, 2023
1 parent 1929bdc commit b0275ae
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import DownloadableBlocksInserterPanel from './inserter-panel';
import DownloadableBlocksNoResults from './no-results';
import { store as blockDirectoryStore } from '../../store';

const EMPTY_ARRAY = [];

function DownloadableBlocksPanel( {
downloadableItems,
onSelect,
Expand Down Expand Up @@ -81,14 +83,25 @@ export default compose( [
);

function getInstallableBlocks( term ) {
return getDownloadableBlocks( term ).filter( ( block ) =>
const downloadableBlocks = getDownloadableBlocks( term );
const installableBlocks = downloadableBlocks.filter( ( block ) =>
canInsertBlockType( block, rootClientId, true )
);

if ( downloadableBlocks.length === installableBlocks.length ) {
return downloadableBlocks;
}
return installableBlocks;
}

const downloadableItems = hasPermission
let downloadableItems = hasPermission
? getInstallableBlocks( filterValue )
: [];

if ( downloadableItems.length === 0 ) {
downloadableItems = EMPTY_ARRAY;
}

const isLoading = isRequestingDownloadableBlocks( filterValue );

return {
Expand Down

1 comment on commit b0275ae

@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 b0275ae.
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/4074237969
📝 Reported issues:

Please sign in to comment.