Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated components codes #2601

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/modern-suits-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/hydrogen-react': patch
'@shopify/hydrogen': patch
---

Update `<ProductPrice>` to remove deprecated code usage for `priceV2` and `compareAtPriceV2`. Remove export for `getCustomerPrivacy`.
2 changes: 1 addition & 1 deletion packages/hydrogen-react/src/CartProvider.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const CART_LINE: PartialDeep<CartLine, {recurseIntoArrays: true}> = {
merchandise: {
id: 'def',
availableForSale: true,
priceV2: {
price: {
amount: '123',
currencyCode: 'USD',
},
Expand Down
3 changes: 0 additions & 3 deletions packages/hydrogen-react/src/Image.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ export function getPreviewImage(image: Partial<ImageType> = {}): PartialDeep<
url: image.url ?? faker.image.imageUrl(),
width: image.width ?? faker.datatype.number(),
height: image.height ?? faker.datatype.number(),
originalSrc: '',
transformedSrc: '',
src: '',
};
}
4 changes: 2 additions & 2 deletions packages/hydrogen-react/src/ProductPrice.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ const Template: Story<ProductPriceProps> = (props) => {
nodes: [
getVariant({
id: '123',
priceV2: {
price: {
currencyCode: 'USD',
amount: '300',
},
compareAtPriceV2: {
compareAtPrice: {
currencyCode: 'USD',
amount: '310',
},
Expand Down
10 changes: 0 additions & 10 deletions packages/hydrogen-react/src/ProductPrice.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('<ProductPrice />', () => {
expect(
screen.getByText(variant?.price?.amount || '', {exact: false}),
).toBeInTheDocument();

expect(
screen.getByText(variant?.priceV2?.amount || '', {exact: false}),
).toBeInTheDocument();
});

it("renders <Money /> with the variant's minimum compareAt price", () => {
Expand Down Expand Up @@ -51,12 +47,6 @@ describe('<ProductPrice />', () => {
exact: false,
}),
).toBeInTheDocument();

expect(
screen.getByText(variant?.compareAtPriceV2?.amount || '', {
exact: false,
}),
).toBeInTheDocument();
});

it('renders <Money /> with unit prices when valueType is `unit`', () => {
Expand Down
23 changes: 3 additions & 20 deletions packages/hydrogen-react/src/ProductPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,19 @@ export function ProductPrice<
) ?? null
: null;

/**
* @deprecated (Next major release) Stop using compareAtPriceV2 and priceV2
*/
const variantPriceProperty =
valueType === 'max' ? 'maxVariantPrice' : 'minVariantPrice';

if (priceType === 'compareAt') {
if (variantId && variant) {
if (variant.compareAtPriceV2) {
console.error(
'<ProductPrice> `compareAtPriceV2` is deprecated. Use `compareAtPrice` instead.',
);
}

price = variant.compareAtPrice ?? variant.compareAtPriceV2;
price = variant.compareAtPrice;
} else {
price = product?.compareAtPriceRange?.[variantPriceProperty];
}

let priceAsNumber: number;
if (variantId && variant) {
priceAsNumber = parseFloat(
variant.price?.amount ?? variant.priceV2?.amount ?? '0',
);
priceAsNumber = parseFloat(variant.price?.amount ?? '0');
} else {
priceAsNumber = parseFloat(
product?.priceRange?.[variantPriceProperty]?.amount ?? '0',
Expand All @@ -86,13 +75,7 @@ export function ProductPrice<
}
} else {
if (variantId && variant) {
if (variant.priceV2) {
console.error(
'<ProductPrice> `priceV2` is deprecated. Use `price` instead.',
);
}

price = variant.price ?? variant.priceV2;
price = variant.price;
if (valueType === 'unit') {
price = variant.unitPrice;
measurement = variant.unitPriceMeasurement;
Expand Down
20 changes: 9 additions & 11 deletions packages/hydrogen-react/src/ProductProvider.test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export function getVariant(
variant?.unitPriceMeasurement ?? undefined,
),
price,
priceV2: price,
compareAtPrice,
compareAtPriceV2: compareAtPrice,
selectedOptions: [
{name: faker.random.word(), value: faker.random.word()},
{name: faker.random.word(), value: faker.random.word()},
Expand All @@ -85,7 +83,7 @@ export function getVariant(
};
}

const priceV2: MoneyV2 = {
const price: MoneyV2 = {
amount: '9.99',
currencyCode: 'CAD',
};
Expand All @@ -109,9 +107,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -128,9 +126,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -147,9 +145,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: true,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
{
Expand All @@ -166,9 +164,9 @@ export const VARIANTS: PartialDeep<
},
],
availableForSale: false,
unitPrice: priceV2,
unitPrice: price,
unitPriceMeasurement: getUnitPriceMeasurement(),
priceV2,
price,
metafields: [],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const data: ReferenceEntityTemplateSchema = {
isVisualComponent: false,
related: [],
description:
'A hook that loads the [Customer Privacy API](/docs/api/customer-privacy).\n\nYou can get the customer privacy instance with `getCustomerPrivacy()`.\n\nYou can also listen to a `document` event for `shopifyCustomerPrivacyApiLoaded`. It will be emitted when the Customer Privacy API is loaded.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this reference still existed in the docs, so I've removed it

'A hook that loads the [Customer Privacy API](/docs/api/customer-privacy).\n\nYou can also listen to a `document` event for `shopifyCustomerPrivacyApiLoaded`. It will be emitted when the Customer Privacy API is loaded.',
type: 'hook',
defaultExample: {
description: 'This is the default example',
Expand Down Expand Up @@ -37,7 +37,7 @@ const data: ReferenceEntityTemplateSchema = {
description: 'Example usage with `useAnalytics`:',
exampleGroups: [
{
title: 'getCustomerPrivacy',
title: 'useCustomerPrivacy',
examples: [
{
description:
Expand Down
4 changes: 0 additions & 4 deletions packages/hydrogen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ export {
type CustomEventMap,
type CustomerPrivacyApiProps,
useCustomerPrivacy,
/*
@deprecated use useAnalytics or useCustomerPrivacy instead
*/
getCustomerPrivacy,
} from './customer-privacy/ShopifyCustomerPrivacy';

export {
Expand Down
Loading