Fix: Tickets menu on Changeset pages redirects to make core/reports/ page instead of opening tickets menu#556
Fix: Tickets menu on Changeset pages redirects to make core/reports/ page instead of opening tickets menu#556hbhalodia wants to merge 3 commits intoWordPress:trunkfrom
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| let match = canonical.match( /\/ticket\/(\d+)$/ ); | ||
| if ( match && match[1] ) { | ||
| ticket = match[1]; | ||
| } |
There was a problem hiding this comment.
I was going to suggest using OR, but.. this is pretty ugly with no benefit:
| let match = canonical.match( /\/ticket\/(\d+)$/ ); | |
| if ( match && match[1] ) { | |
| ticket = match[1]; | |
| } | |
| ( canonical.match( /\/ticket\/(\d+)$/ ) || [,0] )[1] |
Using Nullish operators can also one-line it, which feels much cleaner to me, as it can be easily used on more complicated code without having to nest multiple levels of if checks.
(This ends up as ticket being undefined which is fine for this use-case)
| let match = canonical.match( /\/ticket\/(\d+)$/ ); | |
| if ( match && match[1] ) { | |
| ticket = match[1]; | |
| } | |
| canonical.match( /\/ticket\/(\d+)$/ )?.[0] |
(This is what I'm going to merge, you'll still get props for it)
However, in this case, there's no need to check the match value, as if it matches due to the static regex you can be sure it'll be set.
| let match = canonical.match( /\/ticket\/(\d+)$/ ); | |
| if ( match && match[1] ) { | |
| ticket = match[1]; | |
| } | |
| let match = canonical.match( /\/ticket\/(\d+)$/ ); | |
| if ( match ) { | |
| ticket = match[1]; | |
| } |
There was a problem hiding this comment.
Thanks @dd32 For review.
Initially I had also used canonical.match( /\/ticket\/(\d+)$/ )?.[0] the nullish operator, but I searched the codebase if optional chaining is used or not for codebase to be consistent, which I ends up using the if checks.
I will update PR with what is being suggested.
Also, we are just matching ticket number instead of whole pattern, I guess it should be canonical.match( /\/ticket\/(\d+)$/ )?.[1]?
Thanks,
Issue
Meta ticket -- https://meta.trac.wordpress.org/ticket/8183