Rename the "other" location from `generic` to `site` (#46228)

* Rename the useGetLocation generic option to site

* Add changelog

* Adjust tests to change
This commit is contained in:
Karol Manijak 2024-04-05 15:54:56 +02:00 committed by GitHub
parent 3af1ff3f68
commit 0c1e4efc89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 15 deletions

View File

@ -6,7 +6,13 @@ import { useState, useEffect, useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { store as blockEditorStore } from '@wordpress/block-editor';
type LocationType = 'product' | 'archive' | 'cart' | 'order' | 'generic';
export const enum LocationType {
Product = 'product',
Archive = 'archive',
Cart = 'cart',
Order = 'order',
Site = 'site',
}
type Context< T > = T & {
templateSlug?: string;
postId?: number;
@ -143,7 +149,9 @@ export const useGetLocation = < T, >(
*/
if ( isInSingleProductBlock ) {
return createLocationObject( 'product', { productId: postId } );
return createLocationObject( LocationType.Product, {
productId: postId,
} );
}
/**
@ -152,7 +160,7 @@ export const useGetLocation = < T, >(
*/
if ( isInSomeCartCheckoutBlock ) {
return createLocationObject( 'cart' );
return createLocationObject( LocationType.Cart );
}
/**
@ -161,7 +169,7 @@ export const useGetLocation = < T, >(
*/
if ( isInSpecificProductTemplate ) {
return createLocationObject( 'product', { productId } );
return createLocationObject( LocationType.Product, { productId } );
}
const isInGenericTemplate = prepareIsInGenericTemplate( templateSlug );
@ -176,7 +184,9 @@ export const useGetLocation = < T, >(
);
if ( isInSingleProductTemplate ) {
return createLocationObject( 'product', { productId: null } );
return createLocationObject( LocationType.Product, {
productId: null,
} );
}
/**
@ -185,7 +195,7 @@ export const useGetLocation = < T, >(
*/
if ( isInSpecificCategoryTemplate ) {
return createLocationObject( 'archive', {
return createLocationObject( LocationType.Archive, {
taxonomy: 'product_cat',
termId: categoryId,
} );
@ -197,7 +207,7 @@ export const useGetLocation = < T, >(
*/
if ( isInSpecificTagTemplate ) {
return createLocationObject( 'archive', {
return createLocationObject( LocationType.Archive, {
taxonomy: 'product_tag',
termId: tagId,
} );
@ -213,7 +223,7 @@ export const useGetLocation = < T, >(
);
if ( isInProductsByCategoryTemplate ) {
return createLocationObject( 'archive', {
return createLocationObject( LocationType.Archive, {
taxonomy: 'product_cat',
termId: null,
} );
@ -224,7 +234,7 @@ export const useGetLocation = < T, >(
);
if ( isInProductsByTagTemplate ) {
return createLocationObject( 'archive', {
return createLocationObject( LocationType.Archive, {
taxonomy: 'product_tag',
termId: null,
} );
@ -235,7 +245,7 @@ export const useGetLocation = < T, >(
);
if ( isInProductsByAttributeTemplate ) {
return createLocationObject( 'archive', {
return createLocationObject( LocationType.Archive, {
taxonomy: null,
termId: null,
} );
@ -251,7 +261,7 @@ export const useGetLocation = < T, >(
templateSlug === templateSlugs.checkout;
if ( isInCartCheckoutTemplate ) {
return createLocationObject( 'cart' );
return createLocationObject( LocationType.Cart );
}
/**
@ -264,7 +274,7 @@ export const useGetLocation = < T, >(
);
if ( isInOrderTemplate ) {
return createLocationObject( 'order' );
return createLocationObject( LocationType.Order );
}
/**
@ -272,7 +282,7 @@ export const useGetLocation = < T, >(
* All other cases
*/
return createLocationObject( 'generic' );
return createLocationObject( LocationType.Site );
};
/**

View File

@ -1002,7 +1002,7 @@ test.describe( 'Product Collection', () => {
expect( termId ).toBe( '' );
} );
test( 'as generic in post', async ( {
test( 'as site in post', async ( {
admin,
editorUtils,
pageObject,
@ -1019,7 +1019,7 @@ test.describe( 'Product Collection', () => {
const { type, sourceData } =
getLocationDetailsFromRequest( locationRequest );
expect( type ).toBe( 'generic' );
expect( type ).toBe( 'site' );
// Field is not sent at all. URLSearchParams get method returns a null
// if field is not available.
expect( sourceData ).toBe( null );

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Product Collection: Rename "other" location from `generic` to `site`