woocommerce/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-items-block/index.tsx

24 lines
445 B
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { Icon, column } from '@wordpress/icons';
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
*/
import { Edit, Save } from './edit';
Fix missing translations in inspector (https://github.com/woocommerce/woocommerce-blocks/pull/6737) * Try registering the "cart taxes" inner block Registering server side. This example isn't working, but I'm pushing to share it and see what's wrong with this implementation. * Fix registering the cart taxes inner block issue * Update translation script loading * Remove unnecessary JS translation The translation should work fine by getting the title & description from the `block.json` file * Put back the initial code in the 'Cart Taxes' inner block We didn't provide the correct `block.json` file path server side, that's why the `metadata` wasn't correctly registered * Generate `block.json`files for inner blocks This is the first step on fixing the missing translations of `metadata` in `block.json` files * Set the folder name exactly the same as the inner block name We are doing this first test for the `Cart taxes` inner block. The `Block` & its containing folder need to have the same name for: - Consistency - We use the `Block` name to get the file Path * Update imports after folder renaming * Get block name directly from the JSON metadata Getting the block name from the JSON metadata is less error prone than extracting it from the file path. And no need to rename all our `inner-blocks` to get the correct `block.json` path * Revert folder naming change of `Cart taxes` inner block Since we are getting the `block` name directly from the `block.json` metadata instead of extracting it from the file path, there is no need to keep their names in sync anymore * Fix missing translations for the `Cart Subtotal` Block * Register only the client-side settings on the client When the block is registered on the server, you only need to register the client-side settings on the client using the same block’s name. See [docs](https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#javascript-client-side). * Add schema validation to `block.json` Development is improved by using a defined schema definition file. Supported editors can provide help like tooltips, autocomplete, and schema validation. * Use the same `editor_script` as the parent block This prevents WordPress from generating script tags to inexistant inner blocks JS files * Add C&C inner blocks in Cart.php & Checkout.php This is a refactoring to keep the block types controller file less overloaded * Fix all Cart inner blocks missing translations * Create the "AbstractInnerBlock" class The "Inner Blocks" will use their parent's script, so no need to create new scripts for each one of them And, our "Inner Blocks" should always be registered using the metadata file * Update the "Inner Blocks" PHP classes * Fix PHP lint erros & update function description * Fix missing translations bug for all Checkout Inner Blocks * Update src/BlockTypes/Checkout.php Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com> * skip lazy loaded scripts Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2022-08-01 14:57:33 +00:00
registerFeaturePluginBlockType( 'woocommerce/cart-items-block', {
icon: {
src: (
<Icon
icon={ column }
className="wc-block-editor-components-block-icon"
/>
),
},
edit: Edit,
save: Save,
} );