@graphcommerce/magento-product 8.1.0-canary.5 → 8.1.0-canary.52
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.
- package/Api/ProductListItem.graphql +1 -2
- package/Api/ProductPageItem.graphql +1 -1
- package/CHANGELOG.md +115 -0
- package/Config.graphqls +13 -0
- package/components/AddProductsToCart/AddProductsToCartButton.tsx +3 -2
- package/components/AddProductsToCart/AddProductsToCartFab.tsx +2 -2
- package/components/AddProductsToCart/AddProductsToCartForm.tsx +31 -28
- package/components/AddProductsToCart/AddProductsToCartSnackbar.tsx +25 -16
- package/components/AddProductsToCart/UseAddProductsToCartAction.graphql +1 -1
- package/components/AddProductsToCart/findAddedItems.ts +1 -4
- package/components/AddProductsToCart/useAddProductsToCartAction.ts +2 -1
- package/components/AddProductsToCart/useFormAddProductsToCart.ts +1 -2
- package/components/JsonLdProduct/JsonLdProduct.graphql +1 -1
- package/components/JsonLdProduct/ProductPageJsonLd.tsx +1 -1
- package/components/ProductAddToCart/ProductAddToCart.tsx +6 -8
- package/components/ProductCustomizable/ProductCustomizable.graphql +1 -1
- package/components/ProductCustomizable/index.ts +1 -0
- package/components/ProductCustomizable/productCustomizableSelectors.ts +59 -0
- package/components/ProductFiltersPro/PriceSlider.tsx +1 -2
- package/components/ProductFiltersPro/ProductFilterEqualChip.tsx +1 -1
- package/components/ProductFiltersPro/ProductFilterEqualSection.tsx +2 -2
- package/components/ProductFiltersPro/ProductFilterRangeChip.tsx +1 -1
- package/components/ProductFiltersPro/ProductFilterRangeSection.tsx +1 -1
- package/components/ProductFiltersPro/ProductFiltersPro.tsx +103 -19
- package/components/ProductFiltersPro/ProductFiltersProAggregations.tsx +31 -18
- package/components/ProductFiltersPro/ProductFiltersProAllFiltersChip.tsx +6 -10
- package/components/ProductFiltersPro/ProductFiltersProAllFiltersSidebar.tsx +18 -8
- package/components/ProductFiltersPro/ProductFiltersProCategorySection.tsx +130 -0
- package/components/ProductFiltersPro/ProductFiltersProChips.tsx +10 -8
- package/components/ProductFiltersPro/ProductFiltersProClearAll.tsx +4 -16
- package/components/ProductFiltersPro/ProductFiltersProLayoutSidebar.tsx +15 -7
- package/components/ProductFiltersPro/ProductFiltersProLimitSection.tsx +5 -2
- package/components/ProductFiltersPro/ProductFiltersProNoResults.tsx +79 -0
- package/components/ProductFiltersPro/ProductFiltersProSortChip.tsx +1 -1
- package/components/ProductFiltersPro/ProductFiltersProSortDirectionArrow.tsx +2 -4
- package/components/ProductFiltersPro/ProductFiltersProSortSection.tsx +7 -2
- package/components/ProductFiltersPro/activeAggregations.ts +5 -9
- package/components/ProductFiltersPro/applyAggregationCount.ts +14 -8
- package/components/ProductFiltersPro/index.ts +9 -0
- package/components/ProductFiltersPro/{useClearAllFiltersHandler.ts → useProductFiltersProClearAllAction.ts} +1 -1
- package/components/ProductFiltersPro/useProductFiltersProHasFiltersApplied.ts +21 -0
- package/components/ProductFiltersPro/useProductFiltersProSort.tsx +4 -2
- package/components/ProductList/ProductList.graphql +8 -5
- package/components/ProductListCount/ProductListCount.tsx +3 -1
- package/components/ProductListFilters/ProductFilters.graphql +7 -2
- package/components/ProductListFilters/ProductListFilters.graphql +1 -1
- package/components/ProductListFiltersContainer/ProductListFiltersContainer.tsx +2 -4
- package/components/ProductListItem/ProductDiscountLabel.tsx +2 -3
- package/components/ProductListItem/ProductListItem.tsx +3 -3
- package/components/ProductListItem/ProductListItemTitleAndPrice.tsx +18 -15
- package/components/ProductListItems/ProductListItemsBase.tsx +65 -23
- package/components/ProductListItems/filterTypes.tsx +14 -5
- package/components/ProductListItems/filteredProductList.tsx +23 -0
- package/components/ProductListItems/productListApplyCategoryDefaults.ts +44 -4
- package/components/ProductListItems/renderer.tsx +8 -2
- package/components/ProductListPagination/ProductListPagination.tsx +39 -20
- package/components/ProductListPrice/ProductListPrice.tsx +9 -4
- package/components/ProductListSuggestions/ProductListSuggestions.graphql +5 -0
- package/components/ProductListSuggestions/ProductListSuggestions.tsx +42 -0
- package/components/ProductPageBreadcrumb/ProductPageBreadcrumb.graphql +3 -0
- package/components/ProductPageBreadcrumb/ProductPageBreadcrumb.tsx +3 -0
- package/components/ProductPageBreadcrumb/ProductPageBreadcrumbs.tsx +40 -0
- package/components/ProductPageBreadcrumb/index.ts +1 -0
- package/components/ProductPageDescription/ComplexTextValue.graphql +1 -1
- package/components/ProductPageDescription/ProductPageDescription.tsx +1 -1
- package/components/ProductPageGallery/ProductImage.graphql +1 -0
- package/components/ProductPageGallery/ProductPageGallery.tsx +14 -8
- package/components/ProductPagePrice/ProductPagePrice.graphql +0 -6
- package/components/ProductPagePrice/ProductPagePrice.tsx +19 -12
- package/components/ProductPagePrice/ProductPagePriceTiers.tsx +4 -3
- package/components/ProductPagePrice/useCustomizableOptionPrice.ts +11 -53
- package/components/ProductShortDescription/ProductShortDescription.tsx +2 -0
- package/components/ProductStaticPaths/getProductStaticPaths.ts +2 -3
- package/components/ProductStaticPaths/getSitemapPaths.ts +3 -0
- package/components/ProductWeight/ProductWeight.tsx +12 -9
- package/components/index.ts +2 -0
- package/hooks/useProductList.ts +123 -0
- package/hooks/useProductListLink.ts +6 -3
- package/index.ts +1 -0
- package/package.json +14 -13
@@ -1,19 +1,22 @@
|
|
1
1
|
import { useQuery } from '@graphcommerce/graphql'
|
2
2
|
import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
3
|
-
import {
|
3
|
+
import { UnitFormat, UnitFormatProps } from '@graphcommerce/next-ui'
|
4
4
|
import { ProductWeightFragment } from './ProductWeight.gql'
|
5
5
|
|
6
|
-
export
|
7
|
-
|
6
|
+
export type ProductWeightProps = Omit<UnitFormatProps, 'unit'> & { product: ProductWeightFragment }
|
7
|
+
|
8
|
+
export function ProductWeight(props: ProductWeightProps) {
|
9
|
+
const { product, ...rest } = props
|
10
|
+
|
8
11
|
const { data: conf } = useQuery(StoreConfigDocument)
|
9
|
-
const unit = conf?.storeConfig?.weight_unit ?? ''
|
10
12
|
|
11
|
-
|
13
|
+
if (!product.weight) return null
|
14
|
+
|
15
|
+
const unit = conf?.storeConfig?.weight_unit === 'lbs' ? 'pound' : 'kilogram'
|
12
16
|
|
13
|
-
if (!numberFormatter || !weight) return null
|
14
17
|
return (
|
15
|
-
|
16
|
-
{
|
17
|
-
|
18
|
+
<UnitFormat unit={unit} {...rest}>
|
19
|
+
{product.weight}
|
20
|
+
</UnitFormat>
|
18
21
|
)
|
19
22
|
}
|
package/components/index.ts
CHANGED
@@ -41,3 +41,5 @@ export * from './ProductStaticPaths/getSitemapPaths'
|
|
41
41
|
export * from './ProductUpsells/UpsellProducts.gql'
|
42
42
|
export * from './ProductWeight/ProductWeight'
|
43
43
|
export * from './ProductListPrice'
|
44
|
+
export * from './ProductListSuggestions/ProductListSuggestions'
|
45
|
+
export * from './ProductListSuggestions/ProductListSuggestions.gql'
|
@@ -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/${
|
44
|
+
return `/c/${urlBase}${paginateSort}/q${uid ? `/category_uid/${uid}` : ''}${query}`
|
42
45
|
|
43
|
-
return query ? `/${
|
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
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.
|
5
|
+
"version": "8.1.0-canary.52",
|
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.
|
22
|
-
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.
|
23
|
-
"@graphcommerce/framer-next-pages": "^8.1.0-canary.
|
24
|
-
"@graphcommerce/framer-scroller": "^8.1.0-canary.
|
25
|
-
"@graphcommerce/graphql": "^8.1.0-canary.
|
26
|
-
"@graphcommerce/graphql-mesh": "^8.1.0-canary.
|
27
|
-
"@graphcommerce/image": "^8.1.0-canary.
|
28
|
-
"@graphcommerce/magento-cart": "^8.1.0-canary.
|
29
|
-
"@graphcommerce/magento-
|
30
|
-
"@graphcommerce/
|
31
|
-
"@graphcommerce/
|
32
|
-
"@graphcommerce/
|
21
|
+
"@graphcommerce/ecommerce-ui": "^8.1.0-canary.52",
|
22
|
+
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.52",
|
23
|
+
"@graphcommerce/framer-next-pages": "^8.1.0-canary.52",
|
24
|
+
"@graphcommerce/framer-scroller": "^8.1.0-canary.52",
|
25
|
+
"@graphcommerce/graphql": "^8.1.0-canary.52",
|
26
|
+
"@graphcommerce/graphql-mesh": "^8.1.0-canary.52",
|
27
|
+
"@graphcommerce/image": "^8.1.0-canary.52",
|
28
|
+
"@graphcommerce/magento-cart": "^8.1.0-canary.52",
|
29
|
+
"@graphcommerce/magento-category": "^8.1.0-canary.52",
|
30
|
+
"@graphcommerce/magento-store": "^8.1.0-canary.52",
|
31
|
+
"@graphcommerce/next-ui": "^8.1.0-canary.52",
|
32
|
+
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.52",
|
33
|
+
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.52",
|
33
34
|
"@lingui/core": "^4.2.1",
|
34
35
|
"@lingui/macro": "^4.2.1",
|
35
36
|
"@lingui/react": "^4.2.1",
|