Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Split Checkout block component into smaller files #3062

Merged
merged 9 commits into from
Aug 31, 2020

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Aug 27, 2020

The component for the Checkout block kept growing and growing as we added features, it was over 440 lines of code and it was becoming difficult to work with. This PR splits it into smaller files.

Even though the line diff of this PR is quite big, it doesn't add or remove any lines other than moving files/code around, renaming some CSS classes and updating the imports according to the new file structure.

How to test the changes in this Pull Request:

Do some smoke testing of the Checkout block: add it in the editor, change some attributes, verify it works in the frontend, try making a purchase, etc.

@Aljullu Aljullu added status: needs review type: refactor The issue/PR is related to refactoring. skip-changelog PRs that you don't want to appear in the changelog. block: checkout Issues related to the checkout block. labels Aug 27, 2020
@Aljullu Aljullu added this to the 3.3.0 milestone Aug 27, 2020
@Aljullu Aljullu requested a review from a team as a code owner August 27, 2020 08:59
@Aljullu Aljullu self-assigned this Aug 27, 2020
@Aljullu Aljullu requested review from haszari and removed request for a team August 27, 2020 08:59
@github-actions
Copy link
Contributor

github-actions bot commented Aug 27, 2020

Size Change: +294 B (0%)

Total Size: 1.11 MB

Filename Size Change
build/all-products-frontend.js 31.2 kB +1 B
build/all-products.js 35.7 kB +4 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 8.89 kB +4 B (0%)
build/atomic-block-components/add-to-cart.js 7.46 kB +1 B
build/atomic-block-components/button-frontend.js 2.02 kB +2 B (0%)
build/atomic-block-components/button.js 835 B -2 B (0%)
build/atomic-block-components/category-list-frontend.js 469 B +1 B
build/atomic-block-components/image-frontend.js 1.71 kB -1 B
build/atomic-block-components/image.js 1.15 kB -1 B
build/atomic-block-components/price-frontend.js 2.1 kB +1 B
build/atomic-block-components/rating.js 527 B +1 B
build/atomic-block-components/sale-badge.js 864 B -1 B
build/atomic-block-components/stock-indicator-frontend.js 568 B +1 B
build/atomic-block-components/stock-indicator.js 571 B -1 B
build/atomic-block-components/summary.js 925 B +1 B
build/cart-frontend.js 69 kB +1 B
build/cart.js 37.4 kB +2 B (0%)
build/checkout-frontend.js 84.1 kB +117 B (0%)
build/checkout.js 40.7 kB +157 B (0%)
build/featured-product.js 9.94 kB +1 B
build/handpicked-products.js 7.34 kB +1 B
build/price-filter-frontend.js 14.4 kB -1 B
build/product-category.js 8.35 kB -1 B
build/product-on-sale.js 7.96 kB -2 B (0%)
build/product-tag.js 6.49 kB -2 B (0%)
build/products-by-attribute.js 8.29 kB +3 B (0%)
build/reviews-by-product.js 13.3 kB -2 B (0%)
build/reviews-frontend.js 9.35 kB +1 B
build/single-product-frontend.js 34 kB -2 B (0%)
build/single-product.js 10.1 kB -1 B
build/style-rtl.css 18 kB +2 B (0%)
build/style.css 18 kB +4 B (0%)
build/vendors.js 416 kB +5 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.76 kB 0 B
build/active-filters.js 8.83 kB 0 B
build/all-reviews.js 9.76 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/button.js 3.16 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/image~atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/category-list.js 475 B 0 B
build/atomic-block-components/price.js 2.13 kB 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/sale-badge-frontend.js 863 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/sku.js 394 B 0 B
build/atomic-block-components/summary-frontend.js 918 B 0 B
build/atomic-block-components/tag-list-frontend.js 466 B 0 B
build/atomic-block-components/tag-list.js 472 B 0 B
build/atomic-block-components/title-frontend.js 1.22 kB 0 B
build/atomic-block-components/title.js 1.05 kB 0 B
build/attribute-filter-frontend.js 18.1 kB 0 B
build/attribute-filter.js 12.4 kB 0 B
build/blocks.js 3.54 kB 0 B
build/editor-rtl.css 13.9 kB 0 B
build/editor.css 13.9 kB 0 B
build/featured-category.js 7.7 kB 0 B
build/price-filter.js 10.2 kB 0 B
build/product-best-sellers.js 7.42 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-new.js 7.58 kB 0 B
build/product-search.js 3.54 kB 0 B
build/product-top-rated.js 7.55 kB 0 B
build/reviews-by-category.js 11.8 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors~atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.09 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.28 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 787 B 0 B
build/wc-payment-method-cod.js 875 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 11.9 kB 0 B
build/wc-settings.js 2.33 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

@haszari
Copy link
Member

haszari commented Aug 27, 2020

Proactive refactoring, I like! 🏅

Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Thanks for streamlining this @Aljullu - great to see our code getting tidier and easier to wrangle as it grows.

I did some quick smoke testing in Chrome, Safari and Firefox, with Storefront. Didn't see any issues.

I did get confused by a quirk with Phone field (unrelated to this PR) - if the order is virtual, there's no Shipping address field, and no Phone field. I understand why this is the case – phone is a shipping field (not included in billing addr). But the block options aren't clear, so this could be confusing. Phone and Require phone number only apply to shippable orders. I haven't added a follow up issue since this might be expected behaviour for most merchants – do you think this is worth adding an issue for?

Screen Shot 2020-08-28 at 9 21 17 AM

'wc-block-components-checkout-form',
className
) }
className={ classnames( 'wc-block-components-form', className ) }
Copy link
Member

Choose a reason for hiding this comment

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

Just noting this change - not just a refactor, this changes the classname for form (and others). Is there any potential theme impact? Is this form component abstract or is it somewhat coupled to checkout?

Copy link
Member

Choose a reason for hiding this comment

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

e.g. is this NumberedForm - where are the checkout-specific styles/behaviour (vs generic)?

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 assumed this is superseded by #3062 (comment), correct? 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Is this form component abstract or is it somewhat coupled to checkout?
e.g. is this NumberedForm - where are the checkout-specific styles/behaviour (vs generic)?

I assumed this is superseded by #3062 (comment), correct? 🙂

Yes ish - though I am still curious how generic this Form component is, might need more work/tweaks when used elsewhere (not in Checkout). We can iterate when that happens, if it is an issue.

showPhoneField: PropTypes.bool.isRequired,
};

export default CheckoutForm;
Copy link
Member

Choose a reason for hiding this comment

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

I see this is the business end, still a big component. Good to start breaking it down, and we can iterate more in future 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, at some point it might make sense to keep splitting this one into smaller chunks. But I feel now it's much more self-contained (it's only the form) than before (it was the entire block inside a single component).

) }
</CheckoutForm>
<CheckoutForm
loginToCheckoutUrl={ loginToCheckoutUrl }
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to pass the login URL through all the layers? Could be local to the component that needs it, or refactored out to utils/settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point. Moved it to a utils.js file in bc03b89.

@@ -45,4 +45,8 @@ WC Blocks 3.3.0, introduced express payment methods in the Cart block. In order
<td><code>wc-block-components-express-checkout-payment-event-buttons</code></td>
<td><code>wc-block-components-express-payment__event-buttons</code></td>
</tr>
<tr>
<td><code>wc-block-components-checkout-form</code></td>
<td><code>wc-block-checkout__form</code></td>
Copy link
Member

Choose a reason for hiding this comment

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

Ah I see this change is documented! 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and moved it to a specific file for 3.4.0 in 0710e73.

@haszari
Copy link
Member

haszari commented Aug 27, 2020

Spotted a visual issue in editor when reviewing this: #3068

@haszari haszari modified the milestones: 3.3.0, 3.4.0 Aug 30, 2020
@Aljullu
Copy link
Contributor Author

Aljullu commented Aug 31, 2020

Thanks for the review @haszari!

I did get confused by a quirk with Phone field (unrelated to this PR) - if the order is virtual, there's no Shipping address field, and no Phone field. I understand why this is the case – phone is a shipping field (not included in billing addr). But the block options aren't clear, so this could be confusing. Phone and Require phone number only apply to shippable orders. I haven't added a follow up issue since this might be expected behaviour for most merchants – do you think this is worth adding an issue for?

Good catch! I don't have a strong opinion on this, it's true it might be confusing for stores that only sell digital products, but I think that can be considered the expected behavior?

@Aljullu Aljullu merged commit 981fd9b into main Aug 31, 2020
@Aljullu Aljullu deleted the refactor/split-checkout-block branch August 31, 2020 10:17
@haszari
Copy link
Member

haszari commented Aug 31, 2020

Good catch! I don't have a strong opinion on this, it's true it might be confusing for stores that only sell digital products, but I think that can be considered the expected behavior?

Yep - agreed. Just noting the potentially confusing UX/behaviour when I see it 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: checkout Issues related to the checkout block. skip-changelog PRs that you don't want to appear in the changelog. type: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants