@graphcommerce/magento-product 8.1.0-canary.9 → 9.0.0-canary.55

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 (78) hide show
  1. package/Api/ProductListItem.graphql +1 -2
  2. package/Api/ProductPageItem.graphql +1 -1
  3. package/CHANGELOG.md +113 -0
  4. package/Config.graphqls +13 -0
  5. package/components/AddProductsToCart/AddProductsToCartButton.tsx +3 -2
  6. package/components/AddProductsToCart/AddProductsToCartFab.tsx +2 -2
  7. package/components/AddProductsToCart/AddProductsToCartForm.tsx +31 -28
  8. package/components/AddProductsToCart/AddProductsToCartSnackbar.tsx +25 -16
  9. package/components/AddProductsToCart/UseAddProductsToCartAction.graphql +1 -1
  10. package/components/AddProductsToCart/findAddedItems.ts +1 -4
  11. package/components/AddProductsToCart/useAddProductsToCartAction.ts +2 -1
  12. package/components/AddProductsToCart/useFormAddProductsToCart.ts +1 -2
  13. package/components/JsonLdProduct/JsonLdProduct.graphql +1 -1
  14. package/components/JsonLdProduct/ProductPageJsonLd.tsx +1 -1
  15. package/components/ProductAddToCart/ProductAddToCart.tsx +6 -8
  16. package/components/ProductCustomizable/ProductCustomizable.graphql +1 -1
  17. package/components/ProductCustomizable/index.ts +1 -0
  18. package/components/ProductCustomizable/productCustomizableSelectors.ts +59 -0
  19. package/components/ProductFiltersPro/PriceSlider.tsx +1 -2
  20. package/components/ProductFiltersPro/ProductFilterEqualChip.tsx +1 -1
  21. package/components/ProductFiltersPro/ProductFilterEqualSection.tsx +2 -2
  22. package/components/ProductFiltersPro/ProductFilterRangeChip.tsx +1 -1
  23. package/components/ProductFiltersPro/ProductFilterRangeSection.tsx +1 -1
  24. package/components/ProductFiltersPro/ProductFiltersPro.tsx +103 -19
  25. package/components/ProductFiltersPro/ProductFiltersProAggregations.tsx +31 -18
  26. package/components/ProductFiltersPro/ProductFiltersProAllFiltersChip.tsx +6 -10
  27. package/components/ProductFiltersPro/ProductFiltersProAllFiltersSidebar.tsx +18 -8
  28. package/components/ProductFiltersPro/ProductFiltersProCategorySection.tsx +130 -0
  29. package/components/ProductFiltersPro/ProductFiltersProChips.tsx +10 -8
  30. package/components/ProductFiltersPro/ProductFiltersProClearAll.tsx +4 -16
  31. package/components/ProductFiltersPro/ProductFiltersProLayoutSidebar.tsx +15 -7
  32. package/components/ProductFiltersPro/ProductFiltersProLimitSection.tsx +5 -2
  33. package/components/ProductFiltersPro/ProductFiltersProNoResults.tsx +79 -0
  34. package/components/ProductFiltersPro/ProductFiltersProSortChip.tsx +1 -1
  35. package/components/ProductFiltersPro/ProductFiltersProSortDirectionArrow.tsx +2 -4
  36. package/components/ProductFiltersPro/ProductFiltersProSortSection.tsx +7 -2
  37. package/components/ProductFiltersPro/activeAggregations.ts +5 -9
  38. package/components/ProductFiltersPro/applyAggregationCount.ts +14 -8
  39. package/components/ProductFiltersPro/index.ts +9 -0
  40. package/components/ProductFiltersPro/{useClearAllFiltersHandler.ts → useProductFiltersProClearAllAction.ts} +1 -1
  41. package/components/ProductFiltersPro/useProductFiltersProHasFiltersApplied.ts +21 -0
  42. package/components/ProductFiltersPro/useProductFiltersProSort.tsx +4 -2
  43. package/components/ProductList/ProductList.graphql +8 -5
  44. package/components/ProductListCount/ProductListCount.tsx +3 -1
  45. package/components/ProductListFilters/ProductFilters.graphql +7 -2
  46. package/components/ProductListFilters/ProductListFilters.graphql +1 -1
  47. package/components/ProductListFiltersContainer/ProductListFiltersContainer.tsx +2 -4
  48. package/components/ProductListItem/ProductDiscountLabel.tsx +2 -3
  49. package/components/ProductListItem/ProductListItem.tsx +3 -3
  50. package/components/ProductListItem/ProductListItemTitleAndPrice.tsx +18 -15
  51. package/components/ProductListItems/ProductListItemsBase.tsx +65 -23
  52. package/components/ProductListItems/filterTypes.tsx +14 -5
  53. package/components/ProductListItems/filteredProductList.tsx +23 -0
  54. package/components/ProductListItems/productListApplyCategoryDefaults.ts +44 -4
  55. package/components/ProductListItems/renderer.tsx +8 -2
  56. package/components/ProductListPagination/ProductListPagination.tsx +39 -20
  57. package/components/ProductListPrice/ProductListPrice.tsx +9 -4
  58. package/components/ProductListSuggestions/ProductListSuggestions.graphql +5 -0
  59. package/components/ProductListSuggestions/ProductListSuggestions.tsx +42 -0
  60. package/components/ProductPageBreadcrumb/ProductPageBreadcrumb.graphql +3 -0
  61. package/components/ProductPageBreadcrumb/ProductPageBreadcrumb.tsx +3 -0
  62. package/components/ProductPageBreadcrumb/ProductPageBreadcrumbs.tsx +40 -0
  63. package/components/ProductPageBreadcrumb/index.ts +1 -0
  64. package/components/ProductPageDescription/ComplexTextValue.graphql +1 -1
  65. package/components/ProductPageDescription/ProductPageDescription.tsx +1 -1
  66. package/components/ProductPageGallery/ProductImage.graphql +1 -0
  67. package/components/ProductPageGallery/ProductPageGallery.tsx +14 -8
  68. package/components/ProductPagePrice/ProductPagePrice.graphql +0 -6
  69. package/components/ProductPagePrice/ProductPagePrice.tsx +19 -12
  70. package/components/ProductPagePrice/ProductPagePriceTiers.tsx +4 -3
  71. package/components/ProductPagePrice/useCustomizableOptionPrice.ts +11 -53
  72. package/components/ProductShortDescription/ProductShortDescription.tsx +2 -0
  73. package/components/ProductWeight/ProductWeight.tsx +12 -9
  74. package/components/index.ts +2 -0
  75. package/hooks/useProductList.ts +123 -0
  76. package/hooks/useProductListLink.ts +6 -3
  77. package/index.ts +1 -0
  78. package/package.json +14 -13
@@ -0,0 +1,123 @@
1
+ import { debounce } from '@graphcommerce/ecommerce-ui'
2
+ import {
3
+ ApolloQueryResult,
4
+ ApolloClient,
5
+ useQuery,
6
+ useInContextQuery,
7
+ getInContextInput,
8
+ } from '@graphcommerce/graphql'
9
+ import { StoreConfigDocument } from '@graphcommerce/magento-store'
10
+ import { showPageLoadIndicator } from '@graphcommerce/next-ui'
11
+ import { useEventCallback } from '@mui/material'
12
+ import { FilterFormProviderProps, ProductFiltersDocument } from '../components'
13
+ import {
14
+ ProductListDocument,
15
+ ProductListQuery,
16
+ ProductListQueryVariables,
17
+ } from '../components/ProductList/ProductList.gql'
18
+ import { CategoryDefaultFragment } from '../components/ProductListItems/CategoryDefault.gql'
19
+ import { ProductListParams, toProductListParams } from '../components/ProductListItems/filterTypes'
20
+ import { useRouterFilterParams } from '../components/ProductListItems/filteredProductList'
21
+ import {
22
+ productListApplyCategoryDefaults,
23
+ useProductListApplyCategoryDefaults,
24
+ } from '../components/ProductListItems/productListApplyCategoryDefaults'
25
+
26
+ const productListQueries: Array<Promise<any>> = []
27
+
28
+ type Next = Parameters<NonNullable<FilterFormProviderProps['handleSubmit']>>[1]
29
+
30
+ export const prefetchProductList = debounce(
31
+ async (
32
+ variables: ProductListQueryVariables,
33
+ next: Next,
34
+ client: ApolloClient<any>,
35
+ shallow: boolean,
36
+ ) => {
37
+ if (!shallow) return next(shallow)
38
+
39
+ showPageLoadIndicator.set(true)
40
+
41
+ const context = getInContextInput(client)
42
+ const productList = client.query({
43
+ query: ProductListDocument,
44
+ variables: { ...variables, context },
45
+ })
46
+
47
+ const productFilters = client.query({
48
+ query: ProductFiltersDocument,
49
+ variables: {
50
+ filters: { category_uid: variables.filters?.category_uid },
51
+ search: variables.search,
52
+ context,
53
+ },
54
+ })
55
+
56
+ const both = Promise.all([productList, productFilters])
57
+
58
+ // Push the query to the queue array.
59
+ productListQueries.push(both)
60
+
61
+ // Since we're waiting here the form will be submitting for longer.
62
+ await both
63
+
64
+ const includes = productListQueries.includes(both)
65
+
66
+ // Remove all requests that are before the current request
67
+ const index = productListQueries.indexOf(both)
68
+ if (index > -1) {
69
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
70
+ productListQueries.splice(0, index + 1)
71
+ }
72
+
73
+ if (productListQueries.length === 0) showPageLoadIndicator.set(false)
74
+
75
+ if (includes) {
76
+ // todo: When navigating a category, it should now be a shallow route
77
+
78
+ // If the resolved request is still in the array, it may be rendered (URL may be updated)
79
+ await next(shallow)
80
+ }
81
+
82
+ return undefined
83
+ },
84
+ 200,
85
+ // the maxWait is now set to a somewhat shorter time than the average query time.
86
+ { leading: true, maxWait: 700, trailing: true },
87
+ )
88
+
89
+ /**
90
+ * - Handles shallow routing requests
91
+ * - Handles customer specific product list queries
92
+ */
93
+ export function useProductList<
94
+ T extends ProductListQuery & {
95
+ params?: ProductListParams
96
+ category?: CategoryDefaultFragment | null | undefined
97
+ },
98
+ >(props: T) {
99
+ const { category } = props
100
+ const { params, shallow } = useRouterFilterParams(props)
101
+ const variables = useProductListApplyCategoryDefaults(params, category)
102
+
103
+ const result = useInContextQuery(ProductListDocument, { variables, skip: !shallow }, props)
104
+ const storeConfig = useQuery(StoreConfigDocument).data
105
+
106
+ const handleSubmit: NonNullable<FilterFormProviderProps['handleSubmit']> = useEventCallback(
107
+ async (formValues, next) => {
108
+ if (!storeConfig) return
109
+
110
+ const vars = await productListApplyCategoryDefaults(
111
+ toProductListParams(formValues),
112
+ storeConfig,
113
+ category,
114
+ )
115
+
116
+ const shallowNow =
117
+ JSON.stringify(vars.filters?.category_uid) === JSON.stringify(params?.filters.category_uid)
118
+ await prefetchProductList(vars, next, result.client, shallowNow)
119
+ },
120
+ )
121
+
122
+ return { ...props, ...result.data, params, mask: result.mask, handleSubmit }
123
+ }
@@ -8,11 +8,14 @@ import {
8
8
  } from '../components/ProductListItems/filterTypes'
9
9
 
10
10
  export function productListLinkFromFilter(props: ProductFilterParams): string {
11
- const { url, sort, dir, currentPage, pageSize, filters: incoming } = props
11
+ const { url, sort, dir, currentPage, pageSize, filters: incoming, search } = props
12
12
  const isSearch = url.startsWith('search')
13
13
  const filters = isSearch ? incoming : { ...incoming, category_uid: undefined }
14
14
  const uid = incoming?.category_uid?.eq || incoming?.category_uid?.in?.[0]
15
15
 
16
+ let urlBase = url
17
+ if (isSearch) urlBase = search ? `search/${search}` : 'search'
18
+
16
19
  // base url path generation
17
20
  let paginateSort = ``
18
21
  let query = ``
@@ -38,9 +41,9 @@ export function productListLinkFromFilter(props: ProductFilterParams): string {
38
41
 
39
42
  // it's a category with filters, use the /c/ route.
40
43
  if (query && !isSearch)
41
- return `/c/${url}${paginateSort}/q${uid ? `/category_uid/${uid}` : ''}${query}`
44
+ return `/c/${urlBase}${paginateSort}/q${uid ? `/category_uid/${uid}` : ''}${query}`
42
45
 
43
- return query ? `/${url}${paginateSort}/q${query}` : `/${url}${paginateSort}`
46
+ return query ? `/${urlBase}${paginateSort}/q${query}` : `/${urlBase}${paginateSort}`
44
47
  }
45
48
 
46
49
  export function productListLink(props: ProductListParams): string {
package/index.ts CHANGED
@@ -5,4 +5,5 @@ export * from './hooks/useProductLink'
5
5
  export * from './hooks/useProductListLink'
6
6
  export * from './hooks/useProductListLinkReplace'
7
7
  export * from './hooks/useProductListParamsContext'
8
+ export * from './hooks/useProductList'
8
9
  export * from './hooks/ProductLink.gql'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.9",
5
+ "version": "9.0.0-canary.55",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,18 +18,19 @@
18
18
  "typescript": "5.3.3"
19
19
  },
20
20
  "peerDependencies": {
21
- "@graphcommerce/ecommerce-ui": "^8.1.0-canary.9",
22
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
23
- "@graphcommerce/framer-next-pages": "^8.1.0-canary.9",
24
- "@graphcommerce/framer-scroller": "^8.1.0-canary.9",
25
- "@graphcommerce/graphql": "^8.1.0-canary.9",
26
- "@graphcommerce/graphql-mesh": "^8.1.0-canary.9",
27
- "@graphcommerce/image": "^8.1.0-canary.9",
28
- "@graphcommerce/magento-cart": "^8.1.0-canary.9",
29
- "@graphcommerce/magento-store": "^8.1.0-canary.9",
30
- "@graphcommerce/next-ui": "^8.1.0-canary.9",
31
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
32
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
21
+ "@graphcommerce/ecommerce-ui": "^9.0.0-canary.55",
22
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.55",
23
+ "@graphcommerce/framer-next-pages": "^9.0.0-canary.55",
24
+ "@graphcommerce/framer-scroller": "^9.0.0-canary.55",
25
+ "@graphcommerce/graphql": "^9.0.0-canary.55",
26
+ "@graphcommerce/graphql-mesh": "^9.0.0-canary.55",
27
+ "@graphcommerce/image": "^9.0.0-canary.55",
28
+ "@graphcommerce/magento-cart": "^9.0.0-canary.55",
29
+ "@graphcommerce/magento-category": "^9.0.0-canary.55",
30
+ "@graphcommerce/magento-store": "^9.0.0-canary.55",
31
+ "@graphcommerce/next-ui": "^9.0.0-canary.55",
32
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.55",
33
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.55",
33
34
  "@lingui/core": "^4.2.1",
34
35
  "@lingui/macro": "^4.2.1",
35
36
  "@lingui/react": "^4.2.1",