Product Collection: Remove automatic migration code (#50440)

Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
This commit is contained in:
Bart Kalisz 2024-08-13 11:29:07 +02:00 committed by GitHub
parent e82f1ea98f
commit 418c8f029f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 43 additions and 41 deletions

View File

@ -3,7 +3,6 @@
*/
import type { UpgradeNoticeStatus, UpgradeNoticeStatuses } from './types';
export const AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false;
export const MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = true;
export const HOURS_TO_DISPLAY_UPGRADE_NOTICE = 72;
export const UPGRADE_NOTICE_DISPLAY_COUNT_THRESHOLD = 4;

View File

@ -7,7 +7,6 @@ import { select, dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { disableAutoUpdate } from './migration-from-products-to-product-collection';
import {
getProductCollectionBlockClientIds,
checkIfBlockCanBeInserted,
@ -216,7 +215,6 @@ export const replaceProductCollectionWithProducts = () => {
};
export const revertMigration = () => {
disableAutoUpdate();
setUpgradeStatus( {
status: 'reverted',
time: Date.now(),

View File

@ -2,21 +2,16 @@
* External dependencies
*/
import { createBlock, BlockInstance } from '@wordpress/blocks';
import { select, dispatch, subscribe } from '@wordpress/data';
import { isWpVersion } from '@woocommerce/settings';
import { select, dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import {
AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION,
getInitialStatusLSValue,
} from './constants';
import { getInitialStatusLSValue } from './constants';
import {
getProductsBlockClientIds,
checkIfBlockCanBeInserted,
postTemplateHasSupportForGridView,
getUpgradeStatus,
setUpgradeStatus,
} from './migration-utils';
import type {
@ -229,25 +224,3 @@ export const manualUpdate = () => {
setUpgradeStatus( getInitialStatusLSValue() );
replaceProductsWithProductCollection();
};
let unsubscribe: ( () => void ) | undefined;
export const disableAutoUpdate = () => {
if ( unsubscribe ) {
unsubscribe();
}
};
export const enableAutoUpdate = () => {
if ( isWpVersion( '6.1', '>=' ) ) {
const { status } = getUpgradeStatus();
if (
AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION &&
status !== 'reverted' &&
! unsubscribe
) {
unsubscribe = subscribe( () => {
replaceProductsWithProductCollection();
}, 'core/block-editor' );
}
}
};

View File

@ -29,7 +29,7 @@ import { DEFAULT_FILTERS } from '../../constants';
function useProducts(
isLargeCatalog: boolean,
search: string,
selected: string[]
selected: string[] = []
) {
// Creating a map for fast lookup of products by id or name.
const [ productsMap, setProductsMap ] = useState<

View File

@ -9,7 +9,6 @@ import { EditorBlock } from '@woocommerce/types';
import { addFilter } from '@wordpress/hooks';
import { ProductCollectionFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';
import {
enableAutoUpdate,
revertMigration,
getUpgradeStatus,
HOURS_TO_DISPLAY_UPGRADE_NOTICE,
@ -190,13 +189,6 @@ const ProductCollectionInspectorControls = (
export default ProductCollectionInspectorControls;
// Trigger Auto Upgrade of Products only once when module is loaded.
// This triggers subscription but only if:
// - auto update is enabled
// - user haven't reverted the migration
// - no other subscription is in place
enableAutoUpdate();
const isProductCollection = ( blockName: string ) =>
blockName === metadata.name;

View File

@ -44,6 +44,42 @@ test.describe( 'Product Collection', () => {
await expect( pageObject.addToCartButtons ).toHaveCount( 9 );
} );
test( 'Can be migrated to from Products (Beta) block', async ( {
page,
editor,
admin,
} ) => {
await admin.createNewPost();
await editor.insertBlock( {
name: 'core/query',
attributes: {
namespace: 'woocommerce/product-query',
},
} );
await expect(
page.getByLabel( 'Block: Products (Beta)' )
).toBeVisible();
await page.getByRole( 'button', { name: 'Start blank' } ).click();
await page.getByLabel( 'Title & Date' ).click();
await page
.getByRole( 'button', { name: 'Upgrade to Product Collection' } )
.click();
await expect(
page.getByLabel( 'Block: Products (Beta)' )
).toBeHidden();
await expect(
page.getByLabel( 'Block: Product Collection' ).first()
).toBeVisible();
await expect(
page.getByRole( 'button', { name: 'Choose collection' } )
).toBeVisible();
} );
test.describe( 'Renders correctly with all Product Elements', () => {
const expectedProductContent = [
'Beanie', // core/post-title

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
Remove the code related to the automatic Products (Beta) -> Product Collection upgrade.