-
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
Navigation: add unit tests for onChange handler and fix cases around custom links tags and post-format #31259
Conversation
Size Change: +379 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
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.
This looks like a good improvement and is a good spot.
Didn't get a chance to take this for a spin, but I did a quick code review and noticed some things.
The key is to be mindful of the mapping because the attributes and nav_menu_item fields are confusingly similar yet different.
block.attributes.type
= nav_menu_item.object
.
block.attributes.kind
= nav_menu_item.type
.
Also I'm thinking that perhaps there is a lot of this "mapping" code going to land up in the nav block/editor. Once #31004 has landed we should look to try and standardize it. Perhaps a first step is solid documentation and then perhaps some kind of schema validation?
It's not only the block attributes, and menu items, but each search result might also have a different value. 🤔 I'll go ahead and stub out some units for the search suggestion -> blockAttribute in this PR |
The unit tests were a good exercise, I found a number of other cases to sort out (for example tags uses 'tag' if inserted as a placeholder, but if a search item is actually set it persists type as 'post_tag'. Putting this back into draft until I cover/fix the rest. |
887ddc5
to
1f1a622
Compare
🤔 looks like E2Es have been a bit flakey in trunk |
url: encodeURI( url ), | ||
label, | ||
opensInNewTab, | ||
...( Number.isInteger( id ) && { id } ), |
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.
For reviewers, the block mostly uses the id value to check whether or not a post-type instance is a draft or not to control the visibility of the link in the published vew.
I double checked what gets returned for a post-format
type, from /wp/v2/search
and it's a string value vs int, so this won't get saved in that case.
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.
Yep. I have a dedicated issue open for this.
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.
Yep. I have a dedicated issue open for this.
Excellent, thanks @getdave
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.
Here is the Issue #31380
To make things easier to reason about I also added some guards in 407b236 to only setAttributes when new values are provided. This one is ready for a 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.
I tested all scenarios and they worked as described. Also the unit tests add a good level of coverage to this which is really really great. Thank you for all the work 🥇
I have approved this on it's current basis. However there are a few questions I raised so feel free to move those to a follow up or resolve them prior to merging. Happy to re-review as required.
Custom Links:
✅ Works as described
Tag
✅ Works as described
Post Formats
✅ Works as described
} = updatedValue; | ||
|
||
const normalizedTitle = title.replace( /http(s?):\/\//gi, '' ); | ||
const normalizedURL = url.replace( /http(s?):\/\//gi, '' ); |
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.
normalizedURL
and normalizedTitle
could both be the result of passing url
/ title
into a function called removeURLProtocol
which would self document the .replace()
. Just a thought...
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.
I think this would be good in a follow up PR. I was trying to retain most of the original logic here while pulling out the function.
} ); | ||
} ); | ||
// https://github.com/WordPress/gutenberg/pull/18617 | ||
it( 'label is javascript escaped', () => { |
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.
👍👍👍👍👍
👏 👏 👏 👏 👏
} ); | ||
|
||
describe( 'does not overwrite props when only some props are passed', () => { | ||
it( 'id is retained after toggling opensInNewTab', () => { |
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.
Super important 🏅
…s a custom type in block attributes
…consistently serialize post_tag as tag whether using a placeholder or full link
Thanks for the review @getdave! |
Fixes #31254 #31379
serialize.mp4
Changes of interest:
Main feedback questions:Did we intend to persist "internal/tel/URL/mailto" or is it okay to map these to a plain custom type?A: good to map to customAre post-formats and post type archives similar or different use cases?post-format is ataxonomy
with a name ofpost_format
If folks prefer, instead of adding aI think it's worth the unit tests at this point, so I'll isolate and refactor this.getNavigationLinkType
helper I can create a function for the LinkControl onChange function. It'd be a little bit of a refactor, but nice for unit testing, as we can isolate the data transform cases.Testing Instructions
Unit Tests:
npm run test-unit packages/block-library/src/navigation-link/test/edit.js
Custom Links:
Tag:
Opens In New Tab
Post Formats