Skip to content

Commit

Permalink
Block Directory: Optimize DownloadableBlocksPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Feb 2, 2023
1 parent 95f3eb9 commit c148f12
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

0 comments on commit c148f12

Please sign in to comment.