woocommerce/plugins/woocommerce-blocks/assets/js/blocks
Tarun Vijwani 4de3bdb0f1 Convert validation context to data store (https://github.com/woocommerce/woocommerce-blocks/pull/6402)
* Add validation reducers, actions, and action types

* Add selector for getValidationErrors

* Export store key and register store

* Export validation store key

* Move TextInput files to checkout package

* Export ValidatedTextInput from blocks-checkout package

* Update imports of ValidatedTextInput to reflect new location

* Use the validation wp-data store for showing error messages

* Export getValidationError in checkout package

* Move validation store to checkout package

* Move ValidationInputError to blocks-checkout package

* Only export "exposedSelectors" from validation

* Convert validation context to data store

* Fixed linting error

* Fixed linting error

* Change the validation selectors to return a function

* Convert reducer and selectors to TS

* Remove superfluous comments and improve test titles

* Test to ensure visible errors remain visible

* Make test for hasValidationErrors more robust

* Augment the wp-data module to include our selectors and actions

* Removed unused `exposedSelectors` variable

* Remove TS error because of `instanceId` on props

* Remove unnecessary as const

* Use function returned by getValidationError

* Use correct selector/action names now context has been decoupled

* hide validation error when input value changes

* Add correct aria-describedBy now we can get error id from store

* Clear validation error from store when component unmounts

* Clear validation error if input is valid

* convert ValidationInputError to TS and get correct id/error from store

* Ensure checkout block doesn't break when there are no errors

* Get validation data from the store instead of context

* Update country input to remove validation context

* Move validation store out of checkout package

* Move TextInput and ValidationInputError back out of the checkout package

* Remove duplicate internal styles comment

* Remove exports that no longer exist

* Get validation store key from block-data

* Make attribute-select-control use validation data store

* Export FieldValidationStatus type

* Make combobox use validation store not context

* Make Address use validation store not context

* Make Address use validation store not context

* Use hasValidationErrors selector as a function in shipping calculator

* Remove validation context from coupon story

* Import VALIDATION_STORE_KEY from correct location

* Stop coupon story from erroring

* Update useStoreCartCoupons to use validation store not context

* Make TotalsCoupon use validation store instead of context

* Make AddToCartFormContext use validation store not context

* Remove ValidationContext

* Import FieldValidationStatus from correct location

* Import ValidatedTextInput and ValidatedTextInput from correct location

* Remove ValidationContextProvider

* Update components to use validation store not context

* Update useValidation to use the data store

* Replace the validation context in checkout-events file

* Use the re-mapped path for the store key import

* Use "register" instead of the deprecated "registerStore"

* Fix import error of the "FieldValidationStatus" type

* Use TS instead of React's "PropTypes"

* Fix the type of "ValidationInputError" in the "payment-method-interface"

* Fix error not showing on the first place order click bug

We were mutating the state in the reducer, which prevented re-rendering
on state change

* Fix state mutation issue in the Validation reducer

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-09-28 13:45:42 +01:00
..
active-filters Fix not enough margin for Filter blocks woocommerce/woocommerce-blocks#7018 (https://github.com/woocommerce/woocommerce-blocks/pull/7226) 2022-09-27 12:48:06 +05:30
attribute-filter Fix not enough margin for Filter blocks woocommerce/woocommerce-blocks#7018 (https://github.com/woocommerce/woocommerce-blocks/pull/7226) 2022-09-27 12:48:06 +05:30
cart Convert validation context to data store (https://github.com/woocommerce/woocommerce-blocks/pull/6402) 2022-09-28 13:45:42 +01:00
cart-checkout-shared Fix lint issues 2022-09-28 13:45:42 +01:00
checkout Convert validation context to data store (https://github.com/woocommerce/woocommerce-blocks/pull/6402) 2022-09-28 13:45:42 +01:00
classic-template Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
featured-items Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
handpicked-products Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
mini-cart Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
price-filter Fix not enough margin for Filter blocks woocommerce/woocommerce-blocks#7018 (https://github.com/woocommerce/woocommerce-blocks/pull/7226) 2022-09-27 12:48:06 +05:30
product-best-sellers Set default orderby to popularity (https://github.com/woocommerce/woocommerce-blocks/pull/7025) 2022-08-31 12:38:48 +01:00
product-categories Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
product-category Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
product-new Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
product-on-sale Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
product-query Refactor Product Query to use the latest Gutenberg APIs (https://github.com/woocommerce/woocommerce-blocks/pull/7169) 2022-09-23 15:07:44 +02:00
product-search Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
product-tag Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
product-top-rated Remove custom `Icon` component in favour of `@wordpress/icons` where possible (https://github.com/woocommerce/woocommerce-blocks/pull/5599) 2022-02-01 16:54:38 +00:00
products Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
products-by-attribute Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566) 2022-06-15 11:56:52 +02:00
reviews Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045) 2022-09-12 10:39:26 +02:00
single-product Update @woocmmerce/eslint-plugin to 2.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/6203) 2022-04-08 14:47:19 +01:00
stock-filter Fix not enough margin for Filter blocks woocommerce/woocommerce-blocks#7018 (https://github.com/woocommerce/woocommerce-blocks/pull/7226) 2022-09-27 12:48:06 +05:30
README.md Format Markdown files using wp-scripts (https://github.com/woocommerce/woocommerce-blocks/pull/6462) 2022-06-09 14:43:17 +02:00

README.md

Blocks

Our blocks are generally made up of up to 4 files:

|- block.js
|- editor.scss
|- index.js
|- style.scss

The only required file is index.js, this sets up the block using registerBlockType. Each block has edit and save functions.

The scss files are split so that things in style are added to the editor and frontend, while styles in editor are only added to the editor. Most of our blocks should use core components that won't need CSS though.

Editing

A simple edit function can live in index.js, but most blocks are a little more complicated, so the edit function instead returns a Block component, which lives in block.js. By using a component, we can use React lifecycle methods to fetch data or save state.

The Newest Products block is a good example to read over, this is a simple block that fetches the products and renders them using the ProductPreview component.

We include settings in the sidebar, called the Inspector in gutenberg. See an example of this.

Other blocks have the concept of an "edit state", like when you need to pick a product in the Featured Product block, or pick a category in the Products by Category block.