@graphcommerce/magento-product 9.0.0-canary.58 → 9.0.0-canary.60

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.60
4
+
5
+ ## 9.0.0-canary.59
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2309](https://github.com/graphcommerce-org/graphcommerce/pull/2309) [`1fe4090`](https://github.com/graphcommerce-org/graphcommerce/commit/1fe409029671b841e582406251e45a9555fc78f9) - Hide SortChip or SortSection when there is only a single filter option. ([@Renzovh](https://github.com/Renzovh))
10
+
3
11
  ## 9.0.0-canary.58
4
12
 
5
13
  ### Patch Changes
@@ -19,6 +19,8 @@ export function ProductFiltersProSortChip(props: ProductListActionSortProps) {
19
19
  const { submit, form } = useProductFiltersPro()
20
20
  const { options, showReset, selected, selectedLabel } = useProductFiltersProSort(props)
21
21
 
22
+ if ((options.length ?? 0) <= 1) return null
23
+
22
24
  return (
23
25
  <ChipOverlayOrPopper
24
26
  {...rest}
@@ -13,6 +13,8 @@ export function ProductFiltersProSortSection(props: ProductFiltersProSortSection
13
13
  const { form } = useProductFiltersPro()
14
14
  const { options, showReset, selected } = useProductFiltersProSort(props)
15
15
 
16
+ if ((options.length ?? 0) <= 1) return null
17
+
16
18
  return (
17
19
  <ActionCardAccordion
18
20
  sx={sx}
@@ -36,7 +36,9 @@ export function useProductFiltersProSort(props: ProductListActionSortProps) {
36
36
 
37
37
  const conf = useQuery(StoreConfigDocument).data?.storeConfig
38
38
  const defaultSortBy = (
39
- category ? category.default_sort_by ?? conf?.catalog_default_sort_by ?? 'position' : 'relevance'
39
+ category
40
+ ? (category.default_sort_by ?? conf?.catalog_default_sort_by ?? 'position')
41
+ : 'relevance'
40
42
  ) as ProductFilterParams['sort']
41
43
 
42
44
  const formSort = useWatch({ control, name: 'sort' })
@@ -20,7 +20,7 @@ export function parseParams(
20
20
  const typeMap = filterTypes
21
21
 
22
22
  let error = false
23
- query.reduce<string | undefined>((param, value) => {
23
+ query.map(decodeURI).reduce<string | undefined>((param, value) => {
24
24
  // We parse everything in pairs, every second loop we parse
25
25
  if (!param || param === 'q') return value
26
26
 
@@ -1,8 +1,8 @@
1
1
  import { cloneDeep, useQuery } from '@graphcommerce/graphql'
2
2
  import { StoreConfigDocument, StoreConfigQuery } from '@graphcommerce/magento-store'
3
+ import { ProductListQueryVariables } from '../ProductList/ProductList.gql'
3
4
  import { CategoryDefaultFragment } from './CategoryDefault.gql'
4
5
  import { ProductListParams } from './filterTypes'
5
- import { ProductListQueryVariables } from '../ProductList/ProductList.gql'
6
6
 
7
7
  export function useProductListApplyCategoryDefaults(
8
8
  params: ProductListParams | undefined,
@@ -66,3 +66,9 @@ export async function productListApplyCategoryDefaults(
66
66
 
67
67
  return newParams
68
68
  }
69
+
70
+ export function categoryDefaultsToProductListFilters(
71
+ variables: ProductListQueryVariables | undefined,
72
+ ): ProductListQueryVariables {
73
+ return { ...variables, filters: { category_uid: variables?.filters?.category_uid } }
74
+ }
@@ -1,6 +1,5 @@
1
1
  import { debounce } from '@graphcommerce/ecommerce-ui'
2
2
  import {
3
- ApolloQueryResult,
4
3
  ApolloClient,
5
4
  useQuery,
6
5
  useInContextQuery,
@@ -9,7 +8,12 @@ import {
9
8
  import { StoreConfigDocument } from '@graphcommerce/magento-store'
10
9
  import { showPageLoadIndicator } from '@graphcommerce/next-ui'
11
10
  import { useEventCallback } from '@mui/material'
12
- import { FilterFormProviderProps, ProductFiltersDocument } from '../components'
11
+ import {
12
+ FilterFormProviderProps,
13
+ ProductFiltersDocument,
14
+ ProductFiltersQuery,
15
+ ProductFiltersQueryVariables,
16
+ } from '../components'
13
17
  import {
14
18
  ProductListDocument,
15
19
  ProductListQuery,
@@ -20,6 +24,7 @@ import { ProductListParams, toProductListParams } from '../components/ProductLis
20
24
  import { useRouterFilterParams } from '../components/ProductListItems/filteredProductList'
21
25
  import {
22
26
  productListApplyCategoryDefaults,
27
+ categoryDefaultsToProductListFilters,
23
28
  useProductListApplyCategoryDefaults,
24
29
  } from '../components/ProductListItems/productListApplyCategoryDefaults'
25
30
 
@@ -30,6 +35,7 @@ type Next = Parameters<NonNullable<FilterFormProviderProps['handleSubmit']>>[1]
30
35
  export const prefetchProductList = debounce(
31
36
  async (
32
37
  variables: ProductListQueryVariables,
38
+ filtersVariables: ProductFiltersQueryVariables,
33
39
  next: Next,
34
40
  client: ApolloClient<any>,
35
41
  shallow: boolean,
@@ -47,8 +53,7 @@ export const prefetchProductList = debounce(
47
53
  const productFilters = client.query({
48
54
  query: ProductFiltersDocument,
49
55
  variables: {
50
- filters: { category_uid: variables.filters?.category_uid },
51
- search: variables.search,
56
+ ...filtersVariables,
52
57
  context,
53
58
  },
54
59
  })
@@ -91,16 +96,23 @@ export const prefetchProductList = debounce(
91
96
  * - Handles customer specific product list queries
92
97
  */
93
98
  export function useProductList<
94
- T extends ProductListQuery & {
95
- params?: ProductListParams
96
- category?: CategoryDefaultFragment | null | undefined
97
- },
99
+ T extends ProductListQuery &
100
+ ProductFiltersQuery & {
101
+ params?: ProductListParams
102
+ category?: CategoryDefaultFragment | null | undefined
103
+ },
98
104
  >(props: T) {
99
105
  const { category } = props
100
106
  const { params, shallow } = useRouterFilterParams(props)
101
107
  const variables = useProductListApplyCategoryDefaults(params, category)
102
108
 
103
109
  const result = useInContextQuery(ProductListDocument, { variables, skip: !shallow }, props)
110
+ const filters = useInContextQuery(
111
+ ProductFiltersDocument,
112
+ { variables: categoryDefaultsToProductListFilters(variables), skip: !shallow },
113
+ props,
114
+ )
115
+
104
116
  const storeConfig = useQuery(StoreConfigDocument).data
105
117
 
106
118
  const handleSubmit: NonNullable<FilterFormProviderProps['handleSubmit']> = useEventCallback(
@@ -115,9 +127,22 @@ export function useProductList<
115
127
 
116
128
  const shallowNow =
117
129
  JSON.stringify(vars.filters?.category_uid) === JSON.stringify(params?.filters.category_uid)
118
- await prefetchProductList(vars, next, result.client, shallowNow)
130
+ await prefetchProductList(
131
+ vars,
132
+ categoryDefaultsToProductListFilters(vars),
133
+ next,
134
+ result.client,
135
+ shallowNow,
136
+ )
119
137
  },
120
138
  )
121
139
 
122
- return { ...props, ...result.data, params, mask: result.mask, handleSubmit }
140
+ return {
141
+ ...props,
142
+ filters: filters.data.filters,
143
+ ...result.data,
144
+ params,
145
+ mask: result.mask,
146
+ handleSubmit,
147
+ }
123
148
  }
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": "9.0.0-canary.58",
5
+ "version": "9.0.0-canary.60",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,19 +18,19 @@
18
18
  "typescript": "5.5.3"
19
19
  },
20
20
  "peerDependencies": {
21
- "@graphcommerce/ecommerce-ui": "^9.0.0-canary.58",
22
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.58",
23
- "@graphcommerce/framer-next-pages": "^9.0.0-canary.58",
24
- "@graphcommerce/framer-scroller": "^9.0.0-canary.58",
25
- "@graphcommerce/graphql": "^9.0.0-canary.58",
26
- "@graphcommerce/graphql-mesh": "^9.0.0-canary.58",
27
- "@graphcommerce/image": "^9.0.0-canary.58",
28
- "@graphcommerce/magento-cart": "^9.0.0-canary.58",
29
- "@graphcommerce/magento-category": "^9.0.0-canary.58",
30
- "@graphcommerce/magento-store": "^9.0.0-canary.58",
31
- "@graphcommerce/next-ui": "^9.0.0-canary.58",
32
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.58",
33
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.58",
21
+ "@graphcommerce/ecommerce-ui": "^9.0.0-canary.60",
22
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.60",
23
+ "@graphcommerce/framer-next-pages": "^9.0.0-canary.60",
24
+ "@graphcommerce/framer-scroller": "^9.0.0-canary.60",
25
+ "@graphcommerce/graphql": "^9.0.0-canary.60",
26
+ "@graphcommerce/graphql-mesh": "^9.0.0-canary.60",
27
+ "@graphcommerce/image": "^9.0.0-canary.60",
28
+ "@graphcommerce/magento-cart": "^9.0.0-canary.60",
29
+ "@graphcommerce/magento-category": "^9.0.0-canary.60",
30
+ "@graphcommerce/magento-store": "^9.0.0-canary.60",
31
+ "@graphcommerce/next-ui": "^9.0.0-canary.60",
32
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.60",
33
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.60",
34
34
  "@lingui/core": "^4.2.1",
35
35
  "@lingui/macro": "^4.2.1",
36
36
  "@lingui/react": "^4.2.1",