Repository navigation
Site Editor: Fix template part area listing when a template has no edits #55085
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,21 +6,30 @@ import memoize from 'memize'; | |
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { isTemplatePart } from '@wordpress/blocks'; | ||
| import { isTemplatePart, parse } from '@wordpress/blocks'; | ||
|
|
||
| const EMPTY_ARRAY = []; | ||
| function getBlocksFromRecord( record ) { | ||
| if ( record?.blocks ) { | ||
| return record?.blocks; | ||
| } | ||
|
|
||
| return record?.content && typeof record.content !== 'function' | ||
| ? parse( record.content ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I didn't hit submit on my review comment for this line. I think this results in a 2023-10-06.12.15.09.mp4In 6.3, the buttons link to the template part: 2023-10-06.12.21.51.mp4
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, @andrewserong! I forgot to test the Document settings sidebar and missed the issue. You're right. Parsing the content separately will cause the |
||
| : []; | ||
| } | ||
|
|
||
| /** | ||
| * Get a flattened and filtered list of template parts and the matching block for that template part. | ||
| * | ||
| * Takes a list of blocks defined within a template, and a list of template parts, and returns a | ||
| * Takes a template, and a list of template parts, and returns a | ||
| * flattened list of template parts and the matching block for that template part. | ||
| * | ||
| * @param {Array} blocks Blocks to flatten. | ||
| * @param {Object} template Current template. | ||
| * @param {?Array} templateParts Available template parts. | ||
| * @return {Array} An array of template parts and their blocks. | ||
| */ | ||
| function getFilteredTemplatePartBlocks( blocks = EMPTY_ARRAY, templateParts ) { | ||
| function getFilteredTemplatePartBlocks( template, templateParts ) { | ||
| const blocks = getBlocksFromRecord( template ); | ||
| const templatePartsById = templateParts | ||
| ? // Key template parts by their ID. | ||
| templateParts.reduce( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.