-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance: Improve opening inserter in post editor (#57006)
* Performance: Improve opening inserter in post editor * make selector private
- Loading branch information
1 parent
77a8b55
commit ef65c8b
Showing
4 changed files
with
129 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils'; | ||
|
||
const EMPTY_ARRAY = []; | ||
|
||
export function getUserPatterns( state ) { | ||
const userPatterns = | ||
state?.settings?.__experimentalReusableBlocks ?? EMPTY_ARRAY; | ||
const userPatternCategories = | ||
state?.settings?.__experimentalUserPatternCategories ?? []; | ||
const categories = new Map(); | ||
userPatternCategories.forEach( ( userCategory ) => | ||
categories.set( userCategory.id, userCategory ) | ||
); | ||
return userPatterns.map( ( userPattern ) => { | ||
return { | ||
name: `core/block/${ userPattern.id }`, | ||
id: userPattern.id, | ||
type: PATTERN_TYPES.user, | ||
title: userPattern.title.raw, | ||
categories: userPattern.wp_pattern_category.map( ( catId ) => | ||
categories && categories.get( catId ) | ||
? categories.get( catId ).slug | ||
: catId | ||
), | ||
content: userPattern.content.raw, | ||
syncStatus: userPattern.wp_pattern_sync_status, | ||
}; | ||
} ); | ||
} | ||
|
||
export const checkAllowList = ( list, item, defaultResult = null ) => { | ||
if ( typeof list === 'boolean' ) { | ||
return list; | ||
} | ||
if ( Array.isArray( list ) ) { | ||
// TODO: when there is a canonical way to detect that we are editing a post | ||
// the following check should be changed to something like: | ||
// if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null ) | ||
if ( list.includes( 'core/post-content' ) && item === null ) { | ||
return true; | ||
} | ||
return list.includes( item ); | ||
} | ||
return defaultResult; | ||
}; | ||
|
||
export const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => { | ||
if ( typeof allowedBlockTypes === 'boolean' ) { | ||
return allowedBlockTypes; | ||
} | ||
|
||
const blocksQueue = [ ...blocks ]; | ||
while ( blocksQueue.length > 0 ) { | ||
const block = blocksQueue.shift(); | ||
|
||
const isAllowed = checkAllowList( | ||
allowedBlockTypes, | ||
block.name || block.blockName, | ||
true | ||
); | ||
if ( ! isAllowed ) { | ||
return false; | ||
} | ||
|
||
block.innerBlocks?.forEach( ( innerBlock ) => { | ||
blocksQueue.push( innerBlock ); | ||
} ); | ||
} | ||
|
||
return true; | ||
}; |
ef65c8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in ef65c8b.
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/7193286921
📝 Reported issues:
/test/e2e/specs/site-editor/font-library.spec.js