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

Update/typescript checkout shipping #3925

Merged
merged 8 commits into from
Mar 9, 2021

Conversation

ralucaStan
Copy link
Contributor

PR adding types to /packages/checkout/shipping directory.

How to test the changes in this Pull Request:
Checkout branch and make sure code is free of TS warnings errors.
Testing is limited to smoke test the Cart and Checkout blocks to verify there are no regressions.

Just a note that this PR already typed FormattedMonetaryAmount component. So I just kept my file and ignored the change brought to the file here aa82c92#diff-d6ebd1dae536334d33ae51da0820ecd0896c24c57a34f5ddaebd0f8b1c98c12cL36

@ralucaStan ralucaStan added status: needs review skip-changelog PRs that you don't want to appear in the changelog. type: technical debt This issue/PR represents/solves the technical debt of the project. labels Mar 5, 2021
@ralucaStan ralucaStan requested a review from a team as a code owner March 5, 2021 14:59
@ralucaStan ralucaStan self-assigned this Mar 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2021

Size Change: +2.72 kB (0%)

Total Size: 1.15 MB

Filename Size Change
build/active-filters-frontend.js 8.41 kB +37 B (0%)
build/active-filters.js 8.5 kB +2 B (0%)
build/all-products-frontend.js 34.9 kB +212 B (+1%)
build/all-products.js 36.5 kB +56 B (0%)
build/all-reviews.js 9.88 kB -5 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.41 kB +34 B (+1%)
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 335 B +1 B (0%)
build/atomic-block-components/add-to-cart-frontend.js 9.33 kB +142 B (+2%)
build/atomic-block-components/add-to-cart.js 7.72 kB +44 B (+1%)
build/atomic-block-components/button-frontend.js 2.39 kB +14 B (+1%)
build/atomic-block-components/button.js 840 B +1 B (0%)
build/atomic-block-components/category-list-frontend.js 470 B +1 B (0%)
build/atomic-block-components/image-frontend.js 1.77 kB -1 B (0%)
build/atomic-block-components/image.js 1.23 kB +1 B (0%)
build/atomic-block-components/price-frontend.js 1.96 kB -21 B (-1%)
build/atomic-block-components/price.js 1.98 kB -22 B (-1%)
build/atomic-block-components/rating-frontend.js 520 B -1 B (0%)
build/atomic-block-components/rating.js 525 B -1 B (0%)
build/atomic-block-components/sale-badge-frontend.js 859 B -2 B (0%)
build/atomic-block-components/sale-badge.js 870 B -1 B (0%)
build/atomic-block-components/sku-frontend.js 389 B -1 B (0%)
build/atomic-block-components/stock-indicator-frontend.js 569 B -1 B (0%)
build/atomic-block-components/tag-list-frontend.js 465 B -2 B (0%)
build/atomic-block-components/title-frontend.js 1.35 kB +3 B (0%)
build/atomic-block-components/title.js 1.21 kB +1 B (0%)
build/attribute-filter-frontend.js 18.3 kB +41 B (0%)
build/attribute-filter.js 12.5 kB -6 B (0%)
build/blocks-checkout.js 16.8 kB +210 B (+1%)
build/blocks.js 3.5 kB -1 B (0%)
build/cart-frontend.js 76 kB +296 B (0%)
build/cart.js 38.7 kB +226 B (+1%)
build/checkout-frontend.js 80.6 kB +273 B (0%)
build/checkout.js 41.5 kB +126 B (0%)
build/featured-category.js 7.83 kB +3 B (0%)
build/featured-product.js 10.1 kB -3 B (0%)
build/handpicked-products.js 7.51 kB -1 B (0%)
build/price-filter-frontend.js 14.7 kB +5 B (0%)
build/price-filter.js 9.96 kB -26 B (0%)
build/price-format.js 1.46 kB -2 B (0%)
build/product-best-sellers.js 7.58 kB +1 B (0%)
build/product-categories.js 3.24 kB +1 B (0%)
build/product-category.js 8.53 kB +1 B (0%)
build/product-new.js 7.76 kB +3 B (0%)
build/product-on-sale.js 8.15 kB -4 B (0%)
build/product-search.js 3.58 kB +1 B (0%)
build/product-tag.js 6.58 kB +1 B (0%)
build/product-top-rated.js 7.73 kB +1 B (0%)
build/products-by-attribute.js 8.51 kB +1 B (0%)
build/reviews-by-category.js 11.9 kB -7 B (0%)
build/reviews-by-product.js 13.5 kB -1 B (0%)
build/reviews-frontend.js 9.57 kB -3 B (0%)
build/single-product-frontend.js 38 kB +304 B (+1%)
build/single-product.js 10.3 kB -1 B (0%)
build/style-rtl.css 18.9 kB -14 B (0%)
build/style.css 18.9 kB -15 B (0%)
build/vendors--atomic-block-components/price-frontend.js 6.53 kB -2 B (0%)
build/vendors.js 419 kB +818 B (0%)
build/wc-blocks-middleware.js 1.11 kB -2 B (0%)
build/wc-blocks-registry.js 2.69 kB +7 B (0%)
build/wc-settings.js 2.42 kB -7 B (0%)
build/wc-shared-context.js 1.53 kB -2 B (0%)
build/wc-shared-hocs.js 1.72 kB +3 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/sku.js 394 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary-frontend.js 920 B 0 B
build/atomic-block-components/summary.js 925 B 0 B
build/atomic-block-components/tag-list.js 473 B 0 B
build/editor-rtl.css 14.9 kB 0 B
build/editor.css 14.9 kB 0 B
build/vendors-style-rtl.css 1.05 kB 0 B
build/vendors-style.css 1.05 kB 0 B
build/wc-blocks-data.js 7.2 kB 0 B
build/wc-payment-method-bacs.js 820 B 0 B
build/wc-payment-method-cheque.js 816 B 0 B
build/wc-payment-method-cod.js 913 B 0 B
build/wc-payment-method-paypal.js 853 B 0 B
build/wc-payment-method-stripe.js 12.2 kB 0 B

compressed-size-action

@ralucaStan ralucaStan force-pushed the update/typescript-checkout-shipping- branch from bf7f997 to 8a16e36 Compare March 5, 2021 15:10
Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

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

I tested cart and checkout block (particularly shipping) and noticed no regressions 👍🏻

I have added a few comments, and some issues I spotted in TS console.

Other than that I also have 2 questions which may not require action, but we should add to our hack.md file as notes.

  1. Should we rename all .js to .ts in packages we convert? I noticed in shipping-rates-control the index file was left as a JS file.
  2. When do we use type-defs vs a types.ts file within the package/component directory? I think we may all be handling this is different ways. Is it just based on if they are shared? Personally I prefer types.ts so it's in the same context as the component using it.

className="wc-block-components-radio-control__description"
>
{ description }
</span>
) }
{ secondaryDescription && (
<span
id={ id ? `${ id }__secondary-description` : null }
id={ id && `${ id }__secondary-description` }
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 good improvement, not sure why null was there originally.

@@ -64,7 +74,7 @@ const FormattedMonetaryAmount = ( {
className
);
const numberFormatProps = {
displayType,
displayType: 'text' as NumberFormatProps[ 'displayType' ],
Copy link
Member

Choose a reason for hiding this comment

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

I think we should move this one to our FormattedMonetaryAmount props since we do use this in other places and we always set the default value to 'text'. The type can then go within FormattedMonetaryAmountProps.

/**
* Formatted price component.
*
* Takes a price and returns a formatted price using the NumberFormat component.
*
* @param {Object} props Component props.
* @param {string=} props.className CSS class used.
* @param {string} props.className CSS class used.
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this docblock and inline the comments now (within FormattedMonetaryAmountProps)

import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
Copy link
Member

Choose a reason for hiding this comment

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

This one gives me an error. Casing of @woocommerce/base-components/formatted-monetary-amount does not match the underlying filesystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this error appear only in your editor and not in the CI? If you don't have other casing on this path assets/js/base/components/formatted-monetary-amount/index.tsx it might be a false positive. Found a similar issue. Could you maybe try to update to eslint-plugin-import@v2.8.0 and see if it still happens.

@ralucaStan
Copy link
Contributor Author

  1. Should we rename all .js to .ts in packages we convert? I noticed in shipping-rates-control the index file was left as a JS file.

I think that's the way to go, this also removes uncertainty whether a file was converted or not. I can add a note in the knowledge file

  1. When do we use type-defs vs a types.ts file within the package/component directory? I think we may all be handling this is different ways. Is it just based on if they are shared? Personally I prefer types.ts so it's in the same context as the component using it.

I can see how a file could use a shared type and something specific. I also prefer local types.ts files for specific types, but this is a good topic to bring to the team.

@ralucaStan
Copy link
Contributor Author

@mikejolley changes pushed

@ralucaStan ralucaStan force-pushed the update/typescript-checkout-shipping- branch from 3089564 to 4184390 Compare March 8, 2021 15:21
@mikejolley mikejolley merged commit ddbfd9c into trunk Mar 9, 2021
@mikejolley mikejolley deleted the update/typescript-checkout-shipping- branch March 9, 2021 10:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog PRs that you don't want to appear in the changelog. type: technical debt This issue/PR represents/solves the technical debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants