Commit Graph

31 Commits

Author SHA1 Message Date
Luigi Teschio 6bbf96d06a Add CI for monitoring TypeScript errors (https://github.com/woocommerce/woocommerce-blocks/pull/6106)
* Add a action that monitors TypeScript errors woocommerce/woocommerce-blocks#6068

Add a action that monitors TypeScript errors

* address feedback

* bot: update checkstyle.xml

* add @bartekbp/typescript-checkstyle as devDeps

* bot: update checkstyle.xml

* bot: update checkstyle.xml

* bot: update checkstyle.xml

* fix

* add checkstyle to .distignore

* add missing import

* address feedback

* fix error

* remove import

* fix name variable

* fix sort function

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2022-11-02 11:41:10 +01:00
Niels Lange c360c5654a Add filter for place order button label (https://github.com/woocommerce/woocommerce-blocks/pull/7154)
* WIP add filter for place order button label

* Solve TS issue

* Add display priority

* Refactor display priority

* WIP Implement useMemo()

* Try using a global cache

* Add docs for placeOrderLabel filter

* Update docs/third-party-developers/extensibility/checkout-block/available-filters.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Adjust docs

* Rename “placeOrderLabel” to “placeOrderButtonLabel”

* Update assets/js/types/type-defs/payments.ts

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Lucio Giannotta <lucio.giannotta@a8c.com>
2022-09-29 15:46:10 +07:00
Alex Florisca e37b787e50 Move mini cart outside cart-checkout folder (https://github.com/woocommerce/woocommerce-blocks/pull/6192)
* Move shared folder to /blocks

* Moved mini-cart block in blocks dir:

* Rename shared folder to cart-checkout-shared

* Remove customDir from mini-cart webpack entry

* Update assets/js/base/context/tsconfig.json

Co-authored-by: Tung Du <dinhtungdu@gmail.com>

* Feedback changes

Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2022-04-07 14:47:58 +01:00
Alex Florisca e15d516163 Revert "Move cart and mini-cart blocks into their own folders (https://github.com/woocommerce/woocommerce-blocks/pull/6126)" (https://github.com/woocommerce/woocommerce-blocks/pull/6190)
This reverts commit d005dbd2cf.
2022-04-05 11:14:32 +01:00
Alex Florisca d005dbd2cf Move cart and mini-cart blocks into their own folders (https://github.com/woocommerce/woocommerce-blocks/pull/6126)
* Move cart and mini-cart into their own folders

* Update other references of cart-checkout
2022-04-04 12:34:29 +01:00
Mike Jolley eb196226d8 WIP: Add Inner blocks to order summary (https://github.com/woocommerce/woocommerce-blocks/pull/6065)
* Sub/Total/Fee inner blocks

* Row blocks within the inner block

* Update icons

* Resolve stying issues

* Remove old block

* Pin totals row

* Locking logic update

* Heading inner block

* Refactor where inner blocks are defined

* Add todos

* Todo for Consider deprecating OrderMetaSlotFill and DiscountSlotFill in favour of inner block areas.

* Improve frontend registration of components using new entrypoint

* Experiment- external block context

* Revert "Experiment- external block context"

This reverts commit 4b75668ec7eb62f065c6a488cd942a666e26204f.

* Duplicate inner blocks to avoid conflicts with context

* Remove todo

* Rename block dir

* Some test fixes

* Fix import

* fix import

* linting

* Remove unused attributes

* Optional classname

* fix coupons import

* fix shipping mocks

* Styling

* Fix selectors in e2e tests

* Add back the wc-block-components-totals-wrapper class that was used for each segment in the totals Order summary

Because, removing them was:
-  a breaking change for the old structure
- was making it harder to target the inner blocks. Before the class was used to target each segment
- it was making the wc-block-components-totals-item behave as a child or parent depending on the inner block, inconsitency

* Reuse the TotalsWrapper component for C& C blocks inner blocks

This component was removed in this PR, but  we wrap components in the Cart and Checkout sidebar in a TotalsWrapper. This will ensure consistent spacing and borders are applied to items in the sidebar.

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
Co-authored-by: Raluca Stan <ralucastn@gmail.com>
2022-04-01 15:45:18 +02:00
Thomas Roberts 426eb51830 Update Checkout block E2E fixture and increase node version in GH actions (https://github.com/woocommerce/woocommerce-blocks/pull/5678)
* Remove unnecessary setup step and use node v16 in E2E action

* Ensure storefront is active

* Use new checkout fixture

* Try with only checkout test

* Update package.json

* Run all tests, not just checkout
2022-02-01 11:14:16 +00:00
Thomas Roberts a46f13c6c5 Move Checkout block attributes into metadata (`block.json`) (https://github.com/woocommerce/woocommerce-blocks/pull/5594)
* Add block title to AbstractBlock class

* Add block title to Checkout block

* Include all block.json files in tsconfig

* Add get_block_title method to Checkout.php

* Remove redundant block_title field

* Add block.json and remove static attributes from attributes.ts

* Register block using attributes from block.json

* Add metadata_path to AbstractBlock

* Add function to AssetsApi to get the metadata path from the plugin root

* Register the block using metadata if it's set in the block's class

* Remove get_block_title method

* Only add supports and attributes to the block when not registering with metadata

* Change get_block_metadata to get_block_metadata_path

* Change indentation to tabs in block.json

* Update comment to clarify why attributes and supports are set later

* Check if path to metadata is not empty instead of set and not empty

* Move checkout block out of cart-checkout directory

* Update get_block_metadata_path function to find block.json automatically

* Remove metadata path from AbstractBlock

* Check if there's a metadata file and register blocks with metadata if so

* Move deprecated attributes out of metadata and into attributes.ts

* Re-add deprecated attributes to checkout index

* Move order notes test

* Move test for checkout phone number in edito

* Fix indentation in checkout/block.json

* Move checkout terms tests

* Try forcing storefront theme in e2e tests

* Revert "Try forcing storefront theme in e2e tests"

This reverts commit 5b0fd47a2c39aadb0141a4ed28cbc0e6baa89625.

* Try capturing screenshot on test failures

* Try uploading error in try catch

* Try uploading artefacts on error

* Test uploading artefacts

* Screenshot just before looking for edit post layout

* Revert "Screenshot just before looking for edit post layout"

This reverts commit 61dff027789ce13a0d84e7b6f11e431637c5a450.

* Revert "Test uploading artefacts"

This reverts commit adf5cc55bcdb677f889bf5a62803b4150d98e665.

* Revert "Try uploading artefacts on error"

This reverts commit 7441a832a113a95fef89cc1b8db6dc79271be516.

* Revert "Try uploading error in try catch"

This reverts commit ca412ce505d56286b164f588a201a451f6bceeb6.

* Revert "Try capturing screenshot on test failures"

This reverts commit 0de6e97df19b116091a7bb3b8652713867d2d80f.

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
2022-01-28 16:37:06 +00:00
M. L. Giannotta 703051b1bc Storybook and TS migration of some cart checkout components (https://github.com/woocommerce/woocommerce-blocks/pull/5324)
* Migrate stories for `ProductName` to latest Storybook. Also add props
documentation and add named export.
* Migrate `TotalsFooterItem` to TypeScript and latest Storybook
* Add a `LooselyMustHave` utility type.
* Export `allSettings` so that they can be manipulated in stories and tests

* Implement a way to easily define and reuse Storybook controls

Implement a currency control for a common use-case of selecting currencies.
It currently implements EUR and USD as they have different properties.

* Migrate `TotalsDiscount` to TypeScript and implement stories
* Migrate `TotalsCoupon` to TypeScript and fix stories
* Change Coupon name within Storybook
* Nicer handling of removal of a coupon from Storybook

It now dynamically calculates the discount from the actual coupons.
2021-12-15 17:30:17 +01:00
Luigi Teschio 13deb1b09e Mini Cart Block: render the empty state set on template parts (https://github.com/woocommerce/woocommerce-blocks/pull/5338)
* add view switcher for mini cart contents block

* editor view switcher

* update mini cart template file

* render the empty state template parts for the Mini Cart Block woocommerce/woocommerce-blocks#4674

render the empty state template parts for the Mini Cart Block woocommerce/woocommerce-blocks#4674

* update selector

* allow empty mini cart block to add all blocks

* fix tests; improve code style

* install @wordpress/block-editor package

* fix warning on frontend side

* block-editor package is not necessary

* merge attributes object

Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2021-12-10 12:11:59 +01:00
Mike Jolley 5c08c75612 Update Checkout to Checkout i2 (https://github.com/woocommerce/woocommerce-blocks/pull/4745)
* Remove i2 from build

* Remove i2 php registration

* Rename old checkout dir

* Rename i2 dir

* Migrate i1 to i2 code

* Register block metadata to fix frontend rendering when migrating to i2

* Register in correct order

* Missing styles

* add register-components to side effectful list

* wrong block class in e2e test

* wp prefix missing on selector

* Fix top level block test

* Reselect labels to work around rerendering

* missing empty cart styles

* Consolodate duplicate styles

* remove init code

* update selectBlockByName

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
2021-09-16 13:16:21 +01:00
Mike Jolley c891beab82 Update checkout block registration API to consume Block Metadata (https://github.com/woocommerce/woocommerce-blocks/pull/4684)
* Update registry to register components with block JSON metadata

* Use updated registration API in sample block

* remove editorScript

* Rename area and allow forced blocks to do it's thing without defining a template manually

* More naming consistency

* Validate a registered checkout block has at least one valid parent
2021-09-07 17:01:14 +01:00
Mike Jolley dc18112911 Google Analytics Integration - Action Hooks and initial tracking events (https://github.com/woocommerce/woocommerce-blocks/pull/3953)
* Remove item and change quantity doAction hooks

* Cart event

* Event/Action system for cart events

* GA implementation

* Revert some unrelated commits

* revert change

* Listing impression config for all products

* Category support

* remove unrelated change

* Remove listype and block import

* wrap action in try catch

* Tidy

* Only load analytics scripts in experimental builds

* Made console log more specific

* Wrap script reg in experimental check
2021-03-16 11:40:22 +00:00
Mike Jolley 86328758bb Add billing data to payment method registration, convert cart/checkout context provider to typescript (https://github.com/woocommerce/woocommerce-blocks/pull/3922)
* Add billingData within usePaymentMethodRegistration

* Add typescript config

* Rename to TS

* Typing in context

* FIxed TS warnings

* Typed event emitters

* subscribers > observers

* Renaming some types

* Remove duplicate definition in tsconfig

* removed undefined check
2021-03-09 10:50:51 +00:00
Albert Juhé Lluveras 0e1b1e3579 Add types to packages directory (https://github.com/woocommerce/woocommerce-blocks/pull/3914)
* Add Typescript to Panel and Icon

* Fix Icon component import

* Convert packages/checkout/utils/validation/index to TypeScript

* Convert checkout registry to TypeScript

* Add return type to mustContain

* Add TypeScript to Totals components from @woocommerce/blocks-checkout

* Add TypeScript to @woocommerce/price-format

* Use types from @woocommerce/type-defs when possible

* Allow empty objects when loading

* Fix formatting in payment-method-data-context.js

* Add missing return types

* Fix up price warnings

* Fix more warnings in FormattedMonetaryAmount

Co-authored-by: Raluca Stan <ralucastn@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Mike Jolley <mike.jolley@me.com>
2021-03-05 14:03:48 +00:00
Thomas Roberts e49a7eaffd Update Label component to TSX (https://github.com/woocommerce/woocommerce-blocks/pull/3889)
* Add tsconfig to components directory and include it as project

* Add @types/classnames package

* Migrate Label component to TSX

* Remove unused imports from Label component

* fix package-lock.json

It was generated with npm 7 and we don’t support that yet (and that update should be done in a separate pull)

* Add interface for LabelProps and implement.

Also:
- import `Fragment` from @wordpress/element.
- import `HTMLAttributes` explicitly as a type from react (@types/wordpress__element doesn’t export this interface).

* fix jest configuration

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
2021-02-26 11:57:49 +00:00
Darren Ethier af99c16931 Add TypeScript support and convert cart data store to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/3768)
* add typescript support

* Add type declarations for Cart and CartResponse interfaces

* make sure we’re resolving .ts files as well as .js files on imports

* add more types

* type the cart data store

* Apply suggestions from code review (implement .tsx in configs)

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>

* remove global fetchMock declaration and directly import where used.

* rename type

* remove named action types and just infer by returning action creator values as const

* use interface instead of type

* rename

* renames

* create CartAction type as union of action creator returned types and implement in reducer

* remove unused imports

* refresh package-lock after rebase

* Add base TS config that projects will inherit from

* Add tsconfig for assets/js/data project

* Ignore TS error on cart store registration

We will address this in cooldown when we have time to investigate further

* Add tsc to build step to catch TypeScript errors

* add a separate command for tsc and tweak build command to use

* restore checkJs and allowJs values in config and remove ts check from build command

* Add ts:check-all command

* Add TypeScript checking workflows

* Change triggers for TypeScript workflow

* Use npm ci instead of npm install

* Remove ts:check-all from TypeScript workflow

* Remove TS Check GitHub workflow

* Remove type-defs dir from TS include, and remove ts:check-all script

We no longer need the ts:check-all script because ts:check will do this for us, the old ts:check did nothing and did not work.

* fix coupon loading issues

* include .ts files only from type-defs folder

Co-authored-by: Jon Surrell <jon.surrell@automattic.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2021-02-23 20:36:24 -05:00
Seghir Nadir 99b78a1c9a add price package (https://github.com/woocommerce/woocommerce-blocks/pull/3790) 2021-02-04 15:30:28 +00:00
Albert Juhé Lluveras b4a37aebd6 Create @woocommerce/checkout to export components to a global (https://github.com/woocommerce/woocommerce-blocks/pull/3654)
* add plugin area

* add invisible errorBoundary

* introduce slot

* change name to OrderMeta

* fix rebase

* wip

* create checkout file

* Import ExperimentalOrderMeta from @woocommerce/checkout

* Rename wc-checkout-packages handle to wc-blocks-checkout

* Only import wc-blocks-checkout in the feature plugin

* Move checkout package to packages folder

* Add @woocommerce/blocks-checkout to tsconfig

* Move TotalsItem to @woocommerce/checkout

* Use Fragment short syntax

* Remove example code

* Honor renderError prop in BlockErrorBoundary

* Rename error boundary

* Add example code

This reverts commit 9b6af7178cbef05589779ef7f5a750d53e7fc8cf.

* Revert "Add example code"

This reverts commit 2f50349692f53c5bb143516365eee7a98d580dfd.

* Add @woocommerce/blocks-checkout to jest config

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2021-01-07 13:02:21 +01:00
Albert Juhé Lluveras 02174c5431 Add stories to Cart & Checkout totals components (https://github.com/woocommerce/woocommerce-blocks/pull/3533)
* Add stories to Cart & Checkout totals components

* Create @woocommerce/knobs alias

* Update TotalsFooterItem default values so they are in line with other stories
2020-12-14 09:15:50 +01:00
Darren Ethier 69ba8161b6 Add @woocommerce/eslint-plugin dependency (https://github.com/woocommerce/woocommerce-blocks/pull/3115)
* convert eslint config to use @woocommerce/eslint-plugin

- removes unnecessary dependencies
- adds e2e-tests/specs to eslint ignore (they are automatically generated)
- turns off rules that will be handled in subsequent pulls (to avoid a mammoth changeset for review).
- NOTE: prettier config needs left in because of a bug with the existing version of `@wordpress/eslint-plugin` pulled in (fixed in https://github.com/WordPress/gutenberg/pull/25068) so I left the file for now.

* prettier fixes.

* remove obsolete plugin and fixes for eslint update

This branch brings an update to eslint which also changes some syntax with plugins. So this commit:

- fixes featuer-flag plugin syntax.
- removed obsolete dependency-group plugin (which is now in the `@woocommerce/eslint-plugin` configuration.

* add to-do comment

* fixes for test runs

- this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run.

* fixes for test runs

- this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run.

* include prettier alias as a dependency

This has to be done because prettier is installed with storybook and thus the alias setup in `@wordpress/scripts` is over-ridden by the storybook import.

* another attempt at e2e-test-fix

* add some debugging and temporarily just add one e2e config test for travis

* more debugging

* try installing full puppeteer and see if fixes

* fix package-lock?

* setupSettings separately from other fixture loading

* add debugging of files

* add another console.log (hopefully trigger travis)

* split out blockPage creation to it’s own as well

* fixed! remove debugging and re-enable travis configs for entire test suite

* fix config and rename e2e-tests to e2e

- fixes the failing product-search test
- tests/e2e-tests was redundant, I changed to `tests/e2e` (this follows a file pattern change made in woocommerce core as well).

* add todo for some eslint properties

* remove unnecessary early function execution

* revert earlier commit and remove duplicate call to createBlockPages
2020-09-07 13:31:10 -04:00
Rua Haszard 5c7447f434 Rename js/components to js/editor-components (https://github.com/woocommerce/woocommerce-blocks/pull/3069)
* mass-rename js/components => js/editor-components & update webpack

* mass-change import '@woocommerce/editor-components' +
+ jsprettier quotes fix

* more mass-rename @woocommerce/editor-components

* fix up references to js/editor-components in various places:
- docs/readmes
- jest config
- typescritp config

* fix story path to match new folder/alias 'editor-components'

* fix jest tests: use new alias for editor-components

* include renamed `editor-components` in editor stylesheet cache group
2020-09-02 10:21:46 +02:00
Mike Jolley 09aa20d0d3 Introduce Atomic Add to Cart Block (https://github.com/woocommerce/woocommerce-blocks/pull/2705)
* Form/button stucture

* Use registerBlockComponent

* Context for add to cart form

* Working cart button

* Tidy up button component

* Add todos

* Revert reg block

* Hide stock indicator if not purchasable

* Hide terms if empty

* Add url and type to API

* Skip default category from term response

* Rename form element

* Form for product types

* Tidy up context provider and expand todos

* No longer using qty icon

* Update todos

* Correct text domain

* registerExperimentalBlockType

* Duplicate method

* Remove prevent default

* Update docblock

* Description for button code
2020-06-17 10:52:03 +01:00
Darren Ethier 41ca430ffe Add initial cart flow tests (https://github.com/woocommerce/woocommerce-blocks/pull/2678)
* more setup configuration for rtl

* move default state for cart out of reducer

This also creates a file for default store states, it should make it easier to execute tests in various environments.

* Make sure there’s a default object for cart line item row

* set defaults for cartData

* add fetchMock as a global in eslint config

* add initial cart flow tests

This is just to get the ball rolling, the cart block needs more tests

* fix missing @wordpress/jest-console configs (because I overwrote the original configuration)

* update test because of change in branch

* switch import order

* add globals.d.ts file to declare globals we use.

This is a quick solution to prevent typescript linting warning about `fetchMock`. At some point we could also create a proper interface for it or import the types (if they exist) for the `jest-mock` package.

The new `globals.d.ts` file is excluded from published builds.
2020-06-10 14:21:34 -04:00
Mike Jolley a5b09b7a43 Update atomic block structure (https://github.com/woocommerce/woocommerce-blocks/pull/2587)
* Move components to blocks dir

* Update import

* Create edit.js for each block

* Remove components/fix title

* Update imports

* Pass corect attributes on edit

* Import

* remove lightBlockWrapper
2020-05-29 14:49:56 +01:00
Mike Jolley 18480b0d68 Add layour editor to the single product block (https://github.com/woocommerce/woocommerce-blocks/pull/2586) 2020-05-29 12:28:04 +01:00
Mike Jolley 95809b30bb Update payment method config to include icons (https://github.com/woocommerce/woocommerce-blocks/pull/2267)
* Remove strong and cleanup existing configs

* Fix TS validation for blocks-registry

* Allow label to be string

* Split up button and icons for cart

* Make icons and payment methods available on cart page

* Fix payment method enqueuing

* Icon normalization and Stripe implementation

* PayPal Icon

* adjust spacing

* Fix string handling

* Remove paypal icon config

* Check for an object before creating icon

* Add payment icons to Stripe label

* Update common-icons.js

* Update Cart.php

* Update jest.config.json
2020-04-29 11:57:58 +01:00
Darren Ethier 2aa2093dfb Add contexts for checkout (https://github.com/woocommerce/woocommerce-blocks/pull/1915)
- restructures `@woocommerce/base-context` imports so it pulls from `index.js` in the `base/context` folder. That way tree-shaking will be used if possible. This also helps with organizing the folder structure a bit better for the new contexts.
- Fixes all the various imports through the code due to the above change.
- Adds `CheckoutContextProvider`, `useCheckoutContext` and related files.
- Adds `PaymentMethodDataProvider`, `usePaymentMethodDataContext` and related files.
- Adds `ShippingMethodDataProvider`, `useShippingMethodDataContext` and related files.
- Adds typedefs used for the various context interfaces.
2020-03-10 09:39:21 -04:00
Mike Jolley dd54ce1136 Checkout form options to control field visibility (https://github.com/woocommerce/woocommerce-blocks/pull/1868)
* Fix background overlap of feedback box

* TS notices

* Add company name toggle

* Implement new attributes and toggles in editor

* Handle field config in address component

* Remove other hoc rule from tsconfig

* map -> forEach

* Remove return from forEach

* Export and extend field config

* Fix optional text for all field types

* unit text

* Update snapshot
2020-03-05 13:06:47 +00:00
Darren Ethier 83d82f3061 Add missing alias for tsconfig and re-order alphabetically (https://github.com/woocommerce/woocommerce-blocks/pull/1800)
* add missing alias and re-order alphabetically

* Fix incorrect alias configuration
2020-02-24 10:50:16 -05:00
Darren Ethier f8d6735baf Create typedefs and add basic typescript configuration (https://github.com/woocommerce/woocommerce-blocks/pull/1796)
* install typescript and add typedef support

* add typedefs for Cart things

* improve typescript config

- adds more base config
- add our aliases

* fix error caught by typescript!

* Tweak typescript configuration

* Add missing `@woocommerce/settings` alias to ts config

* Add alias for type-defs
2020-02-24 07:52:24 -05:00