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

Checkout: Simplify code for rendering line item sublabel #80987

Merged
merged 9 commits into from
Aug 30, 2023

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented Aug 23, 2023

Line items in checkout are rendered by the CheckoutLineItem component (previously WPLineItem). They consist of several parts:

  1. A product title.
  2. An item sublabel that may explain the product (eg: "Mailboxes and Productivity Tools") or the price breakdown (eg: "Plan Subscription: $48 per year").
  3. A price, possibly with a crossed-out amount.
  4. Additional lines for certain discounts or products.
Screenshot 2023-08-23 at 4 38 03 PM

In this list the item sublabel is rendered in the following way:

  • The getSublabel() function is called to generate the general text.
  • Using a translate() function, the general text is combined with other text after a colon, like the billing interval.

This is a slightly strange use of a translated string since its primary purpose is layout (eg: %(premiumLabel)s %(sublabel)s: %(interval)s contains nothing really to translate). It also creates a fair amount of complexity when reading or trying to alter the sublabel since it is combined in so many different ways. This has led to confusion when devs are attempting to fix bugs or add new subtext. It's also inflexible since it means that the general text must be a string only.

Proposed Changes

In this PR we rename getSublabel() to turn it into a React component instead.

This change allows us to render it combined with other information using HTML for layout and makes its behavior more explicit.

Testing Instructions

This PR should not change how line items are rendered, so testing involves adding various products to your shopping cart and verifying that they render the same way in checkout as before this PR.

@sirbrillig sirbrillig self-assigned this Aug 23, 2023
@github-actions
Copy link

github-actions bot commented Aug 23, 2023

@sirbrillig sirbrillig added the [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. label Aug 23, 2023
@matticbot
Copy link
Contributor

matticbot commented Aug 23, 2023

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~166 bytes removed 📉 [gzipped])

name                               parsed_size           gzip_size
site-purchases                           -74 B  (-0.0%)      -12 B  (-0.0%)
purchases                                -74 B  (-0.0%)      -12 B  (-0.0%)
plans                                    +33 B  (+0.0%)     -149 B  (-0.0%)
jetpack-connect                          +33 B  (+0.0%)     -149 B  (-0.0%)
jetpack-cloud-pricing                    +33 B  (+0.0%)     -149 B  (-0.1%)
jetpack-cloud-plugin-management          +33 B  (+0.0%)     -149 B  (-0.0%)
jetpack-cloud-partner-portal             +33 B  (+0.0%)     -149 B  (-0.1%)
jetpack-cloud-features-comparison        +33 B  (+0.0%)     -149 B  (-0.1%)
jetpack-cloud-agency-dashboard           +33 B  (+0.0%)     -149 B  (-0.1%)
checkout                                 +13 B  (+0.0%)     -154 B  (-0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~154 bytes removed 📉 [gzipped])

name                                              parsed_size           gzip_size
async-load-masterbar-cart-masterbar-cart-wrapper        +33 B  (+0.0%)     -149 B  (-0.5%)
async-load-calypso-my-sites-checkout-modal              +13 B  (+0.0%)     -154 B  (-0.0%)
async-load-calypso-blocks-editor-checkout-modal         +13 B  (+0.0%)     -154 B  (-0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@sirbrillig
Copy link
Member Author

One thing I want to check before putting this up for review: does this change how the sublabel renders in RTL languages? or languages with word orders significantly different from English?

@sirbrillig
Copy link
Member Author

I added fallback translations for the modified strings to make sure that this looks right in different languages.

Before/after in JP:

before-80987-jp

Before/after in HE:

before-80987

@sirbrillig sirbrillig marked this pull request as ready for review August 24, 2023 17:30
@sirbrillig sirbrillig requested a review from a team as a code owner August 24, 2023 17:30
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 24, 2023
@sirbrillig sirbrillig merged commit 0b8a5af into trunk Aug 30, 2023
@sirbrillig sirbrillig deleted the update/simplify-checkout-line-item-sublabel branch August 30, 2023 14:54
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 30, 2023
@a8ci18n
Copy link

a8ci18n commented Aug 30, 2023

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/8826688

Thank you @sirbrillig for including a screenshot in the description! This is really helpful for our translators.

@a8ci18n
Copy link

a8ci18n commented Sep 10, 2023

Translation for this Pull Request has now been finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants