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

Block Directory: Optimize DownloadableBlocksPanel #47679

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
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