Skip to content

UX improvement on WordPress.com account connection #1068

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

Merged
merged 9 commits into from
Oct 29, 2021

Conversation

ecgan
Copy link
Contributor

@ecgan ecgan commented Oct 28, 2021

Changes proposed in this Pull Request:

Part of #1065 .

This PR changes the WordPress.com account connection card to the newer design. The account connection functionality and track events should all remain the same.

Screenshots:

To be connected:

image

Connected account:

image

Detailed test instructions:

  1. Disconnect WordPress.com account in connection test page.
  2. Go to Setup MC flow. You should see the first screenshot above.
  3. Connect your WordPress.com account.
  4. When connection is done, you should see the second screenshot above.

Changelog entry

Update - Update the WordPress.com account connection UI to the newer design.

ecgan added 7 commits October 29, 2021 01:20
Remove old CardContent and ConnectAccount, and use new ConnectWPComAccountCard and ConnectedWPComAccountCard instead.

Also simplify code by passing down jetpack as props to WordPressDotComAccount, so we don't need to use useJetpackAccount hook and check for isResolving, it was never called anyway because the check has been done in SetupAccounts.
@ecgan ecgan requested a review from a team October 28, 2021 18:51
@ecgan ecgan self-assigned this Oct 28, 2021
Comment on lines -18 to -31
if ( isResolving ) {
return <AppSpinner />;
}

if ( ! jetpack ) {
return (
<TitleButtonLayout
title={ __(
'Error while loading WordPress.com account info',
'google-listings-and-ads'
) }
/>
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I believe we don't need this because it is already checked for in SetupAccounts parent component.

if (
! jetpack ||
( jetpack.active === 'yes' &&
( ! google || ( google.active === 'yes' && ! googleMCAccount ) ) )
) {
return <AppSpinner />;
}

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

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

Testing well. LGTM.

Comment on lines +15 to +28
appearance={ {
icon: (
<img
src={ wpLogoURL }
alt={ __(
'WordPress.com Logo',
'google-listings-and-ads'
) }
width="40"
height="40"
/>
),
title: 'WordPress.com',
} }
Copy link
Member

Choose a reason for hiding this comment

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


Would you think it could be more consistent on code perspective to add these to APPEARANCE and appearanceDict within the AccountCard component?

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 thought about that. For the long term code perspective, I think it may not be a good idea. If we were to make it consistent to handle WordPress.com Logo SVG, the AccountCard component is going to get more bloated. For example, in this Setup MC Step 1 page, even though we are not displaying phone and store icon, when we use AccountCard, those icons are imported.

I prefer to use composition here, and keep AccountCard general purpose and lean. That would also help with file splitting and tree shaking when we want to go towards that direction.

Copy link
Member

Choose a reason for hiding this comment

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

If we were to make it consistent to handle WordPress.com Logo SVG, the AccountCard component is going to get more bloated. For example, in this Setup MC Step 1 page, even though we are not displaying phone and store icon, when we use AccountCard, those icons are imported.

The size ratios of phone and store icons including their dependencies in the index.js are highlighted by red background. (Total three blocks. The zoom-in of phone icon block.)

Their size is only about 1.3 kB after gzip. I think even if the <AccountCard> file is getting more bloated, the impact is not a primary concern compared to the overall file size for the present.

2021-11-01 16 58 46


That would also help with file splitting and tree shaking when we want to go towards that direction.

For the long term, regardless of their file size ratios, we could still achieve tree shaking and further file splitting by moving them to another file under the same folder of <AccountCard>:

// Another standalone file
export const APPEARANCE_PHONE = {
	icon: <GridiconPhone size={ 32 } />,
	title: __( 'Phone number', 'google-listings-and-ads' ),
};

export const APPEARANCE_ADDRESS = {
	icon: <Icon icon={ storeIcon } size={ 32 } />,
	title: __( 'Store address', 'google-listings-and-ads' ),
};

And expose them from <AccountCard>:

// .~/components/account-card/index.js
export { APPEARANCE_ADDRESS, APPEARANCE_PHONE } from './appearance-contact-info';

Then the bundle of consumer side would not contain phone and store icon codes if it doesn't use any of the constants.

// A consumer component depends on the account-card file
import AccountCard, { APPEARANCE_GOOGLE } from '.~/components/account-card';

Copy link
Contributor Author

@ecgan ecgan Nov 2, 2021

Choose a reason for hiding this comment

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

The size ratios of phone and store icons including their dependencies in the index.js are highlighted by red background. (Total three blocks. The zoom-in of phone icon block.)

That's a good analysis 🙂 👍 What is that tool that you use to generate that treemap? 🤔

Their size is only about 1.3 kB after gzip.

Yes, the size for the phone and store icons is small and not a primary concern for the present.

To be clear, the mention of phone and store icons is to serve as an example. The point I was trying to bring up is that it can have a better code architecture design and be more scalable for the long run. With the current approach, if we are not mindful and careful, we might accidentally add a super large icon and it would be included in the bundle even though it is actually not used in the page.

For the long term, regardless of their file size ratios, we could still achieve tree shaking and further file splitting by moving them to another file under the same folder of <AccountCard>:

Yes, correct, and that's why I was doing this WPComAccountCard as a separate file (though not under the same folder of AccountCard), so that we don't need to do that later.

Then the bundle of consumer side would not contain phone and store icon codes if it doesn't use any of the constants.

The problem is, when we use <AccountCard>, phone and store icons are still included in the bundle, because of the use of appearanceDict (which has reference to the constants) within the <AccountCard> component:

const { icon, title } =
typeof appearance === 'object'
? appearance
: appearanceDict[ appearance ];

const appearanceDict = {
[ APPEARANCE.GOOGLE ]: {
icon: (
<img
src={ googleLogoURL }
alt={ __( 'Google Logo', 'google-listings-and-ads' ) }
width="40"
height="40"
/>
),
title: __( 'Google account', 'google-listings-and-ads' ),
},
[ APPEARANCE.PHONE ]: {
icon: <GridiconPhone size={ 32 } />,
title: __( 'Phone number', 'google-listings-and-ads' ),
},
[ APPEARANCE.ADDRESS ]: {
icon: <Icon icon={ storeIcon } size={ 32 } />,
title: __( 'Store address', 'google-listings-and-ads' ),
},
};

Edit: oops, I guess what you mean is that when we "move them to another file", we would also get rid of appearanceDict, and we would be using AccountCard like so, and that should be good and no problem: 😄

<AccountCard
  appearance={APPEARANCE_PHONE}
/>

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for replying.

I'm good with both code structures. Just to clarify that even if these assets are imported from <AccountCard>, bundle size, tree shaking, and code splitting will not be an issue.

What is that tool that you use to generate that treemap?

It's Webpack Bundle Analyzer. And a relevant usage can be found in the Detailed test instructions section in #1073.

With the current approach, if we are not mindful and careful, we might accidentally add a super large icon and it would be included in the bundle even though it is actually not used in the page.

I think with the current code structure, no matter where the huge inline SVG appears, it will be included in index.js at all. And I believe it will be discovered by the bundlewatch check.

@ecgan ecgan merged commit 8a0eb69 into feature/1065-ux-account-connection Oct 29, 2021
@ecgan ecgan deleted the feature/1065/wpcom-account branch October 29, 2021 18:39
@ecgan ecgan mentioned this pull request Oct 29, 2021
11 tasks
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