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

Improve post Site Scan action items #6698

Merged
merged 16 commits into from
Nov 23, 2021
Merged

Conversation

delawski
Copy link
Collaborator

@delawski delawski commented Nov 8, 2021

Summary

Fixes #6689

This PR improves the action items for when there are theme and/or plugin incompatibilities.

Here are the todo items from the original issue:

  • The action item to review and suppress plugins should rather only appear if there are plugins with incompatibilities, and this action item should appear inside the plugins box.
  • In the incompatible themes box, this is probably where the recommendation to change to Reader mode should be. Or else to consider switching to an alternative theme (see below).
  • In the boxes for themes and plugins, there should be links to the AMP Compatible tabs for the the Theme Install and Plugin Install screens, if theme/plugin installation is available (i.e. if filesystem is not read only). If the theme/plugin installation is not available, there should rather be ExternalLinks going to the theme/plugin ecosystem pages on amp-wp.org.
  • When a site scan completes, the suppressed_plugins option should be re-fetched so that the suppressed table is updated with which plugins have validation errors.
  • Discontinue doing synchronous re-validation of validated URLs when updating suppressed plugins. Instead of doing this, initiating a re-scan should be done.

Here's the updated Site Scan panel on the AMP Settings screen where the plugin/theme action items are located inside the respective sub-panels:

Screenshot 2021-11-08 at 19 16 02

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
Copy link
Collaborator Author

delawski commented Nov 8, 2021

@westonruter The only item left to do is adding links to the AMP Compatible tabs for themes and plugins. I was wondering about the filesystem check you mentioned in the original issue. I think we need to not only check the filesystem but also user capabilities. Do you think we could reuse some of the logic from can_install_theme()? I guess we could do something similar for plugins and then pass two flags to the frontend so that appropriate links are rendered on the Settings page.

@delawski delawski marked this pull request as ready for review November 10, 2021 13:49
@codecov
Copy link

codecov bot commented Nov 10, 2021

Codecov Report

Merging #6698 (253e5fd) into develop (92453d4) will decrease coverage by 0.06%.
The diff coverage is 20.68%.

❗ Current head 253e5fd differs from pull request most recent head 87e609c. Consider uploading reports for the commit 87e609c to get more accurate results
Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #6698      +/-   ##
=============================================
- Coverage      76.67%   76.61%   -0.07%     
- Complexity      6543     6545       +2     
=============================================
  Files            263      265       +2     
  Lines          20956    20989      +33     
=============================================
+ Hits           16069    16080      +11     
- Misses          4887     4909      +22     
Flag Coverage Δ
javascript 58.19% <14.81%> (-0.75%) ⬇️
php 77.76% <100.00%> (+<0.01%) ⬆️
unit 77.76% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...s/src/components/options-context-provider/index.js 2.22% <0.00%> (-0.56%) ⬇️
...src/components/site-scan-context-provider/index.js 35.11% <37.50%> (+0.43%) ⬆️
assets/src/common/helpers/is-external-url.js 100.00% <100.00%> (ø)
src/Admin/OptionsMenu.php 94.44% <100.00%> (+0.08%) ⬆️
...onents/site-scan-results/site-scan-sources-list.js 100.00% <0.00%> (ø)

@delawski delawski marked this pull request as draft November 10, 2021 13:52
@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2021

Plugin builds for 7114e14 are ready 🛎️!

@westonruter
Copy link
Member

The only item left to do is adding links to the AMP Compatible tabs for themes and plugins. I was wondering about the filesystem check you mentioned in the original issue. I think we need to not only check the filesystem but also user capabilities. Do you think we could reuse some of the logic from can_install_theme()? I guess we could do something similar for plugins and then pass two flags to the frontend so that appropriate links are rendered on the Settings page.

@delawski That's right. If the filesystem is not writable, the install_themes and install_plugins capabilities will return false due to logic in map_meta_cap(). But then going ahead with the additional checks in \AmpProject\AmpWP\Admin\ReaderThemes::can_install_theme() would make it even more robust, although I think it may be overkill since we don't actually need to perform the installation ourselves. I think that was done specifically for the case where a site may require SFTP credentials to be provided to do the update. In contrast, all we need to do is provide a link to the theme/plugin install screens. So for that, all we need to do is check if current_user_can('install_themes') and current_user_can('install_plugins'). The logic would be as follows:

$theme_link  = current_user_can( 'install_themes' ) ? admin_url( '/theme-install.php?browse=amp-compatible' ) : 'https://amp-wp.org/ecosystem/themes/';
$plugin_link = current_user_can( 'install_plugins' ) ? admin_url( '/plugin-install.php?tab=amp-compatible' ) : 'https://amp-wp.org/ecosystem/plugins/';

@westonruter
Copy link
Member

And when the capability checks return false, we should have the external link icon to go with the links.

@delawski delawski force-pushed the update/site-scan-results-panel branch from d9759f3 to 074f845 Compare November 15, 2021 14:20
@delawski delawski marked this pull request as ready for review November 15, 2021 17:51
@delawski
Copy link
Collaborator Author

@westonruter Thank you for the suggestions. I've used the proposed logic in fd06053:

Screenshot 2021-11-15 at 17 46 52

Also, I found a bug in the Site Scan in the Wizard. The progress bar has been shown too early, when the state was not stable yet causing the progress bar to start at 100%. This has been fixed in 3621298.

Lastly, I've included a Site Scan reducer one-line fix (253e5fd) to the issue you've revealed in #6705 (comment).

@delawski
Copy link
Collaborator Author

I've just noticed a new action item on the original issue:

Discontinue doing synchronous re-validation of validated URLs when updating suppressed plugins. Instead of doing this, initiating a re-scan should be done.

I'll take care of that next.

@delawski
Copy link
Collaborator Author

I've just noticed a new action item on the original issue:

Discontinue doing synchronous re-validation of validated URLs when updating suppressed plugins. Instead of doing this, initiating a re-scan should be done.

I'll take care of that next.

This has been addressed in 87e609c:

Screen.Recording.2021-11-17.at.02.20.16.PM.mp4

@delawski delawski added this to the v2.2 milestone Nov 17, 2021
@delawski delawski added Enhancement New feature or improvement of an existing one Site Scanning Validation labels Nov 17, 2021
@westonruter
Copy link
Member

Regarding this phpunit failure:

image

This seems to be an issue in PHP 8 and/or WP 5.9-alpha, so I'll investigate. It's unrelated to this PR anyway.

@westonruter
Copy link
Member

westonruter commented Nov 17, 2021

This seems to be an issue in PHP 8 and/or WP 5.9-alpha, so I'll investigate. It's unrelated to this PR anyway.

It's this change in WordPress core: WordPress/wordpress-develop@5d5c9bf

Easy to fix. See #6727.

…te-scan-results-panel

* 'develop' of github.com:ampproject/amp-wp:
  Fix test_amp_remove_paired_endpoint in WP 5.9 by removing empty query string
@westonruter
Copy link
Member

I just realized there is another factor for the recommendation matrix. Namely, if the user has a plugin suppressed then we should never recommend Standard mode, which we are doing now:

image

If a plugin is being suppressed, then this normally means that you're in a paired AMP mode and you don't want the plugin running on the AMP version but you do want it running on the non-AMP version. If you are in Standard mode, then essentially the user should rather just have deactivated the plugin entirely as that is how it would be behaving.

So this would look something like this:

diff --git a/assets/src/components/use-template-mode-recommendation/index.js b/assets/src/components/use-template-mode-recommendation/index.js
index d6b9dee9d..dfea95155 100644
--- a/assets/src/components/use-template-mode-recommendation/index.js
+++ b/assets/src/components/use-template-mode-recommendation/index.js
@@ -60,12 +60,14 @@ export function useTemplateModeRecommendation() {
  * @param {boolean} args.hasFreshSiteScanResults Whether fresh site scan results are available.
  * @param {boolean} args.hasThemeIssues          Whether the site scan found themes with AMP incompatibility.
  * @param {boolean} args.userIsTechnical         Whether the user answered yes to the technical question.
+ * @param {boolean} args.hasSuppressedPlugins
  */
 export function getTemplateModeRecommendation( {
 	hasPluginIssues,
 	hasFreshSiteScanResults,
 	hasThemeIssues,
 	userIsTechnical,
+	hasSuppressedPlugins,
 } ) {
 	/* eslint-disable @wordpress/no-unused-vars-before-return */
 	const mobileRedirectionNote = __( 'If automatic mobile redirection is enabled, the AMP version of the content will be served on mobile devices. If AMP-to-AMP linking is enabled, once users are on an AMP page, they will continue navigating your AMP content.', 'amp' );
@@ -298,17 +300,18 @@ export function getTemplateModeRecommendation( {
 					],
 				},
 				[ TRANSITIONAL ]: {
-					recommendationLevel: NOT_RECOMMENDED,
+					recommendationLevel: hasSuppressedPlugins ? RECOMMENDED : NOT_RECOMMENDED,
 					details: [
 						transitionalModeDescription,
 						notRecommendedDueToCompleteCompatibility,
 					],
 				},
 				[ STANDARD ]: {
-					recommendationLevel: RECOMMENDED,
+					recommendationLevel: hasSuppressedPlugins ? NOT_RECOMMENDED : RECOMMENDED,
 					details: [
 						standardModeDescription,
 						__( 'Recommended as you have an AMP-compatible theme and no issues were detected with any of the plugins on your site.', 'amp' ),
+						hasSuppressedPlugins ? __( 'Not recommended because you have suppressed plugins.', 'amp' ) : null,
 					],
 				},
 			};
@@ -326,7 +329,7 @@ export function getTemplateModeRecommendation( {
 					],
 				},
 				[ TRANSITIONAL ]: {
-					recommendationLevel: NEUTRAL,
+					recommendationLevel: hasSuppressedPlugins ? RECOMMENDED : NEUTRAL,
 					details: [
 						transitionalModeDescription,
 						__( 'Recommended if you can’t commit to choosing plugins that are AMP compatible when extending your site. This mode will make it easy to keep AMP content even if non-AMP-compatible plugins are used later on.', 'amp' ),
@@ -337,6 +340,7 @@ export function getTemplateModeRecommendation( {
 					details: [
 						standardModeDescription,
 						__( 'Recommended if you can commit to always choosing plugins that are AMP compatible when extending your site.', 'amp' ),
+						hasSuppressedPlugins ? __( 'Not recommended because you have suppressed plugins.', 'amp' ) : null,
 					],
 				},
 			};


/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';
import { createInterpolateElement, useMemo } from '@wordpress/element';
Copy link
Member

Choose a reason for hiding this comment

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

Fancy.

{ showHelpText && (
<p>
{ createInterpolateElement(
__( 'Because of plugin issues we’ve uncovered, you may want to <a>review and suppress plugins</a>.', 'amp' ),
Copy link
Member

Choose a reason for hiding this comment

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

Aside: With createInterpolateElement, what happens when you have more than one <a> in your string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can use whatever tag name you wish, e.g. you could do something like this:

createInterpolateElement( 'Visit <ArchiveLink>archive</ArchiveLink> or return to <HomeLink>homepage</HomeLink>', {
	ArchiveLink: <a href="/archive" />,
	HomeLink: <a href="/" />,
} );

@delawski
Copy link
Collaborator Author

delawski commented Nov 18, 2021

I just realized there is another factor for the recommendation matrix. Namely, if the user has a plugin suppressed then we should never recommend Standard mode, which we are doing now

Thanks for providing that diff. I've added it along with a logic for determining the hasSuppressedPlugins in 0de088d.

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.

🥇

Comment on lines +44 to +46
// Plugins are considered suppressed only if they are active (included in the `suppressible_plugins` object).
const hasSuppressedPlugins = Object.entries( currentOptions?.suppressed_plugins || {} )
.some( ( [ slug, suppressed ] ) => suppressed && Boolean( currentOptions.suppressible_plugins?.[ slug ] ) );
Copy link
Member

Choose a reason for hiding this comment

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

Nicely done

Comment on lines +76 to +80
const fetchedPluginSuppression = await apiFetch( {
path: addQueryArgs( optionsRestPath, {
_fields: [ 'suppressed_plugins', 'suppressible_plugins' ],
} ),
} );
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Comment on lines +86 to +89
setOriginalOptions( {
...originalOptions,
...fetchedPluginSuppression,
} );
Copy link
Member

Choose a reason for hiding this comment

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

This is great. I was thinking that this could have the effect of overriding a user's unsaved changes to plugin suppression, but this won't be the case the original options are updated, not the modified otpions.

@westonruter westonruter merged commit f484b76 into develop Nov 23, 2021
@westonruter westonruter deleted the update/site-scan-results-panel branch November 23, 2021 01:48
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Dec 15, 2021
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 Validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve action items for when there are theme/plugin incompatibilities
3 participants