woocommerce/plugins/woocommerce-blocks/assets/js/blocks/classic-template/archive-product.ts

166 lines
4.5 KiB
TypeScript
Raw Normal View History

[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
/**
* External dependencies
*/
import {
createBlock,
createBlocksFromInnerBlocksTemplate,
type BlockInstance,
} from '@wordpress/blocks';
import { isWpVersion } from '@woocommerce/settings';
import { isExperimentalBuild } from '@woocommerce/block-settings';
[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 { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import {
INNER_BLOCKS_TEMPLATE as productsInnerBlocksTemplate,
QUERY_DEFAULT_ATTRIBUTES as productsQueryDefaultAttributes,
} from '../product-query/constants';
import { VARIATION_NAME as productsVariationName } from '../product-query/variations/product-query';
import { createArchiveTitleBlock, createRowBlock } from './utils';
import { OnClickCallbackParameter, type InheritedAttributes } from './types';
[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 createProductsBlock = ( inheritedAttributes: InheritedAttributes ) =>
createBlock(
[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
'core/query',
{
...productsQueryDefaultAttributes,
...inheritedAttributes,
namespace: productsVariationName,
query: {
...productsQueryDefaultAttributes.query,
inherit: true,
},
},
createBlocksFromInnerBlocksTemplate( productsInnerBlocksTemplate )
[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 getBlockifiedTemplate = (
inheritedAttributes: InheritedAttributes,
withTermDescription = false
) =>
[
[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
createBlock( 'woocommerce/breadcrumbs', inheritedAttributes ),
createArchiveTitleBlock( 'archive-title', inheritedAttributes ),
withTermDescription
? createBlock( 'core/term-description', inheritedAttributes )
: null,
createBlock( 'woocommerce/store-notices', inheritedAttributes ),
createRowBlock(
[
createBlock( 'woocommerce/product-results-count' ),
createBlock( 'woocommerce/catalog-sorting' ),
],
inheritedAttributes
),
createProductsBlock( inheritedAttributes ),
[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
].filter( Boolean ) as BlockInstance[];
const getBlockifiedTemplateWithTermDescription = (
inheritedAttributes: InheritedAttributes
) => getBlockifiedTemplate( inheritedAttributes, true );
const isConversionPossible = () => {
// Blockification is possible for the WP version 6.1 and above,
// which are the versions the Products block supports.
return isExperimentalBuild() && isWpVersion( '6.1', '>=' );
[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 getDescriptionAllowingConversion = ( templateTitle: string ) =>
sprintf(
/* translators: %s is the template title */
__(
'Transform this template into multiple blocks so you can add, remove, reorder, and customize your %s template.',
[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
'woo-gutenberg-products-block'
),
templateTitle
);
const getDescriptionDisallowingConversion = ( templateTitle: string ) =>
sprintf(
/* translators: %s is the template title */
__(
'This block serves as a placeholder for your %s. It will display the actual product image, title, price in your store. You can move this placeholder around and add more blocks around to customize the template.',
'woo-gutenberg-products-block'
),
templateTitle
);
const getDescription = ( templateTitle: string, canConvert: boolean ) => {
if ( canConvert ) {
return getDescriptionAllowingConversion( templateTitle );
}
return getDescriptionDisallowingConversion( templateTitle );
};
const getButtonLabel = () =>
__( 'Transform into blocks', 'woo-gutenberg-products-block' );
const onClickCallback = ( {
clientId,
attributes,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes ) );
const blocks = getBlocks();
const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
block.innerBlocks.some(
( innerBlock ) =>
innerBlock.name === 'woocommerce/store-notices'
)
);
if ( groupBlock ) {
selectBlock( groupBlock.clientId );
}
};
const onClickCallbackWithTermDescription = ( {
clientId,
attributes,
getBlocks,
replaceBlock,
selectBlock,
}: OnClickCallbackParameter ) => {
replaceBlock( clientId, getBlockifiedTemplate( attributes, true ) );
const blocks = getBlocks();
const groupBlock = blocks.find(
( block ) =>
block.name === 'core/group' &&
block.innerBlocks.some(
( innerBlock ) =>
innerBlock.name === 'woocommerce/store-notices'
)
);
if ( groupBlock ) {
selectBlock( groupBlock.clientId );
}
};
[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
export const blockifiedProductCatalogConfig = {
getBlockifiedTemplate,
isConversionPossible,
getDescription,
getButtonLabel,
onClickCallback,
[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
};
export const blockifiedProductTaxonomyConfig = {
getBlockifiedTemplate: getBlockifiedTemplateWithTermDescription,
onClickCallback: onClickCallbackWithTermDescription,
[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
isConversionPossible,
getDescription,
getButtonLabel,
};