@magento/peregrine 12.1.0 → 12.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/lib/Apollo/clearCartDataFromCache.js +11 -12
  2. package/lib/Apollo/clearCustomerDataFromCache.js +15 -8
  3. package/lib/Apollo/policies/index.js +35 -3
  4. package/lib/Toasts/useToasts.js +5 -0
  5. package/lib/hooks/useCustomerWishlistSkus/customerWishlist.gql.ce.js +3 -3
  6. package/lib/store/actions/cart/asyncActions.js +1 -2
  7. package/lib/store/actions/user/asyncActions.js +2 -4
  8. package/lib/store/reducers/catalog.js +7 -7
  9. package/lib/store/reducers/user.js +1 -3
  10. package/lib/talons/Adapter/useAdapter.js +80 -11
  11. package/lib/talons/AddToCartDialog/addToCartDialog.gql.js +2 -2
  12. package/lib/talons/AddressBookPage/addressBookPage.gql.js +3 -9
  13. package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +16 -12
  14. package/lib/talons/Breadcrumbs/useBreadcrumbs.js +6 -4
  15. package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +2 -2
  16. package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +2 -3
  17. package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +1 -1
  18. package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +2 -1
  19. package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +3 -3
  20. package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +6 -3
  21. package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +1 -0
  22. package/lib/talons/CartPage/ProductListing/product.gql.js +2 -1
  23. package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +2 -1
  24. package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +2 -1
  25. package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +14 -5
  26. package/lib/talons/CartPage/ProductListing/useProduct.js +8 -1
  27. package/lib/talons/CartPage/ProductListing/useProductListing.js +4 -2
  28. package/lib/talons/CartPage/useCartPage.js +4 -3
  29. package/lib/talons/CategoryList/categoryList.gql.js +25 -17
  30. package/lib/talons/CategoryList/useCategoryList.js +6 -1
  31. package/lib/talons/CategoryList/useCategoryTile.js +2 -0
  32. package/lib/talons/CategoryTree/categoryTree.gql.js +18 -12
  33. package/lib/talons/CategoryTree/useCategoryBranch.js +1 -1
  34. package/lib/talons/CategoryTree/useCategoryTree.js +5 -5
  35. package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +1 -1
  36. package/lib/talons/CheckoutPage/BillingAddress/billingAddress.gql.js +1 -1
  37. package/lib/talons/CheckoutPage/ItemsReview/__fixtures__/cartItems.js +12 -12
  38. package/lib/talons/CheckoutPage/ItemsReview/itemsReview.gql.js +2 -1
  39. package/lib/talons/CheckoutPage/ItemsReview/itemsReviewFragments.gql.js +11 -5
  40. package/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +12 -6
  41. package/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js +2 -2
  42. package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +2 -2
  43. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +3 -5
  44. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +12 -4
  45. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +45 -5
  46. package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +2 -2
  47. package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +1 -1
  48. package/lib/talons/CheckoutPage/checkoutPage.gql.js +2 -2
  49. package/lib/talons/CheckoutPage/checkoutPageFragments.gql.js +4 -2
  50. package/lib/talons/CheckoutPage/useCheckoutPage.js +5 -2
  51. package/lib/talons/Cms/cmsPage.gql.js +0 -4
  52. package/lib/talons/Cms/useCmsPage.js +6 -23
  53. package/lib/talons/CommunicationsPage/communicationsPage.gql.js +2 -2
  54. package/lib/talons/ContactPage/contactUs.gql.js +48 -0
  55. package/lib/talons/ContactPage/index.js +2 -0
  56. package/lib/talons/ContactPage/useContactLink.js +27 -0
  57. package/lib/talons/ContactPage/useContactPage.js +85 -0
  58. package/lib/talons/CreateAccount/createAccount.gql.js +15 -8
  59. package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
  60. package/lib/talons/FilterModal/helpers.js +29 -0
  61. package/lib/talons/FilterModal/useFilterModal.js +9 -2
  62. package/lib/talons/FilterSidebar/useFilterSidebar.js +4 -1
  63. package/lib/talons/Footer/footer.gql.js +2 -1
  64. package/lib/talons/FormError/useFormError.js +9 -7
  65. package/lib/talons/Gallery/__fixtures__/apolloMocks.js +2 -2
  66. package/lib/talons/Gallery/gallery.gql.ce.js +2 -1
  67. package/lib/talons/Gallery/gallery.gql.ee.js +2 -1
  68. package/lib/talons/Gallery/useAddToCartButton.js +12 -11
  69. package/lib/talons/Header/storeSwitcher.gql.js +21 -9
  70. package/lib/talons/Header/useCartTrigger.js +3 -3
  71. package/lib/talons/Header/useStoreSwitcher.js +10 -8
  72. package/lib/talons/MagentoRoute/magentoRoute.gql.js +4 -2
  73. package/lib/talons/MagentoRoute/useMagentoRoute.js +39 -33
  74. package/lib/talons/MegaMenu/megaMenu.gql.js +10 -5
  75. package/lib/talons/MegaMenu/useMegaMenu.js +3 -5
  76. package/lib/talons/MegaMenu/useMegaMenuItem.js +5 -0
  77. package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +10 -5
  78. package/lib/talons/MiniCart/miniCart.gql.js +2 -1
  79. package/lib/talons/MiniCart/useMiniCart.js +8 -7
  80. package/lib/talons/Navigation/navigation.gql.js +4 -3
  81. package/lib/talons/Navigation/useNavigation.js +1 -1
  82. package/lib/talons/Newsletter/newsletter.gql.js +14 -1
  83. package/lib/talons/Newsletter/useNewsletter.js +31 -12
  84. package/lib/talons/OrderHistoryPage/orderHistoryContext.gql.js +2 -1
  85. package/lib/talons/OrderHistoryPage/orderHistoryPage.gql.js +1 -1
  86. package/lib/talons/OrderHistoryPage/orderRow.gql.js +7 -3
  87. package/lib/talons/ProductFullDetail/CustomAttributes/AttributeType/useAttributeType.js +26 -0
  88. package/lib/talons/ProductFullDetail/productFullDetail.gql.ce.js +4 -3
  89. package/lib/talons/ProductFullDetail/productFullDetail.gql.ee.js +2 -1
  90. package/lib/talons/ProductFullDetail/useProductFullDetail.js +28 -2
  91. package/lib/talons/RootComponents/Category/category.gql.js +7 -4
  92. package/lib/talons/RootComponents/Category/categoryContent.gql.js +27 -7
  93. package/lib/talons/RootComponents/Category/categoryFragments.gql.js +4 -2
  94. package/lib/talons/RootComponents/Category/useCategory.js +8 -6
  95. package/lib/talons/RootComponents/Category/useCategoryContent.js +30 -3
  96. package/lib/talons/RootComponents/Category/useNoProductsFound.js +0 -1
  97. package/lib/talons/RootComponents/Product/product.gql.js +2 -1
  98. package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +70 -10
  99. package/lib/talons/SearchPage/searchPage.gql.js +18 -2
  100. package/lib/talons/SearchPage/useSearchPage.js +25 -0
  101. package/lib/talons/SignIn/signIn.gql.js +4 -3
  102. package/lib/talons/SignIn/useSignIn.js +2 -4
  103. package/lib/talons/Wishlist/WishlistDialog/wishlistDialog.gql.js +3 -2
  104. package/lib/talons/WishlistPage/createWishlist.gql.js +2 -1
  105. package/lib/talons/WishlistPage/useWishlistItem.js +2 -2
  106. package/lib/talons/WishlistPage/wishlist.gql.js +2 -2
  107. package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +2 -1
  108. package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +2 -1
  109. package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +5 -2
  110. package/lib/talons/WishlistPage/wishlistPage.gql.js +1 -1
  111. package/package.json +6 -6
  112. package/lib/Apollo/clearStore.js +0 -26
  113. package/lib/Apollo/deleteCacheEntry.js +0 -87
@@ -25,6 +25,7 @@ export const useSearchPage = (props = {}) => {
25
25
  getFilterInputsQuery,
26
26
  getPageSize,
27
27
  getProductFiltersBySearchQuery,
28
+ getSearchAvailableSortMethods,
28
29
  productSearchQuery
29
30
  } = operations;
30
31
 
@@ -32,6 +33,15 @@ export const useSearchPage = (props = {}) => {
32
33
  fetchPolicy: 'cache-and-network',
33
34
  nextFetchPolicy: 'cache-first'
34
35
  });
36
+
37
+ const [getSortMethods, { data: sortData }] = useLazyQuery(
38
+ getSearchAvailableSortMethods,
39
+ {
40
+ fetchPolicy: 'cache-and-network',
41
+ nextFetchPolicy: 'cache-first'
42
+ }
43
+ );
44
+
35
45
  const pageSize = pageSizeData && pageSizeData.storeConfig.grid_per_page;
36
46
 
37
47
  const sortProps = useSort();
@@ -193,6 +203,16 @@ export const useSearchPage = (props = {}) => {
193
203
  }
194
204
  }, [currentSort, search, setCurrentPage]);
195
205
 
206
+ useEffect(() => {
207
+ if (inputText) {
208
+ getSortMethods({
209
+ variables: {
210
+ search: inputText
211
+ }
212
+ });
213
+ }
214
+ }, [inputText, getSortMethods]);
215
+
196
216
  // Fetch category filters for when a user is searching in a category.
197
217
  const [getFilters, { data: filterData }] = useLazyQuery(
198
218
  getProductFiltersBySearchQuery,
@@ -224,7 +244,12 @@ export const useSearchPage = (props = {}) => {
224
244
 
225
245
  useScrollTopOnChange(currentPage);
226
246
 
247
+ const availableSortMethods = sortData
248
+ ? sortData.products.sort_fields.options
249
+ : null;
250
+
227
251
  return {
252
+ availableSortMethods,
228
253
  data,
229
254
  error,
230
255
  filters,
@@ -3,8 +3,8 @@ import { CheckoutPageFragment } from '../CheckoutPage/checkoutPageFragments.gql'
3
3
 
4
4
  export const GET_CUSTOMER = gql`
5
5
  query GetCustomerAfterSignIn {
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
7
  customer {
7
- id
8
8
  email
9
9
  firstname
10
10
  lastname
@@ -35,10 +35,11 @@ export const MERGE_CARTS = gql`
35
35
  mergeCarts(
36
36
  source_cart_id: $sourceCartId
37
37
  destination_cart_id: $destinationCartId
38
- ) @connection(key: "mergeCarts") {
38
+ ) {
39
39
  id
40
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
40
41
  items {
41
- id
42
+ uid
42
43
  }
43
44
  ...CheckoutPageFragment
44
45
  }
@@ -1,8 +1,6 @@
1
1
  import { useCallback, useRef, useState, useMemo } from 'react';
2
2
  import { useApolloClient, useMutation } from '@apollo/client';
3
3
 
4
- import { clearCartDataFromCache } from '../../Apollo/clearCartDataFromCache';
5
- import { clearCustomerDataFromCache } from '../../Apollo/clearCustomerDataFromCache';
6
4
  import mergeOperations from '../../util/shallowMerge';
7
5
  import { useCartContext } from '../../context/cart';
8
6
  import { useUserContext } from '../../context/user';
@@ -67,8 +65,8 @@ export const useSignIn = props => {
67
65
  await setToken(token);
68
66
 
69
67
  // Clear all cart/customer data from cache and redux.
70
- await clearCartDataFromCache(apolloClient);
71
- await clearCustomerDataFromCache(apolloClient);
68
+ await apolloClient.clearCacheData(apolloClient, 'cart');
69
+ await apolloClient.clearCacheData(apolloClient, 'checkout');
72
70
  await removeCart();
73
71
 
74
72
  // Create and get the customer's cart id.
@@ -23,13 +23,14 @@ export const ADD_TO_WISHLIST = gql`
23
23
 
24
24
  export const GET_WISHLISTS = gql`
25
25
  query getWishlistsDialogData {
26
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
26
27
  storeConfig {
27
- id
28
+ store_code
28
29
  enable_multiple_wishlists
29
30
  maximum_number_of_wishlists
30
31
  }
32
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
31
33
  customer {
32
- id
33
34
  wishlists {
34
35
  id
35
36
  name
@@ -12,8 +12,9 @@ export const CREATE_WISHLIST = gql`
12
12
 
13
13
  export const GET_MULTIPLE_WISHLISTS_ENABLED = gql`
14
14
  query getMultipleWishlistsEnabled {
15
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
15
16
  storeConfig {
16
- id
17
+ store_code
17
18
  enable_multiple_wishlists
18
19
  }
19
20
  }
@@ -81,8 +81,8 @@ export const useWishlistItem = props => {
81
81
  const selectedOptionsArray = selectedConfigurableOptions.map(
82
82
  selectedOption => {
83
83
  const {
84
- id: attributeId,
85
- value_id: selectedValueId
84
+ configurable_product_option_uid: attributeId,
85
+ configurable_product_option_value_uid: selectedValueId
86
86
  } = selectedOption;
87
87
  const configurableOption = configurableOptions.find(
88
88
  option => option.attribute_id_v2 === attributeId
@@ -5,8 +5,8 @@ import { WishlistItemFragment } from './wishlistItemFragments.gql';
5
5
 
6
6
  export const GET_CUSTOMER_WISHLIST = gql`
7
7
  query GetCustomerWishlist {
8
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
8
9
  customer {
9
- id
10
10
  wishlists {
11
11
  id
12
12
  ...WishlistPageFragment
@@ -18,8 +18,8 @@ export const GET_CUSTOMER_WISHLIST = gql`
18
18
 
19
19
  export const GET_CUSTOMER_WISHLIST_ITEMS = gql`
20
20
  query getCustomerWishlist($id: ID!, $currentPage: Int) {
21
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
21
22
  customer {
22
- id
23
23
  wishlist_v2(id: $id) {
24
24
  id
25
25
  items_v2(currentPage: $currentPage) {
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_WISHLIST_CONFIG = gql`
4
4
  query GetWishlistConfigForWishlistPageCE {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  magento_wishlist_general_is_enabled
8
9
  }
9
10
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_WISHLIST_CONFIG = gql`
4
4
  query GetWishlistConfigForWishlistPageEE {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  magento_wishlist_general_is_enabled
8
9
  enable_multiple_wishlists
9
10
  }
@@ -3,8 +3,9 @@ import { gql } from '@apollo/client';
3
3
  export const WishlistItemFragment = gql`
4
4
  fragment WishlistItemFragment on WishlistItemInterface {
5
5
  id
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
7
  product {
7
- id
8
+ uid
8
9
  image {
9
10
  label
10
11
  url
@@ -20,9 +21,11 @@ export const WishlistItemFragment = gql`
20
21
  }
21
22
  sku
22
23
  stock_status
24
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
23
25
  ... on ConfigurableProduct {
26
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
24
27
  configurable_options {
25
- id
28
+ uid
26
29
  attribute_code
27
30
  attribute_id
28
31
  attribute_id_v2
@@ -4,8 +4,8 @@ import { WishlistPageFragment } from './wishlistFragment.gql';
4
4
 
5
5
  export const GET_CUSTOMER_WISHLIST = gql`
6
6
  query GetCustomerWishlist {
7
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
8
  customer {
8
- id
9
9
  wishlists {
10
10
  id
11
11
  ...WishlistPageFragment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magento/peregrine",
3
- "version": "12.1.0",
3
+ "version": "12.2.0-beta.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -15,12 +15,12 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/magento/pwa-studio/issues"
17
17
  },
18
- "homepage": "https://github.com/magento/pwa-studio/tree/master/packages/peregrine#readme",
18
+ "homepage": "https://github.com/magento/pwa-studio/tree/main/packages/peregrine#readme",
19
19
  "dependencies": {
20
20
  "fast-glob": "~3.2.4"
21
21
  },
22
22
  "devDependencies": {
23
- "@apollo/client": "~3.1.2",
23
+ "@apollo/client": "~3.4.0",
24
24
  "@magento/eslint-config": "~1.5.0",
25
25
  "@testing-library/react-hooks": "~5.0.3",
26
26
  "intl": "~1.2.5",
@@ -36,8 +36,8 @@
36
36
  "wait-for-expect": "~1.2.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@apollo/client": "~3.1.2",
40
- "@babel/runtime": "~7.4.2",
39
+ "@apollo/client": "~3.4.0",
40
+ "@babel/runtime": "~7.15.3",
41
41
  "informed": "~3.29.0",
42
42
  "react": "~17.0.1",
43
43
  "react-dom": "~17.0.1",
@@ -48,7 +48,7 @@
48
48
  "redux-actions": "~2.6.5"
49
49
  },
50
50
  "engines": {
51
- "node": ">=10.x",
51
+ "node": ">=14.x",
52
52
  "yarn": ">=1.12.0"
53
53
  },
54
54
  "pwa-studio": {
@@ -1,26 +0,0 @@
1
- /**
2
- * Wipes the apollo cache in memory and persistence.
3
- *
4
- * According to Apollo's docs you should only have to call client.clearStore
5
- * but if you use a persistence layer such as apollo-cache-persist you MUST
6
- * pause and purge the persistor's buffer _before_ calling clear store otherwise
7
- * the data is immediately replayed into the client store from the persistor.
8
- *
9
- * See: https://github.com/apollographql/apollo-cache-persist/issues/34#issuecomment-371177206
10
- *
11
- * @param {ApolloClient} client apollo client instance
12
- * @param {PersistorInstance} persistor persistor instance
13
- */
14
- export const clearStore = async (client, persistor) => {
15
- // Pause automatic persistence.
16
- persistor.pause();
17
-
18
- // Delete everything in the storage provider.
19
- await persistor.purge();
20
-
21
- // Wipe the apollo store. Do not replay queries.
22
- await client.clearStore();
23
-
24
- // Resume automatic persistence.
25
- persistor.resume();
26
- };
@@ -1,87 +0,0 @@
1
- import { CACHE_PERSIST_PREFIX } from '@magento/peregrine/lib/Apollo/constants';
2
-
3
- /**
4
- * Deletes specific entry/entries from the apollo cache and then tries to
5
- * persist the deletions.
6
- *
7
- * @param {ApolloClient} client apollo client instance
8
- * @param {Function} predicate a matching function
9
- */
10
- export const deleteCacheEntry = async (client, predicate) => {
11
- await deleteActiveCacheEntry(client, predicate);
12
- await deleteInactiveCachesEntry(client, predicate);
13
- };
14
-
15
- const deleteActiveCacheEntry = async (client, predicate) => {
16
- // If there is no client or cache then just back out since it doesn't matter :D
17
- if (
18
- !client ||
19
- !client.cache ||
20
- !client.cache.data ||
21
- !client.cache.data.data
22
- ) {
23
- if (process.env.NODE_ENV === 'development') {
24
- console.warn(
25
- 'Apollo Cache entry deletion attempted without client or cache.'
26
- );
27
- }
28
- return;
29
- }
30
-
31
- // Remove from the active cache.
32
- Object.keys(client.cache.data.data).forEach(key => {
33
- if (predicate(key)) {
34
- client.cache.data.delete(key);
35
- }
36
- });
37
-
38
- // Remove from ROOT_QUERY cache.
39
- if (client.cache.data.data.ROOT_QUERY) {
40
- Object.keys(client.cache.data.data.ROOT_QUERY).forEach(key => {
41
- if (predicate(key)) {
42
- client.cache.data.delete('ROOT_QUERY', key);
43
- }
44
- });
45
- }
46
-
47
- // Immediately persist the cache changes to the active cache storage.
48
- if (client.persistor) {
49
- await client.persistor.persist();
50
- }
51
- };
52
-
53
- const deleteInactiveCachesEntry = async (client, predicate) => {
54
- if (!client || !client.persistor || !globalThis.localStorage) return;
55
-
56
- const activeApolloCacheLocalStorageKey =
57
- client.persistor.persistor.storage.key;
58
-
59
- const isAnInactiveApolloCache = ([key]) => {
60
- return (
61
- key.startsWith(CACHE_PERSIST_PREFIX) &&
62
- key !== activeApolloCacheLocalStorageKey
63
- );
64
- };
65
-
66
- const { localStorage } = globalThis;
67
-
68
- Object.entries(localStorage)
69
- .filter(isAnInactiveApolloCache)
70
- .forEach(([inactiveCacheKey, inactiveCacheValue]) => {
71
- const inactiveApolloCache = JSON.parse(inactiveCacheValue);
72
-
73
- Object.keys(inactiveApolloCache).forEach(key => {
74
- if (predicate(key)) {
75
- delete inactiveApolloCache[key];
76
- }
77
- });
78
-
79
- // We're done deleting keys that match the predicate,
80
- // but we've only mutated the object in memory.
81
- // Write the updated inactive cache back out to localStorage.
82
- localStorage.setItem(
83
- inactiveCacheKey,
84
- JSON.stringify(inactiveApolloCache)
85
- );
86
- });
87
- };