-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Standardise and fix parsing and serialization of blocks and nav menu items #31004
Conversation
Size Change: -185 kB (-12%) 👏 Total Size: 1.31 MB
ℹ️ View Unchanged
|
packages/block-library/src/navigation-link/fallback-variations.js
Outdated
Show resolved
Hide resolved
I've realised this is more complex than I thought. Essentially we have x2 fields on the
We also have On our
I think we need to update everything as follows:
I'll dive into this again tomorrow. |
Watch out for
|
Leaving a brain dump of the current values. I think all props are optional (we render placeholders in the editor). Some older data might be missing
gutenberg/packages/block-library/src/navigation-link/block.json Lines 1 to 35 in ee84e94
|
I think we have some flexibility in the data formats, what might help drive this is adding unit test cases for our common scenarios. If it makes sense, I think we'll want three suites:
Each suite would likely cover cases like:
|
bddea9f
to
6e726cb
Compare
This comment has been minimized.
This comment has been minimized.
…field. This field is the correct field in which to store the type of the object being stored (eg: “post”, “pages”…etc). See https://core.trac.wordpress.org/browser/tags/5.7.1/src/wp-includes/nav-menu.php#L796
✅ Fixed Screen.Capture.on.2021-04-30.at.13-20-29.mp4Good catch. Another one which @gwwar also noticed. I've been through again and I was able to replicate. The issue is that the block variation is I've decided to avoid a block migration by simply doing the conversion on the fly when mapping blocks -> menu items (and vica versa). I've added x2 specific tests to provide coverage on these and documented the reasons behind the decision in code.
✅ Fixed Screen.Capture.on.2021-04-30.at.13-21-52.movGot it! I think @gwwar picked this one up as well. I've just worked out the cause, fixed the issue and added some test coverage. |
@gwwar @talldan I looked into the Other than that I believe all the previous points have now been addressed, namely: ✅ Updated to use per block/menu item transforms rather than per property. So the only issue left is I'd say I'm ready for a final review 🤞 🙇 |
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.
Nice work @getdave this is a huge improvement on our serialization and data handling in the navigation editor! ✨
I'm giving tentative approval. ✅ Please fix the opensInNewTab
case before merge. No need for another look from me for that case if that's sorted.
I tested this by some manual smoke testing starting from various editors, and seeing if values were persisted starting from one editor or another.
Here's a quick example case:
Description
Aims to fix #29793.
This PR does two things:
core/navigation-link
block variations based on the menu item data from the database.core/navigation-link
block variation.Post
or aPage
...etc).Known Bugs
Note in the process of working on this PR I've uncovered a few more bugs which I won't attempt to fix in this PR lest it get too large. I'm noting for future reference here:
Post link
in the block sidebar (screenshot). They should probably use the title of the Custom Post Type (eg:Portfolio link
)Post Type Archive
as a result these are saved asCustom
. We need a new variation to be created. Here's how you add aPost Type Archive
to a menu. See Add Post Type Archive variation tocore/navigation-link
block #31452Other attributes aren't always parsed/serialized correctly from block -> menuItem and menuItem -> block (eg:Update: this is now resolved as part of this PR.attr_label
...etc). Once this PR is merged, we need to audit these and write some automated tests to ensure they are adding to the mapping for conversion.Custom
because the REST API endpoint forv2/search
doesn't return numeric IDs for the post formats. See Fixpost-format
serialization due to invalid REST API response forid
prop #31380How has this been tested?
Setup
Test
core/navigation-link
s should appear with the correct block variation (eg:Post Link,
Page Link,
Custom`...etc. There are a few known exceptions that don't work which - given that they have never worked - I will tackle in a follow up. These are:Post Type Archive
this will not work because we don't have a variation setup for this yet.Portfolio Categories
will show up with the block variation name beingCategory
. This needs fixing.Screenshots
Menu -> Nav Editor -> Menu
Screen.Capture.on.2021-04-23.at.13-02-18.mov
Menu -> Nav Block
Screen.Capture.on.2021-04-23.at.13-05-53.mov
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).