-
Notifications
You must be signed in to change notification settings - Fork 381
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
Delay showing the unreviewed counts of validated URLs and errors; remove 'At a Glance' widget #5900
Delay showing the unreviewed counts of validated URLs and errors; remove 'At a Glance' widget #5900
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5900 +/- ##
=============================================
- Coverage 75.16% 74.96% -0.20%
- Complexity 5665 5675 +10
=============================================
Files 210 212 +2
Lines 17019 17049 +30
=============================================
- Hits 12792 12781 -11
- Misses 4227 4268 +41
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This is ready for review while I work on resolving these E2E test issues. |
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
41a546e
to
14fd4b2
Compare
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } ); | ||
updateMenuItemCounts( counts ); |
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'm looking at apiFetch
here:
It's throwing an error if the request fails including if a non-successful response code is being sent. Therefore, I think actually updateMenuItemCounts
can be changed to only accept an object
and that this code here can be changed to:
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } ); | |
updateMenuItemCounts( counts ); | |
try { | |
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } ); | |
if ( ! isPlainObject( counts ) ) { | |
throw new Error( 'Object not returned.' ); | |
} | |
updateMenuItemCounts( counts ); | |
} catch ( exception ) { | |
// eslint-disable-next-line no-console | |
console.error( '[AMP Plugin] An error occurred while retrieving unreviewed validation counts.', exception.message ); | |
} |
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.
Ah, right. I've taken a similar approach to what you've suggested in 70941a5.
const errorCountEl = document.getElementById( 'new-error-index-count' ); | ||
const validatedUrlsCountEl = document.getElementById( 'new-validation-url-count' ); | ||
|
||
updateMenuItem( errorCountEl, newErrorCount ); | ||
updateMenuItem( validatedUrlsCountEl, newValidatedUrlCount ); |
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 can be hardened a bit to handle other plugins which may have removed the elements from the admin menu:
const errorCountEl = document.getElementById( 'new-error-index-count' ); | |
const validatedUrlsCountEl = document.getElementById( 'new-validation-url-count' ); | |
updateMenuItem( errorCountEl, newErrorCount ); | |
updateMenuItem( validatedUrlsCountEl, newValidatedUrlCount ); | |
const errorCountEl = document.getElementById( 'new-error-index-count' ); | |
if ( errorCountEl ) { | |
updateMenuItem( errorCountEl, newErrorCount ); | |
} | |
const validatedUrlsCountEl = document.getElementById( 'new-validation-url-count' ); | |
if ( validatedUrlsCountEl ) { | |
updateMenuItem( validatedUrlsCountEl, newValidatedUrlCount ); | |
} |
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.
Updated in 8d90f2d.
count = Math.abs( count ); | ||
|
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'm thinking abs()
may be unnecessary here?
count = Math.abs( count ); |
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.
In retrospect, yea not necessary. Removed in 8d90f2d.
This is a very nice loading indicator: spinners.mov |
} | ||
|
||
domReady( async () => { | ||
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } ); |
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.
Another performance enhancement would be to check whether the #toplevel_page_amp-options
element has the wp-has-current-submenu
class meaning the submenu is expanded. If it does, then go ahead and fetch and display the counts. Otherwise, if it does not have this class (or if it has the wp-not-current-submenu
class), then the menu is not expanded and it is not needed to do the fetch immediately. It can be deferred until the first time that the opensub
class is added to this element, which is what happens when the user hovers over the collapsed menu item or tabs onto it. In this way, the REST API request will only be triggered with every admin page load if the user is looking at one of the AMP screens. If not, then the request will be deferred until the point that the user is actually going to see the menu.
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.
Actually, a nice way to implement both could be to wrap this logic in an IntersectionObserver
callback, specifically targeting the parent element of the menu items. This should defer the loading of the data for 3 scenarios:
- The user is not on an AMP screen so the menu items are not shown until the AMP menu is hovered/focus.
- The browser window is too short to even show the initially-expanded AMP settings menu in the first viewport, meaning the fetch could be delayed until the user scrolls down.
- The user has collapsed the entire admin menu in which case all of the submenus are hidden, even those which have the
wp-has-current-submenu
class.
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.
That worked perfectly (see 70941a5), thanks for the tip! I've set it to fetch the counts whenever the AMP submenu is visible.
We may have another flaky E2E test here due to the async loading of counts; confirming if that's the case... |
2b8d478
to
de08cbd
Compare
Plugin builds for f1005a9 are ready 🛎️!
|
This doesn't seem to be the 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.
This is slick.
Tested that behavior is consistent across Chrome, Firefox, and Safari. |
Summary
Fixes #5772
Checklist