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 publication onboarding state synchronization. #9469

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Oct 7, 2024

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented Oct 7, 2024

Build files for d17f5bd are ready:

Copy link

github-actions bot commented Oct 7, 2024

Size Change: +178 B (+0.01%)

Total Size: 1.82 MB

Filename Size Change
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 81.4 kB +138 B (+0.17%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 156 kB +144 B (+0.09%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 40.6 kB -104 B (-0.26%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 58.5 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.2 kB
./dist/assets/js/32-********************.js 2.76 kB
./dist/assets/js/33-********************.js 2.25 kB
./dist/assets/js/34-********************.js 3.64 kB
./dist/assets/js/35-********************.js 935 B
./dist/assets/js/36-********************.js 893 B
./dist/assets/js/37-********************.js 1.61 kB
./dist/assets/js/38-********************.js 1.57 kB
./dist/assets/js/39-********************.js 1.61 kB
./dist/assets/js/40-********************.js 1.59 kB
./dist/assets/js/41-********************.js 3.11 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 901 B
./dist/assets/js/googlesitekit-activation-********************.js 23.9 kB
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 54.7 kB
./dist/assets/js/googlesitekit-adminbar-********************.js 34.5 kB
./dist/assets/js/googlesitekit-api-********************.js 10.1 kB
./dist/assets/js/googlesitekit-components-gm2-********************.js 6.04 kB
./dist/assets/js/googlesitekit-components-gm3-********************.js 10.1 kB
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB
./dist/assets/js/googlesitekit-data-********************.js 2.37 kB
./dist/assets/js/googlesitekit-datastore-forms-********************.js 8.95 kB
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.5 kB
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10 kB
./dist/assets/js/googlesitekit-datastore-user-********************.js 26.8 kB
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 624 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 712 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 657 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B
./dist/assets/js/googlesitekit-i18n-********************.js 3.93 kB
./dist/assets/js/googlesitekit-modules-ads-********************.js 33.5 kB
./dist/assets/js/googlesitekit-modules-adsense-********************.js 111 kB
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 178 kB
./dist/assets/js/googlesitekit-modules-********************.js 22.3 kB
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 22.7 kB
./dist/assets/js/googlesitekit-modules-search-console-********************.js 59.6 kB
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 10.9 kB
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32.2 kB
./dist/assets/js/googlesitekit-notifications-********************.js 22.6 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B
./dist/assets/js/googlesitekit-settings-********************.js 118 kB
./dist/assets/js/googlesitekit-splash-********************.js 68.8 kB
./dist/assets/js/googlesitekit-user-input-********************.js 43.6 kB
./dist/assets/js/googlesitekit-vendor-********************.js 321 kB
./dist/assets/js/googlesitekit-widgets-********************.js 90 kB
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 62.4 kB
./dist/assets/js/runtime-********************.js 1.38 kB

compressed-size-action

Copy link
Collaborator

@nfmohit nfmohit left a comment

Choose a reason for hiding this comment

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

Brilliant work on this, thank you @ankitrox !

  1. I have left a number of comments in the PR. Could you please go through my comments and update the PR accordingly?
  2. The major issue that I've noticed is that the "publication approved overlay notification" does not appear when the cron event runs and the publication onboarding state changes to complete. Could you investigate?
  3. I see that the publicationOnboardingStateLastSyncedAtMs setting is still used across the codebase, mostly in tests and stories. Can they be removed?

Please let me know if you have any questions. Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should no longer set publicationOnboardingStateLastSyncedAtMs in the selectPublication action.

Comment on lines 68 to 98
/**
* User options instance.
*
* @since n.e.x.t
*
* @var User_Options
*/
protected $user_options;

/**
* Constructor.
*
* @since n.e.x.t
*
* @param Context $context Plugin context.
* @param Options $options Optional. Option API instance. Default is a new instance.
* @param User_Options $user_options Optional. User Option API instance. Default is a new instance.
* @param Authentication $authentication Optional. Authentication instance. Default is a new instance.
* @param Assets $assets Optional. Assets API instance. Default is a new instance.
*/
public function __construct(
Context $context,
Options $options = null,
User_Options $user_options = null,
Authentication $authentication = null,
Assets $assets = null
) {
parent::__construct( $context, $options, $user_options, $authentication, $assets );
$this->user_options = $user_options;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not necessary to re-declare the $user_options class property because the parent class, Module, already declares the $user_options class.

Please take a look at other module classes, such as Analytics_4, on how they use the $user_options property.

Suggested change
/**
* User options instance.
*
* @since n.e.x.t
*
* @var User_Options
*/
protected $user_options;
/**
* Constructor.
*
* @since n.e.x.t
*
* @param Context $context Plugin context.
* @param Options $options Optional. Option API instance. Default is a new instance.
* @param User_Options $user_options Optional. User Option API instance. Default is a new instance.
* @param Authentication $authentication Optional. Authentication instance. Default is a new instance.
* @param Assets $assets Optional. Assets API instance. Default is a new instance.
*/
public function __construct(
Context $context,
Options $options = null,
User_Options $user_options = null,
Authentication $authentication = null,
Assets $assets = null
) {
parent::__construct( $context, $options, $user_options, $authentication, $assets );
$this->user_options = $user_options;
}

@@ -38,6 +42,8 @@
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Web_Tag;
use Google\Site_Kit\Modules\Search_Console\Settings as Search_Console_Settings;
use Google\Site_Kit_Dependencies\Google\Service\SubscribewithGoogle as Google_Service_SubscribewithGoogle;
use Google\Site_Kit\Modules\Reader_Revenue_Manager\Synchronize_OnboardingState;
Copy link
Collaborator

Choose a reason for hiding this comment

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

While we're at it, let's re-order this import alphabetically. Also, if we do remove the constructor as described above, we'll also need to remove a few unused imports.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Two points:

  1. Sanitization should be added for the publicationOnboardingStateChanged setting.
  2. Existing sanitization should be removed for the legacy publicationOnboardingStateLastSyncedAtMs setting.

Comment on lines 2 to 7
/**
* Class Google\Site_Kit\Modules\Analytics_4\Synchronize_OnboardingState.
*
* @since n.e.x.t
* @package Google\Site_Kit\Modules\Reader_Revenue_Manager
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

The header comment for this file appears to be quite different than other classes.

Suggested change
/**
* Class Google\Site_Kit\Modules\Analytics_4\Synchronize_OnboardingState.
*
* @since n.e.x.t
* @package Google\Site_Kit\Modules\Reader_Revenue_Manager
*/
/**
* Class Google\Site_Kit\Modules\Reader_Revenue_Manager\Synchronize_OnboardingState
*
* @package Google\Site_Kit\Modules\Reader_Revenue_Manager
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/

@@ -293,7 +295,6 @@ public function test_get_debug_fields() {
array(
'reader_revenue_manager_publication_id',
'reader_revenue_manager_publication_onboarding_state',
'reader_revenue_manager_publication_onboarding_state_last_synced_at',
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to my observation, I don't think any other change apart from this one is needed in this test suite.

$this->assertFalse( $settings['publicationOnboardingStateChanged'] );

do_action( Synchronize_OnboardingState::CRON_SYNCHRONIZE_ONBOARDING_STATE );
$test_synced_at = time();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$test_synced_at = time();

Comment on lines 152 to 165
// Get cron list and check if the cron is scheduled.
$crons = _get_cron_array();
$cron_exists = false;

foreach ( $crons as $timestamp => $cron_events ) {
foreach ( $cron_events as $event_key => $cron_event ) {
if ( Synchronize_OnboardingState::CRON_SYNCHRONIZE_ONBOARDING_STATE === $event_key ) {
$cron_exists = true;
break 2;
}
}
}

$this->assertTrue( $cron_exists );
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can simplify this.

Suggested change
// Get cron list and check if the cron is scheduled.
$crons = _get_cron_array();
$cron_exists = false;
foreach ( $crons as $timestamp => $cron_events ) {
foreach ( $cron_events as $event_key => $cron_event ) {
if ( Synchronize_OnboardingState::CRON_SYNCHRONIZE_ONBOARDING_STATE === $event_key ) {
$cron_exists = true;
break 2;
}
}
}
$this->assertTrue( $cron_exists );
$this->assertTrue(
(bool) wp_next_scheduled( Synchronize_OnboardingState::CRON_SYNCHRONIZE_ONBOARDING_STATE )
);

@@ -170,7 +177,7 @@ export default {
.dispatch( MODULES_ANALYTICS_4 )
.receiveGetAccountSummaries( {
accountSummaries,
nextPageToken: null,
nextPageToken: '',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to change this.

Suggested change
nextPageToken: '',
nextPageToken: null,

Comment on lines 94 to 100
const shouldShowNotification =
isDismissed === false &&
showApprovedNotificationUI === true &&
! isViewOnly &&
dashboardType === VIEW_CONTEXT_MAIN_DASHBOARD;
dashboardType === VIEW_CONTEXT_MAIN_DASHBOARD &&
initialPublicationOnboardingStateChanged.current === true &&
publicationOnboardingState === ONBOARDING_COMPLETE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently, the overlay notification no longer appears for me, because no one sets the value for UI_KEY_READER_REVENUE_MANAGER_SHOW_PUBLICATION_APPROVED_NOTIFICATION in the CORE_UI store, which is only done when the sync is run on the client-side.

The logic here should be changed so that the notification is displayed when either the UI store value is set, OR, the new conditions are met.

Somewhat like the following:

const shouldShowNotification =
	isDismissed === false &&
	! isViewOnly &&
	dashboardType === VIEW_CONTEXT_MAIN_DASHBOARD &&
	( showApprovedNotificationUI === true ||
		( initialPublicationOnboardingStateChanged.current === true &&
			publicationOnboardingState === ONBOARDING_COMPLETE ) );

Could you please investigate and ensure that the notification appears?

@ankitrox
Copy link
Collaborator Author

Thank you @nfmohit for reviewing the PR and adding the feedback. I've addressed the feedback and left response for couple of comments.

Over to you for another round of review.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants