@magento/peregrine 12.1.0 → 12.2.0-alpha.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 (110) 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/Footer/footer.gql.js +2 -1
  61. package/lib/talons/FormError/useFormError.js +9 -7
  62. package/lib/talons/Gallery/__fixtures__/apolloMocks.js +2 -2
  63. package/lib/talons/Gallery/gallery.gql.ce.js +2 -1
  64. package/lib/talons/Gallery/gallery.gql.ee.js +2 -1
  65. package/lib/talons/Gallery/useAddToCartButton.js +12 -11
  66. package/lib/talons/Header/storeSwitcher.gql.js +21 -9
  67. package/lib/talons/Header/useCartTrigger.js +3 -3
  68. package/lib/talons/Header/useStoreSwitcher.js +10 -8
  69. package/lib/talons/MagentoRoute/magentoRoute.gql.js +4 -2
  70. package/lib/talons/MagentoRoute/useMagentoRoute.js +39 -33
  71. package/lib/talons/MegaMenu/megaMenu.gql.js +10 -5
  72. package/lib/talons/MegaMenu/useMegaMenu.js +3 -5
  73. package/lib/talons/MegaMenu/useMegaMenuItem.js +5 -0
  74. package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +10 -5
  75. package/lib/talons/MiniCart/miniCart.gql.js +2 -1
  76. package/lib/talons/MiniCart/useMiniCart.js +8 -7
  77. package/lib/talons/Navigation/navigation.gql.js +4 -3
  78. package/lib/talons/Navigation/useNavigation.js +1 -1
  79. package/lib/talons/Newsletter/newsletter.gql.js +14 -1
  80. package/lib/talons/Newsletter/useNewsletter.js +31 -12
  81. package/lib/talons/OrderHistoryPage/orderHistoryContext.gql.js +2 -1
  82. package/lib/talons/OrderHistoryPage/orderHistoryPage.gql.js +1 -1
  83. package/lib/talons/OrderHistoryPage/orderRow.gql.js +7 -3
  84. package/lib/talons/ProductFullDetail/CustomAttributes/AttributeType/useAttributeType.js +26 -0
  85. package/lib/talons/ProductFullDetail/productFullDetail.gql.ce.js +4 -3
  86. package/lib/talons/ProductFullDetail/productFullDetail.gql.ee.js +2 -1
  87. package/lib/talons/ProductFullDetail/useProductFullDetail.js +28 -2
  88. package/lib/talons/RootComponents/Category/category.gql.js +7 -4
  89. package/lib/talons/RootComponents/Category/categoryContent.gql.js +26 -7
  90. package/lib/talons/RootComponents/Category/categoryFragments.gql.js +4 -2
  91. package/lib/talons/RootComponents/Category/useCategory.js +8 -6
  92. package/lib/talons/RootComponents/Category/useCategoryContent.js +30 -3
  93. package/lib/talons/RootComponents/Category/useNoProductsFound.js +0 -1
  94. package/lib/talons/RootComponents/Product/product.gql.js +2 -1
  95. package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +66 -10
  96. package/lib/talons/SearchPage/searchPage.gql.js +17 -2
  97. package/lib/talons/SearchPage/useSearchPage.js +25 -0
  98. package/lib/talons/SignIn/signIn.gql.js +4 -3
  99. package/lib/talons/SignIn/useSignIn.js +2 -4
  100. package/lib/talons/Wishlist/WishlistDialog/wishlistDialog.gql.js +3 -2
  101. package/lib/talons/WishlistPage/createWishlist.gql.js +2 -1
  102. package/lib/talons/WishlistPage/useWishlistItem.js +2 -2
  103. package/lib/talons/WishlistPage/wishlist.gql.js +2 -2
  104. package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +2 -1
  105. package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +2 -1
  106. package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +5 -2
  107. package/lib/talons/WishlistPage/wishlistPage.gql.js +1 -1
  108. package/package.json +6 -6
  109. package/lib/Apollo/clearStore.js +0 -26
  110. package/lib/Apollo/deleteCacheEntry.js +0 -87
@@ -98,8 +98,8 @@ export const GET_CUSTOMER_ORDERS = gql`
98
98
  $filter: CustomerOrdersFilterInput
99
99
  $pageSize: Int!
100
100
  ) {
101
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
101
102
  customer {
102
- id
103
103
  orders(filter: $filter, pageSize: $pageSize) {
104
104
  ...CustomerOrdersFragment
105
105
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
4
4
  query getConfigurableThumbnailSource {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  configurable_thumbnail_source
8
9
  }
9
10
  }
@@ -12,19 +13,22 @@ export const GET_CONFIGURABLE_THUMBNAIL_SOURCE = gql`
12
13
  export const GET_PRODUCT_THUMBNAILS_BY_URL_KEY = gql`
13
14
  query GetProductThumbnailsByURLKey($urlKeys: [String!]!) {
14
15
  products(filter: { url_key: { in: $urlKeys } }) {
16
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
15
17
  items {
16
- id
18
+ uid
17
19
  sku
18
20
  thumbnail {
19
21
  label
20
22
  url
21
23
  }
22
24
  url_key
25
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
23
26
  ... on ConfigurableProduct {
24
27
  variants {
28
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
25
29
  product {
26
30
  sku
27
- id
31
+ uid
28
32
  thumbnail {
29
33
  label
30
34
  url
@@ -0,0 +1,26 @@
1
+ import { useCallback } from 'react';
2
+
3
+ /**
4
+ * @param {Object} props.typeConfig - component types configuration object
5
+ *
6
+ * @returns {{
7
+ * getAttributeTypeConfig: function
8
+ * }}
9
+ */
10
+ export const useAttributeType = props => {
11
+ const { typeConfig = {} } = props;
12
+
13
+ // Retrieve a attribute types configuration
14
+ const getAttributeTypeConfig = useCallback(
15
+ attributeType => {
16
+ if (typeConfig[attributeType]) {
17
+ return typeConfig[attributeType];
18
+ }
19
+ },
20
+ [typeConfig]
21
+ );
22
+
23
+ return {
24
+ getAttributeTypeConfig
25
+ };
26
+ };
@@ -19,8 +19,9 @@ export const ADD_PRODUCT_TO_CART = gql`
19
19
 
20
20
  export const GET_WISHLIST_CONFIG = gql`
21
21
  query GetWishlistConfigForProductCE {
22
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
22
23
  storeConfig {
23
- id
24
+ store_code
24
25
  magento_wishlist_general_is_enabled
25
26
  }
26
27
  }
@@ -46,7 +47,7 @@ export const ADD_CONFIGURABLE_MUTATION = gql`
46
47
  }
47
48
  ]
48
49
  }
49
- ) @connection(key: "addConfigurableProductsToCart") {
50
+ ) {
50
51
  cart {
51
52
  id
52
53
  # Update the cart trigger when adding an item.
@@ -74,7 +75,7 @@ export const ADD_SIMPLE_MUTATION = gql`
74
75
  cart_id: $cartId
75
76
  cart_items: [{ data: { quantity: $quantity, sku: $sku } }]
76
77
  }
77
- ) @connection(key: "addSimpleProductsToCart") {
78
+ ) {
78
79
  cart {
79
80
  id
80
81
  # Update the cart trigger when adding an item.
@@ -4,8 +4,9 @@ import defaultOperations from './productFullDetail.gql.ce';
4
4
 
5
5
  export const GET_WISHLIST_CONFIG = gql`
6
6
  query GetWishlistConfigForProductEE {
7
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
8
  storeConfig {
8
- id
9
+ store_code
9
10
  magento_wishlist_general_is_enabled
10
11
  enable_multiple_wishlists
11
12
  }
@@ -135,12 +135,12 @@ const getBreadcrumbCategoryId = categories => {
135
135
  // Until we can get the single canonical breadcrumb path to a product we
136
136
  // will just return the first category id of the potential leaf categories.
137
137
  const leafCategory = categories.find(
138
- category => !breadcrumbSet.has(category.id)
138
+ category => !breadcrumbSet.has(category.uid)
139
139
  );
140
140
 
141
141
  // If we couldn't find a leaf category then just use the first category
142
142
  // in the list for this product.
143
- return leafCategory.id || categories[0].id;
143
+ return leafCategory.uid || categories[0].uid;
144
144
  };
145
145
 
146
146
  const getConfigPrice = (product, optionCodes, optionSelections) => {
@@ -170,6 +170,26 @@ const getConfigPrice = (product, optionCodes, optionSelections) => {
170
170
  return value;
171
171
  };
172
172
 
173
+ const getCustomAttributes = (product, optionCodes, optionSelections) => {
174
+ const { custom_attributes, variants } = product;
175
+ const isConfigurable = isProductConfigurable(product);
176
+ const optionsSelected =
177
+ Array.from(optionSelections.values()).filter(value => !!value).length >
178
+ 0;
179
+
180
+ if (isConfigurable && optionsSelected) {
181
+ const item = findMatchingVariant({
182
+ optionCodes,
183
+ optionSelections,
184
+ variants
185
+ });
186
+
187
+ return item.product.custom_attributes;
188
+ }
189
+
190
+ return custom_attributes;
191
+ };
192
+
173
193
  /**
174
194
  * @param {GraphQLDocument} props.addConfigurableProductToCartMutation - configurable product mutation
175
195
  * @param {GraphQLDocument} props.addSimpleProductToCartMutation - configurable product mutation
@@ -276,6 +296,11 @@ export const useProductFullDetail = props => {
276
296
  [product, optionCodes, optionSelections]
277
297
  );
278
298
 
299
+ const customAttributes = useMemo(
300
+ () => getCustomAttributes(product, optionCodes, optionSelections),
301
+ [product, optionCodes, optionSelections]
302
+ );
303
+
279
304
  // The map of ids to values (and their uids)
280
305
  // For example:
281
306
  // { "179" => [{ uid: "abc", value_index: 1 }, { uid: "def", value_index: 2 }]}
@@ -488,6 +513,7 @@ export const useProductFullDetail = props => {
488
513
  storeConfigData &&
489
514
  !!storeConfigData.storeConfig.magento_wishlist_general_is_enabled,
490
515
  productDetails,
516
+ customAttributes,
491
517
  wishlistButtonProps,
492
518
  wishlistItemOptions
493
519
  };
@@ -4,15 +4,18 @@ import { CategoryFragment, ProductsFragment } from './categoryFragments.gql';
4
4
 
5
5
  export const GET_CATEGORY = gql`
6
6
  query GetCategories(
7
- $id: Int!
7
+ $id: String!
8
8
  $pageSize: Int!
9
9
  $currentPage: Int!
10
10
  $filters: ProductAttributeFilterInput!
11
11
  $sort: ProductAttributeSortInput
12
12
  ) {
13
- category(id: $id) {
14
- id
15
- ...CategoryFragment
13
+ categories(filters: { category_uid: { in: [$id] } }) {
14
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
15
+ items {
16
+ uid
17
+ ...CategoryFragment
18
+ }
16
19
  }
17
20
  products(
18
21
  pageSize: $pageSize
@@ -4,7 +4,7 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
4
4
  query getProductFiltersByCategory(
5
5
  $categoryIdFilter: FilterEqualTypeInput!
6
6
  ) {
7
- products(filter: { category_id: $categoryIdFilter }) {
7
+ products(filter: { category_uid: $categoryIdFilter }) {
8
8
  aggregations {
9
9
  label
10
10
  count
@@ -19,16 +19,35 @@ export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
19
19
  `;
20
20
 
21
21
  export const GET_CATEGORY_CONTENT = gql`
22
- query getCategoryData($id: Int!) {
23
- category(id: $id) {
24
- id
25
- name
26
- description
22
+ query getCategoryData($id: String!) {
23
+ categories(filters: { category_uid: { in: [$id] } }) {
24
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
25
+ items {
26
+ uid
27
+ name
28
+ description
29
+ }
30
+ }
31
+ }
32
+ `;
33
+
34
+ export const GET_CATEGORY_AVAILABLE_SORT_METHODS = gql`
35
+ query getCategoryAvailableSortMethods(
36
+ $categoryIdFilter: FilterEqualTypeInput!
37
+ ) {
38
+ products(filter: { category_uid: $categoryIdFilter }) {
39
+ sort_fields {
40
+ options {
41
+ label
42
+ value
43
+ }
44
+ }
27
45
  }
28
46
  }
29
47
  `;
30
48
 
31
49
  export default {
32
50
  getCategoryContentQuery: GET_CATEGORY_CONTENT,
33
- getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY
51
+ getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
52
+ getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS
34
53
  };
@@ -1,8 +1,9 @@
1
1
  import { gql } from '@apollo/client';
2
2
 
3
3
  export const CategoryFragment = gql`
4
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
4
5
  fragment CategoryFragment on CategoryTree {
5
- id
6
+ uid
6
7
  meta_title
7
8
  meta_keywords
8
9
  meta_description
@@ -28,7 +29,8 @@ export const ProductsFragment = gql`
28
29
  url
29
30
  }
30
31
  stock_status
31
- type_id
32
+ rating_summary
33
+ __typename
32
34
  url_key
33
35
  }
34
36
  page_info {
@@ -21,7 +21,7 @@ import DEFAULT_OPERATIONS from './category.gql';
21
21
  * @kind function
22
22
  *
23
23
  * @param {object} props
24
- * @param {number} props.id - Category Id.
24
+ * @param {String} props.id - Category uid.
25
25
  * @param {GraphQLAST} props.operations.getCategoryQuery - Fetches category using a server query
26
26
  * @param {GraphQLAST} props.operations.getFilterInputsQuery - Fetches "allowed" filters using a server query
27
27
  * @param {GraphQLAST} props.queries.getStoreConfig - Fetches store configuration using a server query
@@ -133,14 +133,14 @@ export const useCategory = props => {
133
133
  newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
134
134
  });
135
135
 
136
- // Use the category id for the current category page regardless of the
136
+ // Use the category uid for the current category page regardless of the
137
137
  // applied filters. Follow-up in PWA-404.
138
- newFilters['category_id'] = { eq: String(id) };
138
+ newFilters['category_uid'] = { eq: id };
139
139
 
140
140
  runQuery({
141
141
  variables: {
142
142
  currentPage: Number(currentPage),
143
- id: Number(id),
143
+ id: id,
144
144
  filters: newFilters,
145
145
  pageSize: Number(pageSize),
146
146
  sort: { [currentSort.sortAttribute]: currentSort.sortDirection }
@@ -201,8 +201,10 @@ export const useCategory = props => {
201
201
 
202
202
  const categoryData = categoryLoading && !data ? null : data;
203
203
  const metaDescription =
204
- data && data.category && data.category.meta_description
205
- ? data.category.meta_description
204
+ data &&
205
+ data.categories.items[0] &&
206
+ data.categories.items[0].meta_description
207
+ ? data.categories.items[0].meta_description
206
208
  : '';
207
209
 
208
210
  // When only categoryLoading is involved, noProductsFound component flashes for a moment
@@ -24,7 +24,8 @@ export const useCategoryContent = props => {
24
24
 
25
25
  const {
26
26
  getCategoryContentQuery,
27
- getProductFiltersByCategoryQuery
27
+ getProductFiltersByCategoryQuery,
28
+ getCategoryAvailableSortMethodsQuery
28
29
  } = operations;
29
30
 
30
31
  const placeholderItems = Array.from({ length: pageSize }).fill(null);
@@ -37,6 +38,14 @@ export const useCategoryContent = props => {
37
38
  }
38
39
  );
39
40
 
41
+ const [getSortMethods, { data: sortData }] = useLazyQuery(
42
+ getCategoryAvailableSortMethodsQuery,
43
+ {
44
+ fetchPolicy: 'cache-and-network',
45
+ nextFetchPolicy: 'cache-first'
46
+ }
47
+ );
48
+
40
49
  const { data: categoryData } = useQuery(getCategoryContentQuery, {
41
50
  fetchPolicy: 'cache-and-network',
42
51
  nextFetchPolicy: 'cache-first',
@@ -58,18 +67,36 @@ export const useCategoryContent = props => {
58
67
  }
59
68
  }, [categoryId, getFilters]);
60
69
 
70
+ useEffect(() => {
71
+ if (categoryId) {
72
+ getSortMethods({
73
+ variables: {
74
+ categoryIdFilter: {
75
+ in: categoryId
76
+ }
77
+ }
78
+ });
79
+ }
80
+ }, [categoryId, getSortMethods]);
81
+
61
82
  const filters = filterData ? filterData.products.aggregations : null;
62
83
  const items = data ? data.products.items : placeholderItems;
63
84
  const totalPagesFromData = data
64
85
  ? data.products.page_info.total_pages
65
86
  : null;
66
87
  const totalCount = data ? data.products.total_count : null;
67
- const categoryName = categoryData ? categoryData.category.name : null;
88
+ const categoryName = categoryData
89
+ ? categoryData.categories.items[0].name
90
+ : null;
68
91
  const categoryDescription = categoryData
69
- ? categoryData.category.description
92
+ ? categoryData.categories.items[0].description
93
+ : null;
94
+ const availableSortMethods = sortData
95
+ ? sortData.products.sort_fields.options
70
96
  : null;
71
97
 
72
98
  return {
99
+ availableSortMethods,
73
100
  categoryName,
74
101
  categoryDescription,
75
102
  filters,
@@ -13,7 +13,6 @@ const isNonDefaultCategory = category => Boolean(category.parentId);
13
13
  * @param {number} props.categoryId - The ID of the category that has no products.
14
14
  *
15
15
  * @returns {object}
16
- * @param {array} recommendedCategories - A list of categories for the UI to recommend.
17
16
  */
18
17
  export const useNoProductsFound = props => {
19
18
  const { categoryId } = props;
@@ -4,8 +4,9 @@ import { ProductDetailsFragment } from './productDetailFragment.gql';
4
4
 
5
5
  export const GET_STORE_CONFIG_DATA = gql`
6
6
  query getStoreConfigData {
7
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
7
8
  storeConfig {
8
- id
9
+ store_code
9
10
  product_url_suffix
10
11
  }
11
12
  }
@@ -3,11 +3,11 @@ import { gql } from '@apollo/client';
3
3
  export const ProductDetailsFragment = gql`
4
4
  fragment ProductDetailsFragment on ProductInterface {
5
5
  __typename
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
7
  categories {
7
- id
8
8
  uid
9
9
  breadcrumbs {
10
- category_id
10
+ category_uid
11
11
  }
12
12
  }
13
13
  description {
@@ -15,10 +15,8 @@ export const ProductDetailsFragment = gql`
15
15
  }
16
16
  id
17
17
  uid
18
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
18
19
  media_gallery_entries {
19
- # id is deprecated and unused in our code, but lint rules require we
20
- # request it if available
21
- id
22
20
  uid
23
21
  label
24
22
  position
@@ -41,12 +39,43 @@ export const ProductDetailsFragment = gql`
41
39
  }
42
40
  stock_status
43
41
  url_key
42
+ custom_attributes {
43
+ selected_attribute_options {
44
+ attribute_option {
45
+ uid
46
+ label
47
+ is_default
48
+ }
49
+ }
50
+ entered_attribute_value {
51
+ value
52
+ }
53
+ attribute_metadata {
54
+ uid
55
+ code
56
+ label
57
+ attribute_labels {
58
+ store_code
59
+ label
60
+ }
61
+ data_type
62
+ is_system
63
+ is_visible_on_front
64
+ entity_type
65
+ ui_input {
66
+ ui_input_type
67
+ is_html_allowed
68
+ }
69
+ }
70
+ }
44
71
  ... on ConfigurableProduct {
72
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
45
73
  configurable_options {
46
74
  attribute_code
47
75
  attribute_id
48
- id
76
+ uid
49
77
  label
78
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
50
79
  values {
51
80
  uid
52
81
  default_label
@@ -67,13 +96,11 @@ export const ProductDetailsFragment = gql`
67
96
  code
68
97
  value_index
69
98
  }
99
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
70
100
  product {
71
- id
72
101
  uid
102
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
73
103
  media_gallery_entries {
74
- # id is deprecated and unused in our code, but lint rules require we
75
- # request it if available
76
- id
77
104
  uid
78
105
  disabled
79
106
  file
@@ -90,6 +117,35 @@ export const ProductDetailsFragment = gql`
90
117
  }
91
118
  }
92
119
  }
120
+ custom_attributes {
121
+ selected_attribute_options {
122
+ attribute_option {
123
+ uid
124
+ label
125
+ is_default
126
+ }
127
+ }
128
+ entered_attribute_value {
129
+ value
130
+ }
131
+ attribute_metadata {
132
+ uid
133
+ code
134
+ label
135
+ attribute_labels {
136
+ store_code
137
+ label
138
+ }
139
+ data_type
140
+ is_system
141
+ is_visible_on_front
142
+ entity_type
143
+ ui_input {
144
+ ui_input_type
145
+ is_html_allowed
146
+ }
147
+ }
148
+ }
93
149
  }
94
150
  }
95
151
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_PAGE_SIZE = gql`
4
4
  query getPageSize {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  grid_per_page
8
9
  }
9
10
  }
@@ -57,7 +58,7 @@ export const PRODUCT_SEARCH = gql`
57
58
  url
58
59
  }
59
60
  stock_status
60
- type_id
61
+ __typename
61
62
  url_key
62
63
  }
63
64
  page_info {
@@ -81,9 +82,23 @@ export const GET_FILTER_INPUTS = gql`
81
82
  }
82
83
  `;
83
84
 
85
+ export const GET_SEARCH_AVAILABLE_SORT_METHODS = gql`
86
+ query getSearchAvailableSortMethods($search: String!) {
87
+ products(search: $search) {
88
+ sort_fields {
89
+ options {
90
+ label
91
+ value
92
+ }
93
+ }
94
+ }
95
+ }
96
+ `;
97
+
84
98
  export default {
85
99
  getFilterInputsQuery: GET_FILTER_INPUTS,
86
100
  getPageSize: GET_PAGE_SIZE,
87
101
  getProductFiltersBySearchQuery: GET_PRODUCT_FILTERS_BY_SEARCH,
102
+ getSearchAvailableSortMethods: GET_SEARCH_AVAILABLE_SORT_METHODS,
88
103
  productSearchQuery: PRODUCT_SEARCH
89
104
  };
@@ -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