google / site-kit-wp

Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
https://sitekit.withgoogle.com
Apache License 2.0
1.23k stars 286 forks source link

Implement automatic refresh for RRM module setup flow #8839

Closed nfmohit closed 1 month ago

nfmohit commented 4 months ago

Feature Description

The Reader Revenue Manager module setup should support automatic refresh behaviour similar to the AdSense module's setup flow: If you navigate away for a certain amount of time and then return to the tab, it should automatically re-run the relevant API requests, to see if maybe something on the SwG API side has changed. This is crucial since all write actions happen within the Publisher Center UI and are therefore unknown to Site Kit.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation Brief

Test Coverage

Add tests for resetPublications action.

QA Brief

Scenario i. Publication ID is not set.

  1. Activate the module. This will redirect to the setup screen.

  2. There should be a progress bar which shows the publications are loading.

  3. Once publications dropdown is visible, navigate away from the current tab in browser. You can open a different tab and stay there for 15+ seconds. Come back to the setup tab again and you should see that publications are loading again (a progress bar to load publications).

Scenario ii. Populating publications when synced.

  1. Activate the module. This will redirect to the setup screen. Wait till publication dropdown appears.

  2. Run the following command in browser.

googlesitekit.data.dispatch( 'modules/reader-revenue-manager' ).receiveGetPublications([]);

This will clear all publications from dropdown.

  1. Once publications dropdown is visible, navigate away from the current tab in browser. You can open a different tab and stay there for 15+ seconds. Come back to the setup tab again and you should see that publications are loading again (a progress bar to load publications). Once publication dropdown appears, you must see all publications available again.

Scenario iii. Publication ID is set, publications should not get loaded again.

  1. Activate the module. This will redirect to the setup screen. Wait till publication dropdown appears.

  2. Run the following command in browser.

  const settings = {
      publicationID: "CAow6J6vDA",
      publicationOnboardingState: "ONBOARDING_ACTION_REQUIRED",
      publicationOnboardingStateLastSyncedAtMs: 0
    };

    googlesitekit.data.dispatch('modules/reader-revenue-manager').setSettings( settings );
    googlesitekit.data.dispatch('modules/reader-revenue-manager').saveSettings();
  1. Navigate away from the current tab in browser. You can open a different tab and stay there for 15+ seconds. Come back to the setup tab again and you should see that publications are NOT loading again (a progress bar to load publications).

Changelog entry

nfmohit commented 3 months ago

Nice work, @ankitrox ! IB LGTM 👍 ✅

kelvinballoo commented 2 months ago

QA Update ⚠️

One flag is that whenever the publications have already been retrieved and I click on the dropdown, there is a console error. Refer to the video attached. ⚠️ However, it's worth noting that after I did Scenario 3, I could not replicate this issue anymore.

Console error: Screenshot 2024-08-05 at 17 35 15 https://github.com/user-attachments/assets/52bd7082-4a9b-4e9a-ada6-19784298df77

Other items successfully verified are as follows: ✅

kelvinballoo commented 2 months ago

QA Update ✅

After a round of review, this aria hidden console error actually happens on other SK module dropdowns as well. Hence, this will be tackled in a separate issue, logged here: https://github.com/google/site-kit-wp/issues/9142

This ticket is good to be moved to approval.

The 3 scenarios were verified good: ✅