-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve PagePanels performance (#51319)
* DRY up ContentBlocksList and BlockInspectorLockedBlocks Extract BlockQuickNavigation out of ContentBlocksList and BlockInspectorLockedBlocks so that we're not repeating the same code that outputs a list of block navigation links. * Add back check that ensures list items don't appear in list * Remove unnecessary CSS * Reduce amount of rerendering * Update __experimentalGetGlobalBlocksByName * Improve PagePanels performance
- Loading branch information
1 parent
c402cde
commit 4464ddb
Showing
2 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
packages/edit-site/src/components/sidebar-edit-mode/page-panels/edit-template.js
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,69 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { BlockContextProvider, BlockPreview } from '@wordpress/block-editor'; | ||
import { Button, __experimentalVStack as VStack } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../../store'; | ||
|
||
export default function EditTemplate() { | ||
const { context, hasResolved, title, blocks } = useSelect( ( select ) => { | ||
const { getEditedPostContext, getEditedPostType, getEditedPostId } = | ||
select( editSiteStore ); | ||
const { getEditedEntityRecord, hasFinishedResolution } = | ||
select( coreStore ); | ||
const _context = getEditedPostContext(); | ||
const queryArgs = [ | ||
'postType', | ||
getEditedPostType(), | ||
getEditedPostId(), | ||
]; | ||
const template = getEditedEntityRecord( ...queryArgs ); | ||
return { | ||
context: _context, | ||
hasResolved: hasFinishedResolution( | ||
'getEditedEntityRecord', | ||
queryArgs | ||
), | ||
title: template?.title, | ||
blocks: template?.blocks, | ||
}; | ||
}, [] ); | ||
|
||
const { setHasPageContentFocus } = useDispatch( editSiteStore ); | ||
|
||
const blockContext = useMemo( | ||
() => ( { ...context, postType: null, postId: null } ), | ||
[ context ] | ||
); | ||
|
||
if ( ! hasResolved ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<VStack> | ||
<div>{ decodeEntities( title ) }</div> | ||
<div className="edit-site-page-panels__edit-template-preview"> | ||
<BlockContextProvider value={ blockContext }> | ||
<BlockPreview viewportWidth={ 1024 } blocks={ blocks } /> | ||
</BlockContextProvider> | ||
</div> | ||
<Button | ||
className="edit-site-page-panels__edit-template-button" | ||
variant="secondary" | ||
onClick={ () => setHasPageContentFocus( false ) } | ||
> | ||
{ __( 'Edit template' ) } | ||
</Button> | ||
</VStack> | ||
); | ||
} |
78 changes: 26 additions & 52 deletions
78
packages/edit-site/src/components/sidebar-edit-mode/page-panels/index.js
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