Add manual path to upgrade Products block (https://github.com/woocommerce/woocommerce-blocks/pull/10268)
* Add option to manually update Products block to Product Collection * Disable manual upgrade of Products yet * Manual update flag doesn't have to be dependant on auto update * Removed commented out console info logs * Disable option to upgrade Products block * Change the way to bold text in Upgrade Notices so it's translatable * Change the way UpgradeNotice is rendered conditionally
This commit is contained in:
parent
c763f39cd4
commit
7018ff47b6
|
@ -4,34 +4,34 @@
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Notice, Button } from '@wordpress/components';
|
import { Notice, Button } from '@wordpress/components';
|
||||||
import { BlockEditProps } from '@wordpress/blocks';
|
import { BlockEditProps } from '@wordpress/blocks';
|
||||||
|
import { createInterpolateElement } from '@wordpress/element';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { ProductCollectionAttributes } from '../types';
|
import { ProductCollectionAttributes } from '../types';
|
||||||
|
|
||||||
const FormattedNotice = ( { notice }: { notice: string } ) => {
|
|
||||||
const strongText = 'Product Collection';
|
|
||||||
const [ before, after ] = notice.split( strongText );
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{ before }
|
|
||||||
<strong>{ strongText }</strong>
|
|
||||||
{ after }
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const UpgradeNotice = (
|
const UpgradeNotice = (
|
||||||
props: BlockEditProps< ProductCollectionAttributes > & {
|
props: BlockEditProps< ProductCollectionAttributes > & {
|
||||||
revertMigration: () => void;
|
revertMigration: () => void;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { displayUpgradeNotice } = props.attributes;
|
const { displayUpgradeNotice } = props.attributes;
|
||||||
const notice = __(
|
const notice = createInterpolateElement(
|
||||||
'Products (Beta) block was upgraded to Product Collection, an updated version with new features and simplified settings.',
|
__(
|
||||||
|
'Products (Beta) block was upgraded to <strongText />, an updated version with new features and simplified settings.',
|
||||||
'woo-gutenberg-products-block'
|
'woo-gutenberg-products-block'
|
||||||
|
),
|
||||||
|
{
|
||||||
|
strongText: (
|
||||||
|
<strong>
|
||||||
|
{ __(
|
||||||
|
`Product Collection`,
|
||||||
|
'woo-gutenberg-products-block'
|
||||||
|
) }
|
||||||
|
</strong>
|
||||||
|
),
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const buttonLabel = __(
|
const buttonLabel = __(
|
||||||
|
@ -53,7 +53,7 @@ const UpgradeNotice = (
|
||||||
|
|
||||||
return displayUpgradeNotice ? (
|
return displayUpgradeNotice ? (
|
||||||
<Notice onRemove={ handleRemove }>
|
<Notice onRemove={ handleRemove }>
|
||||||
<FormattedNotice notice={ notice } />
|
<>{ notice } </>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<Button variant="link" onClick={ handleClick }>
|
<Button variant="link" onClick={ handleClick }>
|
||||||
|
|
|
@ -13,7 +13,8 @@ import { VARIATION_NAME as PRODUCT_TITLE_ID } from './variations/elements/produc
|
||||||
import { VARIATION_NAME as PRODUCT_TEMPLATE_ID } from './variations/elements/product-template';
|
import { VARIATION_NAME as PRODUCT_TEMPLATE_ID } from './variations/elements/product-template';
|
||||||
import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
|
import { ImageSizing } from '../../atomic/blocks/product-elements/image/types';
|
||||||
|
|
||||||
export const REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
|
export const AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
|
||||||
|
export const MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
|
||||||
|
|
||||||
export const EDIT_ATTRIBUTES_URL =
|
export const EDIT_ATTRIBUTES_URL =
|
||||||
'/wp-admin/edit.php?post_type=product&page=product_attributes';
|
'/wp-admin/edit.php?post_type=product&page=product_attributes';
|
||||||
|
|
|
@ -38,11 +38,13 @@ import {
|
||||||
QUERY_DEFAULT_ATTRIBUTES,
|
QUERY_DEFAULT_ATTRIBUTES,
|
||||||
QUERY_LOOP_ID,
|
QUERY_LOOP_ID,
|
||||||
STOCK_STATUS_OPTIONS,
|
STOCK_STATUS_OPTIONS,
|
||||||
REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION,
|
AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION,
|
||||||
|
MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { AttributesFilter } from './inspector-controls/attributes-filter';
|
import { AttributesFilter } from './inspector-controls/attributes-filter';
|
||||||
import { PopularPresets } from './inspector-controls/popular-presets';
|
import { PopularPresets } from './inspector-controls/popular-presets';
|
||||||
import { ProductSelector } from './inspector-controls/product-selector';
|
import { ProductSelector } from './inspector-controls/product-selector';
|
||||||
|
import { UpgradeNotice } from './inspector-controls/upgrade-notice';
|
||||||
import { replaceProductsWithProductCollection } from '../shared/scripts';
|
import { replaceProductsWithProductCollection } from '../shared/scripts';
|
||||||
|
|
||||||
import './editor.scss';
|
import './editor.scss';
|
||||||
|
@ -221,6 +223,11 @@ const ProductQueryControls = ( props: ProductQueryBlock ) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<InspectorControls>
|
<InspectorControls>
|
||||||
|
{ MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION && (
|
||||||
|
<UpgradeNotice
|
||||||
|
upgradeBlock={ replaceProductsWithProductCollection }
|
||||||
|
/>
|
||||||
|
) }
|
||||||
{ allowedControls?.includes( 'presets' ) && (
|
{ allowedControls?.includes( 'presets' ) && (
|
||||||
<PopularPresets { ...props } />
|
<PopularPresets { ...props } />
|
||||||
) }
|
) }
|
||||||
|
@ -272,13 +279,9 @@ addFilter( 'editor.BlockEdit', QUERY_LOOP_ID, withProductQueryControls );
|
||||||
|
|
||||||
if ( isWpVersion( '6.1', '>=' ) ) {
|
if ( isWpVersion( '6.1', '>=' ) ) {
|
||||||
let unsubscribe: ( () => void ) | undefined;
|
let unsubscribe: ( () => void ) | undefined;
|
||||||
if ( REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION && ! unsubscribe ) {
|
if ( AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION && ! unsubscribe ) {
|
||||||
// console.info( 'Subscribed to allow Products block migration' );
|
|
||||||
unsubscribe = subscribe( () => {
|
unsubscribe = subscribe( () => {
|
||||||
replaceProductsWithProductCollection( () => {
|
replaceProductsWithProductCollection( () => {
|
||||||
// console.info(
|
|
||||||
// 'Unsubscribed and disallow further Products block migration'
|
|
||||||
// );
|
|
||||||
if ( unsubscribe ) {
|
if ( unsubscribe ) {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { Notice, Button } from '@wordpress/components';
|
||||||
|
import { createInterpolateElement } from '@wordpress/element';
|
||||||
|
|
||||||
|
export const UpgradeNotice = ( props: { upgradeBlock: () => void } ) => {
|
||||||
|
const notice = createInterpolateElement(
|
||||||
|
__(
|
||||||
|
'Upgrade all Products (Beta) blocks on this page to <strongText /> for more features!',
|
||||||
|
'woo-gutenberg-products-block'
|
||||||
|
),
|
||||||
|
{
|
||||||
|
strongText: (
|
||||||
|
<strong>
|
||||||
|
{ __(
|
||||||
|
`Product Collection`,
|
||||||
|
'woo-gutenberg-products-block'
|
||||||
|
) }
|
||||||
|
</strong>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const buttonLabel = __(
|
||||||
|
'Upgrade to Product Collection',
|
||||||
|
'woo-gutenberg-products-block'
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
props.upgradeBlock();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Notice isDismissible={ false }>
|
||||||
|
<>{ notice }</>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<Button variant="link" onClick={ handleClick }>
|
||||||
|
{ buttonLabel }
|
||||||
|
</Button>
|
||||||
|
</Notice>
|
||||||
|
);
|
||||||
|
};
|
|
@ -195,7 +195,7 @@ const replaceProductsBlocks = ( productsBlockClientIds: string[] ) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const replaceProductsWithProductCollection = (
|
export const replaceProductsWithProductCollection = (
|
||||||
unsubscribe: () => void
|
unsubscribe?: () => void
|
||||||
) => {
|
) => {
|
||||||
const queryBlocksCount =
|
const queryBlocksCount =
|
||||||
select( 'core/block-editor' ).getGlobalBlockCount( 'core/query' );
|
select( 'core/block-editor' ).getGlobalBlockCount( 'core/query' );
|
||||||
|
@ -213,7 +213,7 @@ export const replaceProductsWithProductCollection = (
|
||||||
|
|
||||||
const replaced = replaceProductsBlocks( productsBlockClientIds );
|
const replaced = replaceProductsBlocks( productsBlockClientIds );
|
||||||
|
|
||||||
if ( replaced ) {
|
if ( unsubscribe && replaced ) {
|
||||||
// @todo: unsubscribe on user reverting migration
|
// @todo: unsubscribe on user reverting migration
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue