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

Patterns: check for edited entity content property when exporting #63227

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Jul 8, 2024

What? How?

(Maybe) fixes #63217

Ensures that content is exported when exporting custom patterns from the editor pattern side bar.

Check for item.content.raw and item.content when exporting item JSON, e.g., for a custom pattern.

This bug was reported in WordPress slack by @jeflopodev. Thank you!

Why?

The "item" passed to getJsonFromItem is fetched using getEditedEntityRecord.

getEditedEntityRecord calls getRawEntityRecord.

getRawEntityRecord maps properties to their raw values, so content.raw will be mapped to content.

Because an item can either be an entity record fetched via getEntityRecord or getEditedEntityRecord, I think we should support both formats.

Testing Instructions

  1. Head over to the site editor and duplicate a theme pattern to create a "custom pattern". Or you can create your own in the editor if you wish!
  2. Edit the custom pattern.
  3. In the pattern sidebar, click on the actions ellipsis menu and export your pattern as JSON.
  4. Check that the JSON contains your pattern's content.
  5. Also check that exporting patterns from the patterns library (for theme and custom patterns) works as expected.

Example:

{
  "__file": "wp_block",
  "title": "Test Custom Pattern",
  "content": "<!-- wp:paragraph -->\n<p>A synced pattern</p>\n<!-- /wp:paragraph -->",
  "syncStatus": ""
}
Kapture.2024-07-08.at.17.25.20.mp4
…ecord or getEditedEntityRecord check for content?.raw and content. The reason being getEditedEntityRecord calls getRawEntityRecord. getRawEntityRecord maps properties to their raw values.
@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta [Block] Pattern Affects the Patterns Block labels Jul 8, 2024
@ramonjd ramonjd self-assigned this Jul 8, 2024
Copy link

github-actions bot commented Jul 8, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Jul 8, 2024

Flaky tests detected in d5cb57e.
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/9849374854
📝 Reported issues:

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ramonjd
Copy link
Member Author

ramonjd commented Jul 8, 2024

Thanks for the quick review 🙇🏻

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix!

However, the format of the item object, which is an argument to the getJsonFromItem() function, is different in the wp/6.6 branch, so automatic cherry-pick may not work.

I did a quick test, and the following changes may be necessary in the wp/6.6 branch.

{
	//...
	content: item?.patternPost?.content?.raw || item.content,
	syncStatus:
		item?.patternPost?.wp_pattern_sync_status ||
		item.wp_pattern_sync_status,
},
@ramonjd
Copy link
Member Author

ramonjd commented Jul 9, 2024

However, the format of the item object, which is an argument to the getJsonFromItem() function, is different in the wp/6.6 branch, so automatic cherry-pick may not work.

Thanks @t-hamano

It looks like I'll need to make it reflect the state before 69a416f#diff-004f063061a2d1f93bea46f595d9d2ee876e371debd30c8027280957d47cdf2bL26 since #63042 doesn't appear to have been merged into wp/6.6

@@ -22,7 +22,10 @@ function getJsonFromItem( item: Pattern ) {
{
__file: item.type,
title: getItemTitle( item ),
content: item.content.raw,
content:
typeof item.content === 'string'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up have to do a type check anyway because "Typescript"

@ramonjd ramonjd enabled auto-merge (squash) July 9, 2024 01:46
@ramonjd ramonjd merged commit e1e4967 into trunk Jul 9, 2024
61 checks passed
@ramonjd ramonjd deleted the update/export-item-check-content-raw branch July 9, 2024 02:19
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 9, 2024
Copy link

github-actions bot commented Jul 9, 2024

There was a conflict while trying to cherry-pick the commit to the wp/6.6 branch. Please resolve the conflict manually and create a PR to the wp/6.6 branch.

PRs to wp/6.6 are similar to PRs to trunk, but you should base your PR on the wp/6.6 branch instead of trunk.

# Checkout the wp/6.6 branch instead of trunk.
git checkout wp/6.6
# Create a new branch for your PR.
git checkout -b my-branch
# Cherry-pick the commit.
git cherry-pick e1e496725c9f374a98a96879b516a8017e4ed739
# Check which files have conflicts.
git status
# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue
# Push the branch to the repository
git push origin my-branch
# Create a PR and set the base to the wp/6.6 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.
ramonjd added a commit that referenced this pull request Jul 9, 2024
Merge #63227 into wp/6.6
ramonjd added a commit that referenced this pull request Jul 9, 2024
…n exporting (#63277)

Merge #63227 into wp/6.6

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
@ramonjd ramonjd removed the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jul 9, 2024
huubl pushed a commit to huubl/gutenberg that referenced this pull request Jul 10, 2024
…rdPress#63227)

* Because an item can either be an entity record fetched via getEntityRecord or getEditedEntityRecord check for content?.raw and content. The reason being getEditedEntityRecord calls getRawEntityRecord. getRawEntityRecord maps properties to their raw values.

* Update type and add type check to keep the type linter happy

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…rdPress#63227)

* Because an item can either be an entity record fetched via getEntityRecord or getEditedEntityRecord check for content?.raw and content. The reason being getEditedEntityRecord calls getRawEntityRecord. getRawEntityRecord maps properties to their raw values.

* Update type and add type check to keep the type linter happy

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pattern Affects the Patterns Block [Type] Bug An existing feature does not function as intended
4 participants