Fix Parent Check Condition in buildTermsTree#66006
Conversation
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @yellowmastodon. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 1.81 MB ℹ️ View Unchanged
|
| return { | ||
| children: [], | ||
| parent: null, | ||
| parent: undefined, |
There was a problem hiding this comment.
Terms fetched by getEntityRecords use parent: undefined, so we match them.
|
|
||
| describe( 'buildTermsTree()', () => { | ||
| it( 'Should return same array as input with null parent and empty children added if parent is never specified.', () => { | ||
| it( 'Should return same array as input with undefined parent and empty children added if parent is never specified.', () => { |
There was a problem hiding this comment.
Should we test both cases of null and undefined?
packages/editor/src/utils/terms.js
Outdated
| if ( | ||
| flatTermsWithParentAndChildren.some( ( { parent } ) => parent === null ) | ||
| flatTermsWithParentAndChildren.some( | ||
| ( { parent } ) => parent === undefined || parent === null |
There was a problem hiding this comment.
In which case will the parent: null be?
There was a problem hiding this comment.
@Mamaduka I checked both HierarchicalTermSelector and PageAttributesParent and parent is undefined if parent does not exist. can we remove parent === null ?
There was a problem hiding this comment.
can we remove parent === null?
If it's never null then I guess we can remove it.
* Use undefined instead of null in `buildTermsTree` * allow null * use undefined * remove null checking
What?
The buildTermsTree function skips the process of converting terms into a tree structure if all terms in the passed array have no parent. Previously, this condition was determined by checking if
parent === null, but it failed to evaluate correctly when parent was undefined. We will modify it to handle both null and undefined correctly.Why?
fix: #65704.
How?
Check
parent === undefiendTesting Instructions
Try #65704.
Testing Instructions for Keyboard
Screenshots or screencast