Skip to content
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

Merged
merged 14 commits into from
Feb 23, 2021

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Feb 19, 2021

Summary

Fixes #5772

  • Removes 'At a Glance' widget on dashboard that diplays summary of unreviewed count of validated URLs
  • Delays showing the unreviewed counts of validated URLs and validation errors by asynchronously updating the 'Validated URLs' and 'Error Index' menu items once they are visible

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@codecov
Copy link

codecov bot commented Feb 19, 2021

Codecov Report

Merging #5900 (99165f8) into develop (26034a7) will decrease coverage by 0.19%.
The diff coverage is 57.14%.

Impacted file tree graph

@@              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     
Flag Coverage Δ Complexity Δ
javascript 75.13% <ø> (ø) 0.00 <ø> (ø)
php 74.96% <57.14%> (-0.21%) 0.00 <15.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
includes/utils/class-amp-dom-utils.php 91.56% <ø> (ø) 35.00 <0.00> (ø)
src/AmpWpPlugin.php 100.00% <ø> (ø) 8.00 <0.00> (ø)
src/DevTools/UserAccess.php 100.00% <ø> (ø) 22.00 <0.00> (ø)
src/Admin/ValidationCounts.php 35.00% <35.00%> (ø) 4.00 <4.00> (?)
...s/validation/class-amp-validated-url-post-type.php 64.74% <50.00%> (-1.35%) 442.00 <2.00> (-5.00)
src/Validation/ValidationCountsRestController.php 62.50% <62.50%> (ø) 7.00 <7.00> (?)
includes/sanitizers/class-amp-meta-sanitizer.php 79.79% <75.00%> (-0.21%) 35.00 <0.00> (+3.00) ⬇️
...validation/class-amp-validation-error-taxonomy.php 50.26% <100.00%> (-0.04%) 540.00 <0.00> (-1.00)
src/Validation/SavePostValidationEvent.php 91.66% <100.00%> (-2.46%) 18.00 <1.00> (+1.00) ⬇️
src/Validation/URLValidationCron.php 73.68% <100.00%> (-20.44%) 8.00 <1.00> (+1.00) ⬇️
... and 6 more

@pierlon
Copy link
Contributor Author

pierlon commented Feb 19, 2021

This is ready for review while I work on resolving these E2E test issues.

@pierlon pierlon force-pushed the fix/5772-delayed-validation-error-count-display branch from 41a546e to 14fd4b2 Compare February 20, 2021 02:23
Comment on lines 60 to 61
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } );
updateMenuItemCounts( counts );
Copy link
Member

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:

https://github.com/WordPress/gutenberg/blob/30b2c144afc8586602c419d2faf21b7f9721be7b/packages/api-fetch/src/index.js#L57-L63

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:

Suggested change
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 );
}

Copy link
Contributor Author

@pierlon pierlon Feb 22, 2021

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.

Comment on lines 52 to 56
const errorCountEl = document.getElementById( 'new-error-index-count' );
const validatedUrlsCountEl = document.getElementById( 'new-validation-url-count' );

updateMenuItem( errorCountEl, newErrorCount );
updateMenuItem( validatedUrlsCountEl, newValidatedUrlCount );
Copy link
Member

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:

Suggested change
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 );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 8d90f2d.

Comment on lines 26 to 27
count = Math.abs( count );

Copy link
Member

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?

Suggested change
count = Math.abs( count );

Copy link
Contributor Author

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.

@westonruter
Copy link
Member

This is a very nice loading indicator:

spinners.mov

}

domReady( async () => {
const counts = await apiFetch( { path: '/amp/v1/unreviewed-validation-counts' } );
Copy link
Member

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.

Copy link
Member

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:

  1. The user is not on an AMP screen so the menu items are not shown until the AMP menu is hovered/focus.
  2. 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.
  3. 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.

Copy link
Contributor Author

@pierlon pierlon Feb 22, 2021

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.

@pierlon pierlon self-assigned this Feb 22, 2021
@pierlon pierlon added this to the v2.1 milestone Feb 22, 2021
@pierlon pierlon added the WS:Core Work stream for Plugin core label Feb 22, 2021
@pierlon pierlon marked this pull request as ready for review February 22, 2021 21:19
@pierlon
Copy link
Contributor Author

pierlon commented Feb 22, 2021

We may have another flaky E2E test here due to the async loading of counts; confirming if that's the case...

@pierlon pierlon force-pushed the fix/5772-delayed-validation-error-count-display branch from 2b8d478 to de08cbd Compare February 22, 2021 21:40
@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2021

Plugin builds for f1005a9 are ready 🛎️!

@pierlon
Copy link
Contributor Author

pierlon commented Feb 22, 2021

We may have another flaky E2E test here due to the async loading of counts; confirming if that's the case...

This doesn't seem to be the case.

@pierlon pierlon added WS:Perf Work stream for Metrics, Performance and Optimizer and removed WS:Core Work stream for Plugin core labels Feb 23, 2021
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slick.

@westonruter
Copy link
Member

Tested that behavior is consistent across Chrome, Firefox, and Safari.

@westonruter westonruter merged commit f2af134 into develop Feb 23, 2021
@westonruter westonruter deleted the fix/5772-delayed-validation-error-count-display branch February 23, 2021 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WS:Perf Work stream for Metrics, Performance and Optimizer
Projects
None yet
2 participants