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

Do async site scan after theme activation #6859

Merged
merged 11 commits into from
Mar 9, 2022

Conversation

delawski
Copy link
Collaborator

@delawski delawski commented Jan 28, 2022

Summary

Fixes #6814
Fixes #6958

This PR reuses the async site scan notice logic introduced in #6685 so that a site scan is done after theme activation, too.

Right now on both plugins.php and themes.php screens the scan results will include plugin and theme issues.

Screenshot 2022-03-05 at 13 45 04

This PR also updates the Site Scan results for themes. Previously, a parent theme causing AMP incompatibilities was greyed-out while it should not (#6958):

Before After
Screenshot 2022-03-05 at 13 12 07 Screenshot 2022-03-05 at 18 56 27

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).

@delawski delawski added Enhancement New feature or improvement of an existing one Site Scanning labels Jan 28, 2022
@delawski delawski added this to the v2.3 milestone Jan 28, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2022

Plugin builds for f7f2121 are ready 🛎️!

@delawski delawski mentioned this pull request Jan 28, 2022
2 tasks
@delawski
Copy link
Collaborator Author

delawski commented Feb 2, 2022

Please note that the site scan notification may need some design review and improvements since right now we show both plugin and theme issues at the same time:

Screenshot 2022-01-27 at 21 23 00

@maitreyie-chavan maitreyie-chavan modified the milestones: v2.3, v2.2.2 Feb 9, 2022
Copy link
Collaborator

@dhaval-parekh dhaval-parekh left a comment

Choose a reason for hiding this comment

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

Changes looks good to me.

This utilizes the async site scan notice that is shown after plugin activation. Right now, both on `plugins.php` and on `themes.php` screens, the scan results will include plugin and theme issues.
@delawski delawski force-pushed the add/6814-theme-activation-site-scan branch from 8696ef2 to 9566a93 Compare February 21, 2022 16:44
@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #6859 (346a83d) into develop (0ba4427) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 346a83d differs from pull request most recent head 3531d9e. Consider uploading reports for the commit 3531d9e to get more accurate results

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #6859      +/-   ##
=============================================
+ Coverage      77.80%   77.81%   +0.01%     
- Complexity      6767     6771       +4     
=============================================
  Files            267      267              
  Lines          21548    21560      +12     
=============================================
+ Hits           16765    16777      +12     
  Misses          4783     4783              
Flag Coverage Δ
javascript 64.04% <ø> (ø)
php 78.57% <100.00%> (+0.01%) ⬆️
unit 78.57% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
src/AmpWpPlugin.php 100.00% <ø> (ø)
src/Admin/AfterActivationSiteScan.php 100.00% <100.00%> (ø)

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.

Sorry for the delay in reviewing.

Comment on lines +44 to +52
/**
* HTML ID for the app root sibling element.
*
* Since there is no action for adding notice on `themes.php` screen, we need to inject React root element with JS.
* It is an ID of a success notice saying "New theme activated. Visit site" on the `themes.php` screen.
*
* @var string
*/
const APP_ROOT_SIBLING_ID = 'message2';
Copy link
Member

Choose a reason for hiding this comment

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

Classic 😄


root = document.createElement( 'div' );
root.setAttribute( 'id', APP_ROOT_ID );
rootSibling.after( root );
Copy link
Member

Choose a reason for hiding this comment

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

Nice. The after method is available for every browser except IE11. I need to start using it!

Comment on lines 37 to 57
<p>
{ createInterpolateElement(
sprintf(
// translators: %s stands for a theme name.
__( 'AMP compatibility issues discovered with the <b>%s</b> theme.', 'amp' ),
themeName,
),
{
b: <strong />,
},
) }
</p>
<div className="amp-site-scan-notice__cta">
<a
href={ AMP_COMPATIBLE_THEMES_URL }
className="button"
{ ...isExternalUrl( AMP_COMPATIBLE_THEMES_URL ) ? { target: '_blank', rel: 'noopener noreferrer' } : {} }
>
{ __( 'View AMP-Compatible Themes', 'amp' ) }
</a>
</div>
Copy link
Member

Choose a reason for hiding this comment

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

Can this add the list of URLs in the same way as PluginsWithAmpIncompatibility does?

Comment on lines 37 to 48
<p>
{ createInterpolateElement(
sprintf(
// translators: %s stands for a theme name.
__( 'AMP compatibility issues discovered with the <b>%s</b> theme.', 'amp' ),
themeName,
),
{
b: <strong />,
},
) }
</p>
Copy link
Member

Choose a reason for hiding this comment

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

There may actually be two themes that have compatibility issues, the parent theme and the child theme. Therefore I suggest that the structure here follow closely what you did in PluginsWithAmpIncompatibility and have the list of themes along with the URLs that they have issues detected on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely. Check out #6859 (comment) below.

return null;
}

const themeMeta = themes.find( ( theme ) => theme.stylesheet === themeWithAmpIncompatibility.slug );
Copy link
Member

Choose a reason for hiding this comment

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

As noted below, this should also account for there being a child theme active.

src/Admin/AfterActivationSiteScan.php Outdated Show resolved Hide resolved
@@ -197,6 +235,11 @@ protected function add_preload_rest_paths() {
[ 'author', 'name', 'plugin', 'status', 'version' ],
'/wp/v2/plugins'
),
add_query_arg(
'_fields',
[ 'author', 'name', 'status', 'stylesheet', 'version' ],
Copy link
Member

Choose a reason for hiding this comment

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

Per above, this will also need to include template for the sake of child themes:

Suggested change
[ 'author', 'name', 'status', 'stylesheet', 'version' ],
[ 'author', 'name', 'status', 'stylesheet', 'template', 'version' ],

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've just committed that but I'm now wondering if we actually need to know the parent theme (i.e. the template)? We don't show an information like this anywhere in the UI so I guess we could just skip that.

Copy link
Member

Choose a reason for hiding this comment

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

I think you'd need it here potentially:

const themeMeta = themes.find( ( theme ) => theme.stylesheet === themeWithAmpIncompatibility.slug );
const themeName = themeMeta?.name?.rendered ?? themeMeta?.name;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are now using template, too. As noted in #6859 (comment), the parent/child themes were not handled well in the Site Scan results. This should be fixed with 11da989.

@delawski
Copy link
Collaborator Author

delawski commented Mar 5, 2022

@westonruter While reviewing your feedback I realized that the Site Scan is not handling correctly cases when child and parent themes cause AMP incompatibilities. The parent theme is greyed-out as if it was inactive (because its status literally is inactive):

Screenshot 2022-03-05 at 13 12 07

I've issued a new ticket #6958 mainly for tracking/QA reasons because this issue should be fixed with 11da989:

Screenshot 2022-03-05 at 18 56 27

It also takes care of the post-activation notice:

Screenshot 2022-03-05 at 13 45 04

@delawski delawski requested a review from westonruter March 5, 2022 18:04
…theme-activation-site-scan

* 'develop' of github.com:ampproject/amp-wp: (158 commits)
  Include SCSS files in the lint-staged config for stylelint
  Fix stylelint issue
  Rename 'allowed' to 'associated'
  Use named functions
  Add label for why the validation data is being shown
  Remove wrapping of site-scan-results__source-detail
  Bump lint-staged from 12.3.4 to 12.3.5
  Update perimssions for gutenberg-packages-update workflow
  Add approve step for auto-merge workflow
  Add notice step
  Move conditional from matrix job to its steps
  Only run PHP feature tests when php files have changed
  Only run phpunit tests if a PHP file has changed
  Update auto-merge workflow based on latest GH docs
  Bump node-fetch from 2.6.5 to 2.6.7
  Bump postcss from 8.4.7 to 8.4.8
  Bump eslint-plugin-jsdoc from 37.9.6 to 37.9.7
  Improve test coverage
  Prevent site scan progress bar overflow bug in Safari
  Hide default details summary marker on Safari
  ...
@westonruter
Copy link
Member

I've issued a new ticket #6958 mainly for tracking/QA reasons because this issue should be fixed with 11da989:

Indeed!

Before After
Screen Shot 2022-03-08 at 15 39 19 Screen Shot 2022-03-08 at 15 40 26

@westonruter
Copy link
Member

Looks like tests are failing after I merged #6933. This error is also happening in develop so it's not unique to this branch.

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.

Good work

];

// Display the theme information at the top when on the `themes.php` screen.
if ( document.location.href.includes( 'themes.php' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

This works, although it may be a bit more elegant to pass this information via the amp-site-scan-notice external dependency.

@westonruter westonruter merged commit 10398bb into develop Mar 9, 2022
@westonruter westonruter deleted the add/6814-theme-activation-site-scan branch March 9, 2022 00:25
westonruter added a commit that referenced this pull request Mar 9, 2022
Co-authored-by: Piotr Delawski <piotr.delawski@gmail.com>
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. Enhancement New feature or improvement of an existing one Site Scanning
Projects
None yet
4 participants