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

Add syncPublicationOnboardingState action #9017

Merged

Conversation

ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Jul 15, 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.

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.

@ankitrox ankitrox marked this pull request as ready for review July 15, 2024 14:41
Copy link

github-actions bot commented Jul 15, 2024

Build files for bef1496 have been deleted.

Copy link

github-actions bot commented Jul 15, 2024

Size Change: +324 B (+0.02%)

Total Size: 1.65 MB

Filename Size Change
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 12.8 kB +324 B (+2.59%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 55.3 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.2 kB
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 842 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 7.47 kB
./dist/assets/js/31-********************.js 2.76 kB
./dist/assets/js/32-********************.js 2.25 kB
./dist/assets/js/33-********************.js 3.64 kB
./dist/assets/js/34-********************.js 935 B
./dist/assets/js/35-********************.js 892 B
./dist/assets/js/36-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 776 B
./dist/assets/js/googlesitekit-activation-********************.js 23.7 kB
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 59.2 kB
./dist/assets/js/googlesitekit-adminbar-********************.js 34.4 kB
./dist/assets/js/googlesitekit-api-********************.js 10 kB
./dist/assets/js/googlesitekit-components-gm2-********************.js 5.88 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.35 kB
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.04 kB
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.3 kB
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.98 kB
./dist/assets/js/googlesitekit-datastore-user-********************.js 25 kB
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 76.9 kB
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 645 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 731 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 674 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.92 kB
./dist/assets/js/googlesitekit-main-dashboard-********************.js 141 kB
./dist/assets/js/googlesitekit-modules-ads-********************.js 29.4 kB
./dist/assets/js/googlesitekit-modules-adsense-********************.js 113 kB
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 161 kB
./dist/assets/js/googlesitekit-modules-********************.js 22.1 kB
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 22.6 kB
./dist/assets/js/googlesitekit-modules-search-console-********************.js 58.1 kB
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32 kB
./dist/assets/js/googlesitekit-notifications-********************.js 1.69 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 376 B
./dist/assets/js/googlesitekit-settings-********************.js 62.7 kB
./dist/assets/js/googlesitekit-splash-********************.js 73 kB
./dist/assets/js/googlesitekit-user-input-********************.js 48.3 kB
./dist/assets/js/googlesitekit-vendor-********************.js 321 kB
./dist/assets/js/googlesitekit-widgets-********************.js 77.7 kB
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 61.4 kB
./dist/assets/js/runtime-********************.js 1.3 kB

compressed-size-action

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

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

Hey @ankitrox, nice work here so far. I have left a few comments, please take a look.

@ankitrox
Copy link
Collaborator Author

Thank you @techanvil for reviewing the PR and adding your valuable feedback. I would also like to thank you for your guidance on testing Date.now(), it was an absolute help and to the point!

I have addressed your feedback and sending your way for another review.

Thanks again.

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

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

LGTM, nice one @ankitrox!

@techanvil techanvil merged commit 2628f57 into develop Jul 19, 2024
21 checks passed
@techanvil techanvil deleted the enhancement/8796-sync-publication-onboarding-state-action branch July 19, 2024 10:23
import { commonActions, combineStores } from 'googlesitekit-data';
import { createFetchStore } from '../../../googlesitekit/data/create-fetch-store';
import {
MODULES_READER_REVENUE_MANAGER,
MODULE_SLUG,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have an (old) related issue about this. See #3417.

It's worth noting that we included the name in the constant for module stores which previously all used STORE_NAME internally and aliases externally. So this kind of generic constant is one we'll want to avoid here as well.

@nfmohit @techanvil

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for flagging this @aaemnnosttv .

I will rename this to READER_REVENUE_MANAGER_MODULE_SLUG in subsequent issue #8846

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep the SLUG part as a prefix rather than a suffix, similar to the store name constant.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly, I'd be happy to use RRM everywhere instead of the full name which is quite long as can be seen here 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

I should mention here that @ankitrox had previously used RRM in another constant name but I advised him against it, referring to our naming conventions whereby we avoid abbreviations in variable names etc.

Tbh, I was wondering if I was being a bit dogmatic, but was simply going on memories of past feedback. I'm entirely happy if we take a more pragmatic approach and use the RRM abbreviation for names in the codebase!

} from './constants';

const fetchGetPublicationsStore = createFetchStore( {
baseName: 'getPublications',
controlCallback: () =>
API.get(
'modules',
'reader-revenue-manager',
MODULE_SLUG,
'publications',
{},
{ useCache: true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated observation – but selectors like this one which are only really used during setup should not use cache so that it pulls fresh data every time, otherwise there is no way to pull a new publication after creating one on the service once cached.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good spot @aaemnnosttv.

It would be nice to roll this one-line fix into a forthcoming RRM PR rather than create a separate issue for it.

@ankitrox, could I ask you to please include it in your next PR?

Suggested change
{ useCache: true }
{ useCache: false }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you folks! Just to make sure we don't miss this out, I've included this in my PR for #8800.

@@ -94,6 +190,7 @@ const baseResolvers = {
.getPublications();
if ( publications === undefined ) {
yield fetchGetPublicationsStore.actions.fetchGetPublications();
yield baseActions.syncPublicationOnboardingState();
Copy link
Collaborator

Choose a reason for hiding this comment

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

@techanvil @ankitrox Why did we add this here? Syncing the onboarding state only makes sense in the context of a selected publication in settings which this selector/resolver is not related to. Also, since this will usually be called before any selection is made I would expect this to not have the intended result. We should only sync the onboarding state for the publication which is saved in settings, not simply selected in state.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aaemnnosttv this is defined as a requirement in the design doc, and the AC/IB for this issue. So, I haven't really questioned it. My presumption is that the intention is to resync the onboarding state for the currently selected publication any time we visit the Settings screen after it has been connected. Arguably, though, it could make sense to decouple the sync from getPublications(). Maybe @nfmohit can shed a bit more light on this one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for raising this, @aaemnnosttv. @techanvil is correct with the presumption above. Since we show the PublicationOnboardingStateNotice in the settings screen based on the publicationOnboardingState module setting which is updated once every hour, there is a chance we may show an unintended notice due to the onboarding state not being up to date.

Since the getPublications selector would likely be resolved in SettingsEdit, my intention was to dispatch the syncPublicationOnboardingState action that would update the onboarding state in the module settings. The action only does this if the module is connected and a publication ID is set.

This would ensure that the correct PublicationOnboardingStateNotice is shown (or not shown at all). Would you suggest we do this any differently?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that I think deeply about this, I feel this is not really necessary and does not add much value and has the potential to cause problems as Evan mentioned above. @techanvil What do you think of the idea of removing this dispatch as part of a subsequent issue?

Copy link
Collaborator

@aaemnnosttv aaemnnosttv Jul 27, 2024

Choose a reason for hiding this comment

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

If the intention is to sync the state on the settings view, then I think it would be more appropriate to move the effect to that component as it's not related to this selector.

We also shouldn't assume this selector will only be called in settings in the future, so this could lead to unexpected behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @nfmohit and @aaemnnosttv. Agreed, it would be good to move the sync out to the component.

I think this merits a new issue to flesh out the details. We also need to revisit the PublicationSelect component due to the divergence from the IB in PR #9006:

Note: publicationOnboardingStateLastSyncedAtMs is not getting updated as part of onPublicationChange function because it will be updated as part of the syncPublicationOnboardingState action, which will run immediately before (getPublications resolver)/after (maybeSyncPublicationsOnboardingState) a publication is selected.

@nfmohit, would you be happy to create an issue for this?

Copy link
Collaborator

@nfmohit nfmohit Jul 30, 2024

Choose a reason for hiding this comment

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

Agreed, it would be good to move the sync out to the component.

I think this merits a new issue to flesh out the details.

Thank you @techanvil. About this one, now that I think about it, I feel updating it in SettingsEdit might actually have unexpected results. The action is responsible for showing the publication approved overlay notification by changing a core/ui data store key, which would only happen when the action is dispatched in the main dashboard. Also, the state would be updated once every hour anyway, so just updating it only for SettingsEdit doesn't seem to be worth it while the publication onboarding state notice also appears in SettingsView. To be fair, dispatching this as a part of the resolver was planned for redundancy.

I think this merits a new issue to flesh out the details. We also need to revisit the PublicationSelect component due to the divergence from the IB in PR #9006:

Note: publicationOnboardingStateLastSyncedAtMs is not getting updated as part of onPublicationChange function because it will be updated as part of the syncPublicationOnboardingState action, which will run immediately before (getPublications resolver)/after (maybeSyncPublicationsOnboardingState) a publication is selected.

About this one, I also feel updating publicationOnboardingStateLastSyncedAtMs as part of syncPublicationOnboardingState is sufficient.

Please let me know what you think, thanks so much!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you @techanvil. About this one, now that I think about it, I feel updating it in SettingsEdit might actually have unexpected results. The action is responsible for showing the publication approved overlay notification by changing a core/ui data store key, which would only happen when the action is dispatched in the main dashboard. Also, the state would be updated once every hour anyway, so just updating it only for SettingsEdit doesn't seem to be worth it while the publication onboarding state notice also appears in SettingsView. To be fair, dispatching this as a part of the resolver was planned for redundancy.

Thanks @nfmohit. As you've pointed out, the publication onboarding state notice appears both in SettingsEdit and SettingsView, so it's a bit of an oddity to only sync the state in SettingsEdit. I think we could either dispatch the sync in SettingsView instead, ensuring the notice is up-to-date in both places, or not at all, and allow for the fact it could be stale. Obviously from UX perspective it would be better if it was up-to-date, so I'd lean in that direction; that said we might then want to consider a loading state which could add a bit of complexity. Maybe we can simply omit it for now and add it as an improvement post launch.

If we do still sync on the Settings screen, setting the core/ui value won't have any effect so I don't see it being too much of a concern here; that said we could still amend the action so as to avoid that if not on the dashboard.

Note: publicationOnboardingStateLastSyncedAtMs is not getting updated as part of onPublicationChange function because it will be updated as part of the syncPublicationOnboardingState action, which will run immediately before (getPublications resolver)/after (maybeSyncPublicationsOnboardingState) a publication is selected.

About this one, I also feel updating publicationOnboardingStateLastSyncedAtMs as part of syncPublicationOnboardingState is sufficient.

Hmm. If we are removing the call to syncPublicationOnboardingState() from the Settings screen entirely, then the logic about it being run immediately before a publication is selected no longer holds true.

So, we could find ourselves making another call to the API in order to sync the onboarding state when we land on the dashboard, even though we've just updated the value.

I would say it would be preferable to avoid this to help reduce unneeded API requests and the relevant API quota usage. So my preference would be to update the timestamp if we are not syncing on the Settings screen. However, it's a pretty marginal point and again something we could address post launch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for your input, Tom! I've included updating this module setting as part of my selectPublication action proposed in my PR for #8800.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good, nice one Nahid!

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.

4 participants