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 shouldPromptGA4DashboardView selector and SwitchGA4DashboardViewNotification component. #6752

Merged
merged 20 commits into from
Mar 23, 2023

Conversation

kuasha420
Copy link
Contributor

@kuasha420 kuasha420 commented Mar 20, 2023

Summary

Addresses issue:

Relevant technical choices

Implementation slightly derives from IB - instead of duplicating isGatheringData logic and adapt it to be 3 days, we changed the isGatheringData to to return true for properties less 3 days old.

The banner is also only rendered if the Analytics module is connected, as discussed with @nfmohit.

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 5.6.
  • 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.

@github-actions
Copy link

github-actions bot commented Mar 20, 2023

Size Change: +714 B (0%)

Total Size: 1.22 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation-********************.js 22.5 kB +7 B (0%)
./dist/assets/js/googlesitekit-adminbar-********************.js 31.6 kB -10 B (0%)
./dist/assets/js/googlesitekit-api-********************.js 9.57 kB +5 B (0%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 5.99 kB -1 B (0%)
./dist/assets/js/googlesitekit-components-gm3-********************.js 9.73 kB +1 B (0%)
./dist/assets/js/googlesitekit-data-********************.js 2.15 kB +1 B (0%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.24 kB +2 B (0%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.09 kB -2 B (0%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 16.3 kB +2 B (0%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.33 kB +1 B (0%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 22.1 kB +1 B (0%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 62.6 kB +37 B (0%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 73.8 kB +638 B (+1%)
./dist/assets/js/googlesitekit-modules-********************.js 20.5 kB -3 B (0%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 68.5 kB -18 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 26.4 kB -2 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-********************.js 80.1 kB +41 B (0%)
./dist/assets/js/googlesitekit-modules-optimize-********************.js 18.8 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 21.2 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 44.9 kB -1 B (0%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32 kB -1 B (0%)
./dist/assets/js/googlesitekit-polyfills-********************.js 378 B +1 B (0%)
./dist/assets/js/googlesitekit-settings-********************.js 47.3 kB -2 B (0%)
./dist/assets/js/googlesitekit-splash-********************.js 65 kB -3 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 39.6 kB +5 B (0%)
./dist/assets/js/googlesitekit-vendor-********************.js 319 kB +6 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 56 kB +8 B (0%)
./dist/assets/js/runtime-********************.js 1.26 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 48.3 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.1 kB
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 7.31 kB
./dist/assets/js/29-********************.js 2.8 kB
./dist/assets/js/30-********************.js 2.28 kB
./dist/assets/js/31-********************.js 3.72 kB
./dist/assets/js/32-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 769 B
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB
./dist/assets/js/googlesitekit-widgets-********************.js 16.5 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.

Hi @kuasha420, this looks good, I've left a few comments but they are all of a pretty trivial nature. Please see what you think.


const { setDashboardView, saveSettings } = useDispatch( MODULES_ANALYTICS );

const handleCTAClick = useCallback( async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed in this comment, we keep on using useCallback() in places where it doesn't actually give us any performance improvement as the components the resulting callbacks are passed to are not memoized, which means rather than a performance improvement, useCallback() is actually a performance hit for no gain.

I think we should stop this cargo-cult-esque usage of useCallback() and only apply it where it actually makes sense to do so. It's not serving any purpose in this instance, as neither SpinnerButton or the Button it's passed to are memoized, so it can be removed here.

The article linked to in the comment is worth a read for a refresh on this stuff.

Suggested change
const handleCTAClick = useCallback( async () => {
const handleCTAClick = async () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very interesting, I have removed the useCallback from this one for the reasons you've mentioned.

There's a lot of instances of this in our codebase and it's easy to just follow prior art, so do you think it's a good idea to reassess the use of useCallback and useMemo in our codebase and remove the unnecessary ones? If you think so, feel free to create an issue for it.

Cheers

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @kuasha420! I agree, it would be good to review our usage of these hooks and remove the unnecessary ones. I've created #6761 to track this.

Comment on lines 72 to 81
ctaComponent={
<SpinnerButton
className="googlesitekit-notification__cta"
onClick={ handleCTAClick }
isSaving={ isSaving }
disabled={ isSaving }
>
{ __( 'Update dashboard', 'google-site-kit' ) }
</SpinnerButton>
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I realise this is following the IB, but considering how BannerNotification uses SpinnerButton, I think we could potentially implement this without ctaComponent, although we'd need to pass something to ctaLink in order for it to display - we passed a lone '# in other cases.

Suggested change
ctaComponent={
<SpinnerButton
className="googlesitekit-notification__cta"
onClick={ handleCTAClick }
isSaving={ isSaving }
disabled={ isSaving }
>
{ __( 'Update dashboard', 'google-site-kit' ) }
</SpinnerButton>
}
ctaLink="#"
ctaLabel={ __( 'Update dashboard', 'google-site-kit' ) }
onCTAClick={ handleCTAClick }

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if putting a link # will trigger the onClick but from my testing it does, so easy win here unless this causes any accessibility issues.

On a side note, I think we could do with a refactoring of the BannerNotification at some point so this ctaLink is not required when there's a label and click handler available in a future issue.

Cheers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed, although, I'm hoping we can take a more wholesale approach to BannerNotification improvements via #6730, so am a little hesitant to add an issue for this detail. If we don't get round to this redesign any time soon then it does feel like a detail that we should address in the current implementation.

assets/js/modules/analytics-4/datastore/report.test.js Outdated Show resolved Hide resolved
assets/js/modules/analytics/datastore/settings.test.js Outdated Show resolved Hide resolved
assets/js/modules/analytics/datastore/settings.test.js Outdated Show resolved Hide resolved
assets/js/modules/analytics/datastore/settings.test.js Outdated Show resolved Hide resolved
assets/js/modules/analytics/datastore/settings.test.js Outdated Show resolved Hide resolved
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 @kuasha420!

@techanvil techanvil merged commit 39198ce into develop Mar 23, 2023
@techanvil techanvil deleted the enhance/6544-switch-to-ga4-banner branch March 23, 2023 12:31
Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

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

A few retrospective comments here 👋

component: SwitchGA4DashboardViewNotification,
decorators: [
( Story ) => {
enabledFeatures.add( 'ga4Reporting' );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Features can be passed on a per-story basis using parameters. If all the stories for this component should have this feature, we could maybe set it at the Template level. Otherwise this is probably okay, but isn't what we normally do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The FeatureProvider or components incorporating that (ie. WithTestRegistry) didn't work here because that only provides the feature in react component context, but we're using isFeatureEnabled in the datastore code that requires the "global" enabledFeatures set to have the feature flag, that's why I had to take this approach. Probably could've parameterized this, however. 👍

.dispatch( MODULES_ANALYTICS_4 )
.receiveIsGatheringData( false );
return (
<WithTestRegistry registry={ registry }>
Copy link
Collaborator

Choose a reason for hiding this comment

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

WithTestRegistry shouldn't be used unless we really need it for some reason. We should be using WithRegistrySetup instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I initially used WithTestRegistry as it has a features prob, however that approach didn't work for the reason I mentioned in the other comment, I didn't bother refactoring it to use WithRegistrySetup afterwards because things seemed to work and probably laziness. 😅 Thanks for letting me know that WithRegistrySetup is generally preferred! 💪

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.

3 participants