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

My Jetpack: Allow the "plugin(s) needs installed" notice to be closed with persistence. #41617

Merged
merged 4 commits into from
Feb 10, 2025

Conversation

elliottprogrammer
Copy link
Contributor

This PR allows the "Needs plugin(s) installed" notice to be manually closed (by clicking the close(X) icon), and remain closed for a set period (14 days in this case).

Closes https://github.com/Automattic/jetpack-roadmap/issues/2294

Proposed changes:

  • Add prop to show the close icon on the Notice.
  • Add onCloseClick event handler. Set 14 day cookie on close click & remove Notice.
  • Add logic to only show Notice if there is no cookie set.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Part of overall task: https://github.com/Automattic/jetpack-roadmap/issues/2050

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Run this PR branch locally or via a Jurassic Ninja site using the Jetpack Beta plugin (run the branch on the VideoPress plugin suggested).
  • Connect Jetpack (site and user).
  • If running Jurassic Ninja, deactivate and uninstall Jetpack. (while this PR branch is running on VideoPress).
  • If running locally, deactivate all Jetpack plugins except VideoPress. Rename the plugins/jetpack directory to plugins/jetpack-disabled
  • Purchase a Backup plan.
  • You should now be able to see the "Needs Plugin installed" Notice.
  • Click the close(X) icon in the top right corner.
  • Verify that the Notice has closed/disappeared.
  • Refresh the My Jetpack page. Verify the Notice does not show again. It remains closed.
  • Set you computer date greater than 14 days in the future.
  • reload the My Jetpack page. Verify the Notice appears again.

@elliottprogrammer elliottprogrammer self-assigned this Feb 6, 2025
Copy link
Contributor

github-actions bot commented Feb 6, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the add/mj-notice-close-plugins-needs-installed branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/mj-notice-close-plugins-needs-installed
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/mj-notice-close-plugins-needs-installed
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Feb 6, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 6, 2025
@elliottprogrammer elliottprogrammer requested a review from a team February 6, 2025 22:07
Copy link
Contributor

github-actions bot commented Feb 6, 2025

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/my-jetpack/_inc/hooks/use-notification-watcher/use-paid-plan-needs-plugin-install-activation-notice.tsx 0/103 (0.00%) 0.00% 6 💔
projects/packages/my-jetpack/src/class-initializer.php 52/499 (10.42%) -0.02% 1 💔

Full summary · PHP report · JS report

Copy link
Contributor

@CodeyGuyDylan CodeyGuyDylan left a comment

Choose a reason for hiding this comment

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

Very minor nitpick, but the positioning of the X seems slightly off here

image

I think it has to do with the padding overlapping the X itself

But honestly it looks fine to the naked eye so it's your choice whether you want to change this or not 😅

This seems to work well and I love that you're adding it! I think my comment about the early return should be done, but it's a pretty small change so I'll go ahead and approve so you can merge after you've done that

@@ -1157,7 +1157,9 @@ public static function alert_if_paid_plan_requires_plugin_install_or_activation(
}

foreach ( $plugins_needing_installed_activated as $plan_slug => $plugins_requirements ) {
$red_bubble_slugs[ "$plan_slug--plugins_needing_installed_activated" ] = $plugins_requirements;
if ( empty( $_COOKIE[ "$plan_slug--plugins_needing_installed_dismissed" ] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, I think we could move this check to the top to avoid having to do all the above stuff in this function, just to optimize performance

Something like

if ( ! empty( $_COOKIE[ "$plan_slug--plugins_needing_installed_dismissed" ] ) ) {
   $red_bubble_slugs;
}

There's other checks like it above so I don't think it would be out of place, and it doesn't rely on any data (other than the cookie) so it can be first

Copy link
Contributor Author

@elliottprogrammer elliottprogrammer Feb 10, 2025

Choose a reason for hiding this comment

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

There's other checks like it above so I don't think it would be out of place, and it doesn't rely on any data (other than the cookie) so it can be first

Actually no I don't think I can move this check up to the top @CodeyGuyDylan ... because it does rely on the $plan_slug which is only available within the foreach loop. So I think it needs to remain where it is.. Unless I'm missing something? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I am very sorry I somehow missed that part! However, I still think there could potentially be a better way to do this. This works, however, so I will approve it for now and leave it up to you (I'll approve for real this time 😅 )

The way it works now, a new cookie will be added for each notice that is dismissed per product with the structure of this

Name: {slug}--plugins_needing_installed_dismissed Value: 1

I think for cleaning up potential cookies and so that we can return earlier, it might be better to have a single cookie that handles all of these in a structure like this:

Name: plugins_needing_installed_dismissed Value: {slugs in comma separated string}

This would avoid having to create multiple cookies if they dismiss more than one, and then we could have a check like

$cookie_value = $_COOKIE[ "plugins_needing_installed_dismissed"]
if ( in_array( explode( ',', $cookie_value ), $plugins_needing_installed_activated ) ) {
   return $red_bubble_slugs;
}

However, I fully acknowledge that the amount of users dismissing multiple of these banners and the performance increase of this rework is minimal, so I won't push to hard to update it 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your additional feedback Dylan!
However, I went ahead and shipped it as-is..
Firstly, just for the simplicity of knowing that for each notice that is displayed to the user, if they click to dismiss it, there is a specific cookie for that particular notice that controls the dismissal of the notice and when the dismissal expires.
Secondly, I think the alternative approach you've described above will have some unwanted behavior, because the approach doesn't take into account the cookies expiration date. (i.e.- Currently the expiration is set to 14 days, meaning that if the user dismisses the notice, but then after 14 days if the user hasn't installed the required plugins needed for the particular paid plan that the notice is displaying for, then the notice will display to the user again). The alternative approach (using a shared cookie) means that the cookie expiration date will no longer be tied specifically to each notice individually.., If that makes sense.

@elliottprogrammer
Copy link
Contributor Author

elliottprogrammer commented Feb 10, 2025

Hey @CodeyGuyDylan, thanks very much for reviewing!
I fixed the alignment/positioning of the Close(X) button in the Notice component. See screenshot:
Screenshot 2025-02-10 at 2 18 04 PM
As for moving the cookie check to the top, I can't do that because it needs to stay within the foreach loop in order to have access to the $plan_slug variable. I also responded to this in the inline comments.

so I'll go ahead and approve so you can merge after you've done that

Changes were requested initially, so this PR still needs re-reviewed/approval. 🙏

@CodeyGuyDylan
Copy link
Contributor

As for moving the cookie check to the top, I can't do that because it needs to stay within the foreach loop in order to have access to the $plan_slug variable. I also responded to this in the inline comments.

🤦🏻 I apologize for that oversight in my review, not sure how I missed that. Thank you for pointing that out to me!

@@ -1157,7 +1157,9 @@ public static function alert_if_paid_plan_requires_plugin_install_or_activation(
}

foreach ( $plugins_needing_installed_activated as $plan_slug => $plugins_requirements ) {
$red_bubble_slugs[ "$plan_slug--plugins_needing_installed_activated" ] = $plugins_requirements;
if ( empty( $_COOKIE[ "$plan_slug--plugins_needing_installed_dismissed" ] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am very sorry I somehow missed that part! However, I still think there could potentially be a better way to do this. This works, however, so I will approve it for now and leave it up to you (I'll approve for real this time 😅 )

The way it works now, a new cookie will be added for each notice that is dismissed per product with the structure of this

Name: {slug}--plugins_needing_installed_dismissed Value: 1

I think for cleaning up potential cookies and so that we can return earlier, it might be better to have a single cookie that handles all of these in a structure like this:

Name: plugins_needing_installed_dismissed Value: {slugs in comma separated string}

This would avoid having to create multiple cookies if they dismiss more than one, and then we could have a check like

$cookie_value = $_COOKIE[ "plugins_needing_installed_dismissed"]
if ( in_array( explode( ',', $cookie_value ), $plugins_needing_installed_activated ) ) {
   return $red_bubble_slugs;
}

However, I fully acknowledge that the amount of users dismissing multiple of these banners and the performance increase of this rework is minimal, so I won't push to hard to update it 😄

@elliottprogrammer elliottprogrammer merged commit 98e9a85 into trunk Feb 10, 2025
80 checks passed
@elliottprogrammer elliottprogrammer deleted the add/mj-notice-close-plugins-needs-installed branch February 10, 2025 20:06
@github-actions github-actions bot removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants