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

Custom dimension tile wrapper #7680

Merged
merged 50 commits into from
Oct 17, 2023

Conversation

nfmohit
Copy link
Collaborator

@nfmohit nfmohit commented Oct 9, 2023

Summary

Addresses issue:

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.

@nfmohit nfmohit marked this pull request as ready for review October 12, 2023 17:43
@github-actions
Copy link

github-actions bot commented Oct 12, 2023

Build files for 6553776 are ready:

@github-actions

This comment was marked as resolved.

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Looks great!

A few notes on the translation strings here, but they're minor.


I did encounter an issue when following the QA Brief:

Upon saving your selection, you should be directed to the OAuth flow. Cancel the OAuth flow to return to the SK dashboard.

I wasn't redirected, instead I was immediately shown this screen:

CleanShot 2023-10-13 at 15 53 40

Verify that clicking on "Update" makes the tiles go on a loading state

I don't see the loading state if I haven't granted OAuth access and am being redirected to the OAuth flow:

CleanShot.2023-10-13.at.15.54.25.mp4

Is that expected?

Even after I've granted access, I don't see a network request when clicking "Update":

CleanShot.2023-10-13.at.15.55.36.mp4

Comment on lines 243 to 262
{ createInterpolateElement(
__(
'Permissions updated? <RetryLink />',
'google-site-kit'
),
{
RetryLink: (
<Link
onClick={
handleCreateCustomDimensions
}
>
{ __(
'Retry',
'google-site-kit'
) }
</Link>
),
}
) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to have the separate translation string here, this should work:

Suggested change
{ createInterpolateElement(
__(
'Permissions updated? <RetryLink />',
'google-site-kit'
),
{
RetryLink: (
<Link
onClick={
handleCreateCustomDimensions
}
>
{ __(
'Retry',
'google-site-kit'
) }
</Link>
),
}
) }
{ createInterpolateElement(
__(
'Permissions updated? <a>Retry</a>',
'google-site-kit'
),
{
a: (
<Link
onClick={
handleCreateCustomDimensions
}
/>
),
}
) }

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 an argument to separating out the small translation strings is that things like __( 'Retry' ) and __( 'Learn more' ) are already translated, but keeping as much context in one string is usually best, and since the main string needs to be translated anyway, I think it's fine 😄 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thank you!

Comment on lines 265 to 280
{ createInterpolateElement(
__(
'You’ll need to contact your administrator. <LearnMoreLink />',
'google-site-kit'
),
{
LearnMoreLink: (
<Link href={ helpLink } external>
{ __(
'Learn more',
'google-site-kit'
) }
</Link>
),
}
) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here:

Suggested change
{ createInterpolateElement(
__(
'You’ll need to contact your administrator. <LearnMoreLink />',
'google-site-kit'
),
{
LearnMoreLink: (
<Link href={ helpLink } external>
{ __(
'Learn more',
'google-site-kit'
) }
</Link>
),
}
) }
{ createInterpolateElement(
__(
'You’ll need to contact your administrator. <a>Learn more</a>',
'google-site-kit'
),
{
a: (
<Link href={ helpLink } external />
),
}
) }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thank you!

Comment on lines 299 to 314
{ createInterpolateElement(
__(
'Retry didn’t work? <GetHelpLink />',
'google-site-kit'
),
{
GetHelpLink: (
<Link href={ helpLink } external>
{ __(
'Learn more',
'google-site-kit'
) }
</Link>
),
}
) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here:

Suggested change
{ createInterpolateElement(
__(
'Retry didn’t work? <GetHelpLink />',
'google-site-kit'
),
{
GetHelpLink: (
<Link href={ helpLink } external>
{ __(
'Learn more',
'google-site-kit'
) }
</Link>
),
}
) }
{ createInterpolateElement(
__(
'Retry didn’t work? <a>Learn more</a>',
'google-site-kit'
),
{
a: (
<Link href={ helpLink } external />
),
}
) }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thank you!

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.

Thanks @nfmohit! This is a big one and looking good. From my POV this looks quite close. There are some things that could be improved but we need to balance that with unblocking other important issues that are waiting for this to land, so let's focus on the most important things at this point and revisit any secondary points in a follow-up. Nice work!

@@ -95,6 +103,7 @@ CTA.propTypes = {
error: PropTypes.bool,
onClick: PropTypes.func,
children: PropTypes.node,
headerContent: PropTypes.node,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor detail, but good to co-locate related prop definitions if we're not sorting the list another way. i.e. putting header* props together.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thank you!

Comment on lines 290 to 294
registry
.select( MODULES_ANALYTICS_4 )
.getCreateCustomDimensionError(
'googlesitekit_post_date'
)
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 avoid using selectors for making assertions about actions. Actions are only concerned with changing state or producing side effects (like a request via a control). In this case, the assertion should be about the state. This way the action tests also cover the relevant portion of the reducer and won't break if the selector is implemented incorrectly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Understood, thank you @aaemnnosttv. I only used the selector here because it was a little inconvenient to access the error in the store because we need to generate the error key using the custom dimension options, which we don't have access to as it is not exported from custom-dimensions.js.

However, I've worked around that by adding a local copy of the custom dimension options in the test case and generating the error copy there.

Let me know what you think, thanks!

const { dimensions, infoTooltip, reportOptions, title } = options;

return ( WrappedComponent ) => {
const WithCustomDimensionsComponent = ( props ) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This component is quite large, it would be great to refactor it to be composed of a few inner components to reduce the overall complexity. We probably don't have time to do it now so this would be nice to do as a future follow-up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I'll open a follow-up issue as soon as the PR is approved otherwise, thanks!

title: definedTitle,
} = KEY_METRICS_WIDGETS[ widgetSlug ] || {};

const newsKeyMetricsEnabled = useFeature( 'newsKeyMetrics' );
Copy link
Collaborator

Choose a reason for hiding this comment

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

This guard is unnecessary because the only widgets that use it will be guarded by it, as well as KMW itself. Aside from that, if we did want such a guard, this is too late to use it because it won't stop all of the effects and other hooks from running.

Not every single thing used by a feature needs to include a guard for it 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed, thanks!


it( 'renders appropriate error if required custom dimensions are not available', () => {
const { container } = render( <WithCustomDimensionsComponent />, {
setupRegistry: ( registry ) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it cleaner to initialize the test registry in a beforeEach and then pass it to in the render options rather than doing the other way around (we're too flexible! 😄)

This way we can't apply common setup (the way beforeEach is intended to be used).

In this case it might only be

provideUserAuthentication( registry );
provideUserCapabilities( registry );

but that does help keep each test a bit more concise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thank you!

@nfmohit
Copy link
Collaborator Author

nfmohit commented Oct 17, 2023

Thanks @nfmohit! This is a big one and looking good. From my POV this looks quite close. There are some things that could be improved but we need to balance that with unblocking other important issues that are waiting for this to land, so let's focus on the most important things at this point and revisit any secondary points in a follow-up. Nice work!

Thank you for the kind words and review, @aaemnnosttv. I've addressed the feedback, thanks!

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Thanks, Nahid. Left more feedback for you. Please, let me know what you think.

Comment on lines 425 to 427
isSyncingAvailableCustomDimensions( state ) {
return !! state?.isSyncingAvailableCustomDimensions;
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is isSyncingAvailableCustomDimensions different from isFetchingSyncAvailableCustomDimensions? These are completely similar selectors with exactly the same logic. If we worry that isFetching may cause race conditions, then isSyncing has the same problem. I think that if we truly want to be safe here, we should use debounce the sync action and call it in the create dimensions action.

cc @aaemnnosttv

* @param {Object} error The error object.
* @param {string} customDimension Custom dimension to set creation error for.
*/
*receiveCreateCustomDimensionError( error, customDimension ) {
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 make this action to be a utility function then and have the same approach as we use for provide* helpers. So we will have something like this: provideCustomDimensionsError( registry, { customDimension, error } ).

Without an action like this, we'll have to export possibleCustomDimensions (as a constant, for example)

Fine with me.

Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Ok, looks good to me now. Thanks, @nfmohit.

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Looks good to me, but I noticed all E2E tests and the JS tests were failing. I re-ran them a few times and it seems something's actually off with them, can you look before we merge @eugene-manuilov?

@tofumatt tofumatt merged commit b2dc8d9 into develop Oct 17, 2023
23 of 24 checks passed
@tofumatt tofumatt deleted the enhancement/#7601-custom-dimension-wrapper branch October 17, 2023 13:50
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