woocommerce/plugins/woocommerce-blocks/assets/js/blocks/classic-template/index.tsx

475 lines
12 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import {
BlockInstance,
createBlock,
getBlockType,
registerBlockType,
unregisterBlockType,
parse,
} from '@wordpress/blocks';
import type { BlockEditProps } from '@wordpress/blocks';
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';
import {
useBlockProps,
BlockPreview,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { Button, Placeholder, Popover } from '@wordpress/components';
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
import { __ } from '@wordpress/i18n';
import { box, Icon } from '@wordpress/icons';
import {
useDispatch,
subscribe,
useSelect,
select,
dispatch,
} from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { useEntityRecord } from '@wordpress/core-data';
import { debounce } from '@woocommerce/base-utils';
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
import { woo } from '@woocommerce/icons';
import { isNumber } from '@woocommerce/types';
/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
import { BLOCK_SLUG, TEMPLATES, TYPES } from './constants';
import {
isClassicTemplateBlockRegisteredWithAnotherTitle,
hasTemplateSupportForClassicTemplateBlock,
getTemplateDetailsBySlug,
} from './utils';
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
import {
blockifiedProductCatalogConfig,
blockifiedProductTaxonomyConfig,
} from './archive-product';
import * as blockifiedSingleProduct from './single-product';
import * as blockifiedProductSearchResults from './product-search-results';
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
import * as blockifiedOrderConfirmation from './order-confirmation';
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
import type { BlockifiedTemplateConfig } from './types';
type Attributes = {
template: string;
align: string;
};
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
const blockifiedFallbackConfig = {
isConversionPossible: () => false,
getBlockifiedTemplate: () => [],
getDescription: () => '',
onClickCallback: () => void 0,
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
};
const conversionConfig: { [ key: string ]: BlockifiedTemplateConfig } = {
[ TYPES.productCatalog ]: blockifiedProductCatalogConfig,
[ TYPES.productTaxonomy ]: blockifiedProductTaxonomyConfig,
[ TYPES.singleProduct ]: blockifiedSingleProduct,
[ TYPES.productSearchResults ]: blockifiedProductSearchResults,
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
[ TYPES.orderConfirmation ]: blockifiedOrderConfirmation,
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
fallback: blockifiedFallbackConfig,
};
const pickBlockClientIds = ( blocks: Array< BlockInstance > ) =>
blocks.reduce< Array< string > >( ( acc, block ) => {
if ( block.name === 'core/template-part' ) {
return acc;
}
return [ ...acc, block.clientId ];
}, [] );
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
const ConvertTemplate = ( { blockifyConfig, clientId, attributes } ) => {
const { getButtonLabel, onClickCallback, getBlockifiedTemplate } =
blockifyConfig;
const [ isPopoverOpen, setIsPopoverOpen ] = useState( false );
const { replaceBlock, selectBlock, replaceBlocks } =
useDispatch( blockEditorStore );
const { getBlocks } = useSelect( ( sel ) => {
return {
getBlocks: sel( blockEditorStore ).getBlocks,
};
}, [] );
const { createInfoNotice } = useDispatch( noticesStore );
return (
<div className="wp-block-woocommerce-classic-template__placeholder-migration-button-container">
<Button
isPrimary
onClick={ () => {
onClickCallback( {
clientId,
getBlocks,
attributes,
replaceBlock,
selectBlock,
} );
createInfoNotice(
__(
'Template transformed into blocks!',
'woo-gutenberg-products-block'
),
{
actions: [
{
label: __(
'Undo',
'woo-gutenberg-products-block'
),
onClick: () => {
const clientIds = pickBlockClientIds(
getBlocks()
);
replaceBlocks(
clientIds,
createBlock(
'core/group',
{
layout: {
inherit: true,
type: 'constrained',
},
},
[
createBlock(
'woocommerce/legacy-template',
{
template:
attributes.template,
}
),
]
)
);
},
},
],
type: 'snackbar',
}
);
} }
onMouseEnter={ () => setIsPopoverOpen( true ) }
onMouseLeave={ () => setIsPopoverOpen( false ) }
text={ getButtonLabel ? getButtonLabel() : '' }
>
{ isPopoverOpen && (
<Popover resize={ false } placement="right-end">
<div
style={ {
minWidth: '250px',
width: '250px',
maxWidth: '250px',
minHeight: '300px',
height: '300px',
maxHeight: '300px',
cursor: 'pointer',
} }
>
<BlockPreview
blocks={ getBlockifiedTemplate( attributes ) }
viewportWidth={ 1200 }
additionalStyles={ [
{
css: 'body { padding: 20px !important; height: fit-content !important; overflow:hidden}',
},
] }
/>
</div>
</Popover>
) }
</Button>
</div>
);
};
const Edit = ( {
clientId,
attributes,
setAttributes,
}: BlockEditProps< Attributes > ) => {
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
const blockProps = useBlockProps();
const { editedPostId } = useSelect( ( sel ) => {
return {
editedPostId: sel( 'core/edit-site' ).getEditedPostId(),
};
}, [] );
const template = useEntityRecord< {
slug: string;
title: {
rendered?: string;
row: string;
};
} >( 'postType', 'wp_template', editedPostId );
const templateDetails = getTemplateDetailsBySlug(
attributes.template,
TEMPLATES
);
const templateTitle =
template.record?.title.rendered?.toLowerCase() ?? attributes.template;
const templatePlaceholder = templateDetails?.placeholder ?? 'fallback';
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
const templateType = templateDetails?.type ?? 'fallback';
useEffect(
() =>
setAttributes( {
template: attributes.template,
align: attributes.align ?? 'wide',
} ),
[ attributes.align, attributes.template, setAttributes ]
);
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
const {
isConversionPossible,
getDescription,
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
getSkeleton,
blockifyConfig,
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
} = conversionConfig[ templateType ];
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
const skeleton = getSkeleton ? (
getSkeleton()
) : (
<img
className="wp-block-woocommerce-classic-template__placeholder-image"
src={ `${ WC_BLOCKS_IMAGE_URL }template-placeholders/${ templatePlaceholder }.svg` }
alt={ templateTitle }
/>
);
const canConvert = isConversionPossible();
[Blockifying Product Archive Templates]: Implement the blockified template conversion for the Classic Template Block. (https://github.com/woocommerce/woocommerce-blocks/pull/8248) * Extract a blockified Product Archive Template to the templates * Add templates to tsconfig.json so the files are resolved as part of the core code * Add a encouragement note to use blockified version IF migration is available * Add a Row block wrapping Product Results Count and Catalog Sorting blocks * Move blockified product-archive from templates/ to assets/ directory * Remove unnecessary margin from Product Results Count block When used in a Row block in a blockified Archive Product template, Product Results Count had additional unnecessary margin which caused misalignment with the Catalog Sorting block * Update the description of the Classic Template Editor placeholder * Remove unnecessary entry in tsconfig.json to include templates directory It was added couple of commits earlier, since the template was kept there, but it was decided to move it to assets directory, so entry is no longer necessary * Differentiate the Classic Template placeholder description depending on the availability to convert to Products block * Set margin for Catalog Sorting to 0, so it aligns properly when used in blockified Archive Product template * Make the blockification config, so it covers the Product Archive as well as Single Product templates * Move the product-archive specific functions from classic-template/index.tsx to the product-archive.ts * Add alignment option to the Store Notices block and make the blockified template blocks aligned wide That is required, so the Classic Template layout is preserved * Create single-product.ts file which is a placeholder for the blockified Single Product template * Make Blockified Product Archive template inherit the align attibute * Simplify the interface of blockified templates Expose function instead of two functions for allowing and disallowing conversion * Add a BlockifiedTemplate type * Rename and simplify the function checking if conversion of classic template to block version is possible * Align the variable naming to use instead of * Pass the Classic Template attributes to the blockified template instead of getting it from data store * Include Breadcrumbs block in the Blockified Product Archive Template * Consume alignment attributes of Catalog Sorting in the PHP render function * Consume alignment attributes of Breadcrumbs in the PHP render function * Remove align support from Catalog Sorting and add to Store Notices block * Extend the get_classes_and_styles_by_attributes method with align and text_align attributes * Add Archive Title block to the Blockified Classic Template * Minor getRowBlock function refactor * Add property to the classic templates and base the config on it instead of placeholder * Add separate blockified template for a Product Search Results * Pass attribute from classic template to No Results block in Product Search Results * Extract the common functions between blockified archive-template and product-search-results to utils * Enable 'Inherit query from template' in Products block by default when converting the Classic Template to blockified one * Improve the naming of BlockifiedTemplateConfig type * Differentiate Product Catalog and Products By * templates. The latter include Term Description block * Change unclear ProductsBy to ProductTaxonomy in regards to classic template conversion * Revert the margin fix which was added already on trunk * Move the surrounding blocks as inner blocks of Products * Hide the conversion behind the experimental build flag (as it was before)
2023-02-27 14:34:18 +00:00
const placeholderDescription = getDescription( templateTitle, canConvert );
return (
<div { ...blockProps }>
<Placeholder className="wp-block-woocommerce-classic-template__placeholder">
<div className="wp-block-woocommerce-classic-template__placeholder-wireframe">
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
{ skeleton }
</div>
<div className="wp-block-woocommerce-classic-template__placeholder-copy">
<div className="wp-block-woocommerce-classic-template__placeholder-copy__icon-container">
<span className="woo-icon">
<Icon icon={ woo } />{ ' ' }
{ __(
'WooCommerce',
'woo-gutenberg-products-block'
) }
</span>
<span>
{ __(
'Classic Template Placeholder',
'woo-gutenberg-products-block'
) }
</span>
</div>
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
<p
dangerouslySetInnerHTML={ {
__html: placeholderDescription,
} }
/>
Add Cart/Checkout/Order-Received Templates (https://github.com/woocommerce/woocommerce-blocks/pull/9301) * WIP: dirty attempt to dry run Cart & Checkout templates * Added Cart and Checkout to the template hierarchies * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Updated cart & Checkout templates * Order Received FSE template (https://github.com/woocommerce/woocommerce-blocks/pull/8937) * Order Received template bootstrap * typo * WIP: new block * add logic here * Order received classic template * reverted constants.ts * Added the post title (buggy) * Corrected page title * Updated constants.ts * Fixed template typo * removed placeholder for order received block * add order-received template description * updated placeholder description * Formatting fixes * Template description. * replaced hardcoded string with OrderReceivedTemplate::SLUG --------- Co-authored-by: Luigi <gigitux@gmail.com> * Code formatting (https://github.com/woocommerce/woocommerce-blocks/pull/8350) * Code formatting * page_template_hierarchy priority to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/9323) Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate Cart and Checkout Pages to the Template Editor when using a FSE theme (https://github.com/woocommerce/woocommerce-blocks/pull/9339) * Introduce woocommerce_blocks_template_content hook * Migrate cart and checkout page content to the template editor * Add redirection from edit page to edit template --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Removed header and footer from checkout template. (https://github.com/woocommerce/woocommerce-blocks/pull/9378) * Removed header and footer from checkout template. * Removed header and footer from checkout template migration * Permalink solution for the checkout endpoint/template (https://github.com/woocommerce/woocommerce-blocks/pull/9406) * Checkout endpoint work * Move setting field to util * Include link to edit the template * Remove todo * Refactor checkout templates to share logic (https://github.com/woocommerce/woocommerce-blocks/pull/9411) * Sync endpoints with pages (https://github.com/woocommerce/woocommerce-blocks/pull/9426) * Switch to page syncing * Update settings descriptions --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Migrate pages to templates once (https://github.com/woocommerce/woocommerce-blocks/pull/9488) * Migrate content on init, once * Skip migration if page does not exist * Put back HTML for header and footer parts * Fix page redirect due to wrong ID * fix loading template part * Removed unnecessary var * update cart and checkout html templates --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Include a notice to redirect user to template editor (https://github.com/woocommerce/woocommerce-blocks/pull/9508) * Template Placeholder Design for the Order Received Template (https://github.com/woocommerce/woocommerce-blocks/pull/9602) * Load frontend styles in editor iframe * Update placeholder to include skeleton and updated icons * Update classic template configs * 1px border for .wp-block-woocommerce-classic-template__placeholder-copy * Show copy on focus * Sample data --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Add simplified header on checkout template (https://github.com/woocommerce/woocommerce-blocks/pull/9607) * Added simplified header on checkout template * Moved simplified header to template part * updated constants.ts * added template part to checkout.html * Add missing translation * frontpage_template_hierarchy no longer needed * Allow plugin based template parts (https://github.com/woocommerce/woocommerce-blocks/pull/9667) * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Synced templates on blockified folder * Add blockified order-received.html * removed WooCommerce prefix * Refactor/rebrand order received template to order confirmation (https://github.com/woocommerce/woocommerce-blocks/pull/9734) * rebrand order received to order confirmation * updated descriptions for templates * updated descriptions for order confirmation placeholder * Resolve merge conflict * Resolve merge conflicts * Resolve more merge conflicts after rebase * Fix formatting * Use patterns for localisation (https://github.com/woocommerce/woocommerce-blocks/pull/9883) * e2e tests for cart and checkout templates (https://github.com/woocommerce/woocommerce-blocks/pull/9939) * Merge branch 'trunk' into poc/cart_and_checkout_fse_templates * Merge branch 'trunk' into add/9288_cart-checkout-order-received_fse_templates * Resolve merge conflicts * Add e2e for permalink settings * Test that templates exist * Add test to check that templates can be edited * Add tests to confirm templates can be edited * Ensure cart has contents before running tests on frontend views * Commend out problem test * Make sure search has multiple results * Remove useThrottle - bad rebase * Revert changes to docs after rebase * Revert function call for noReviewsPlaceholder * Bad rebase * Reverts * Remove revertTemplate * Spacing * Wait for networkidle after navigation * Always wait for network * Use button roles in site editor * More specific button locator * Update option comparison * Fix template content * Disable failing tests * Disable failing classic template tests * Use enterEditMode * More enterEditMode usage * enterEditMode * Use test.skip * More robust selectors * Alt iframe selector --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> * Skip flakey test --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Mike Jolley <mike.jolley@me.com>
2023-06-29 13:41:22 +00:00
<p>
{ __(
'You cannot edit the content of this block. However, you can move it and place other blocks around it.',
'woo-gutenberg-products-block'
) }
</p>
{ canConvert && blockifyConfig && (
<ConvertTemplate
clientId={ clientId }
blockifyConfig={ blockifyConfig }
attributes={ attributes }
/>
) }
</div>
</Placeholder>
</div>
);
};
const registerClassicTemplateBlock = ( {
template,
inserter,
}: {
template?: string;
inserter: boolean;
} ) => {
/**
* The 'WooCommerce Legacy Template' block was renamed to 'WooCommerce Classic Template', however, the internal block
* name 'woocommerce/legacy-template' needs to remain the same. Otherwise, it would result in a corrupt block when
* loaded for users who have customized templates using the legacy-template (since the internal block name is
* stored in the database).
*
* See https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5861 for more context
*/
registerBlockType( BLOCK_SLUG, {
title:
template && TEMPLATES[ template ]
? TEMPLATES[ template ].title
: __(
'WooCommerce Classic Template',
'woo-gutenberg-products-block'
),
icon: (
<Icon
icon={ box }
className="wc-block-editor-components-block-icon"
/>
),
category: 'woocommerce',
apiVersion: 2,
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
description: __(
'Renders classic WooCommerce PHP templates.',
'woo-gutenberg-products-block'
),
supports: {
align: [ 'wide', 'full' ],
html: false,
multiple: false,
reusable: false,
inserter,
},
attributes: {
/**
* Template attribute is used to determine which core PHP template gets rendered.
*/
template: {
type: 'string',
default: 'any',
},
align: {
type: 'string',
default: 'wide',
},
},
edit: ( {
attributes,
clientId,
setAttributes,
}: BlockEditProps< Attributes > ) => {
const newTemplate = template ?? attributes.template;
return (
<Edit
attributes={ {
...attributes,
template: newTemplate,
} }
setAttributes={ setAttributes }
clientId={ clientId }
/>
);
},
save: () => null,
} );
};
/**
* Attempts to recover the Classic Template block if it fails to render on the Single Product template
* due to the user resetting customizations without refreshing the page.
*
* When the Classic Template block fails to render, it is replaced by the 'core/missing' block, which
* displays an error message stating that the WooCommerce Classic template block is unsupported.
*
* This function replaces the 'core/missing' block with the original Classic Template block that failed
* to render, allowing the block to be displayed correctly.
*
* @see {@link https://github.com/woocommerce/woocommerce-blocks/issues/9637|Issue: Block error is displayed on clearing customizations for Woo Templates}
*
*/
const tryToRecoverClassicTemplateBlockWhenItFailsToRender = debounce( () => {
const blocks = select( 'core/block-editor' ).getBlocks();
const blocksIncludingInnerBlocks = blocks.flatMap( ( block ) => [
block,
...block.innerBlocks,
] );
const classicTemplateThatFailedToRender = blocksIncludingInnerBlocks.find(
( block ) =>
block.name === 'core/missing' &&
block.attributes.originalName === BLOCK_SLUG
);
if ( classicTemplateThatFailedToRender ) {
const blockToReplaceClassicTemplateBlockThatFailedToRender = parse(
classicTemplateThatFailedToRender.attributes.originalContent
);
if ( blockToReplaceClassicTemplateBlockThatFailedToRender ) {
dispatch( 'core/block-editor' ).replaceBlock(
classicTemplateThatFailedToRender.clientId,
blockToReplaceClassicTemplateBlockThatFailedToRender
);
}
}
}, 100 );
// @todo Refactor when there will be possible to show a block according on a template/post with a Gutenberg API. https://github.com/WordPress/gutenberg/pull/41718
let currentTemplateId: string | undefined;
subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
// With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230
const editedPostId = store?.getEditedPostId() as
| string
| number
| undefined;
currentTemplateId = isNumber( editedPostId ) ? undefined : editedPostId;
const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];
if ( parsedTemplate === null || parsedTemplate === undefined ) {
return;
}
const block = getBlockType( BLOCK_SLUG );
const isBlockRegistered = Boolean( block );
if (
isBlockRegistered &&
hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES )
) {
tryToRecoverClassicTemplateBlockWhenItFailsToRender();
}
if ( previousTemplateId === currentTemplateId ) {
return;
}
if (
isBlockRegistered &&
( ! hasTemplateSupportForClassicTemplateBlock(
parsedTemplate,
TEMPLATES
) ||
isClassicTemplateBlockRegisteredWithAnotherTitle(
block,
parsedTemplate
) )
) {
unregisterBlockType( BLOCK_SLUG );
currentTemplateId = undefined;
return;
}
if (
! isBlockRegistered &&
hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES )
) {
registerClassicTemplateBlock( {
template: parsedTemplate,
inserter: true,
} );
}
}, 'core/blocks-editor' );