@graphcommerce/magento-product 3.0.7 → 3.0.8
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 +12 -0
- package/components/ProductListFilters/FilterCheckboxType.tsx +4 -4
- package/components/ProductListFilters/FilterEqualType.tsx +7 -3
- package/components/ProductListFilters/FilterRangeType.tsx +9 -5
- package/components/ProductListLink/ProductListLink.tsx +4 -1
- package/components/ProductListSort/index.tsx +4 -4
- package/hooks/useProductListLinkReplace.ts +32 -0
- package/index.ts +1 -1
- package/package.json +3 -3
- package/hooks/useProductListLinkPush.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.8](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.7...@graphcommerce/magento-product@3.0.8) (2021-09-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **filter-range-type:** invalid filter value after browser back ([b1e0a78](https://github.com/ho-nl/m2-pwa/commit/b1e0a78bb92719fb0f23eef53053e825e78d7ed1))
|
|
12
|
+
* **filters:** only push first filter to the history ([bbe1ac5](https://github.com/ho-nl/m2-pwa/commit/bbe1ac5b629f8ed7798094d64a413d0c27519854))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
## [3.0.7](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.6...@graphcommerce/magento-product@3.0.7) (2021-09-30)
|
|
7
19
|
|
|
8
20
|
|
|
@@ -3,7 +3,7 @@ import { useChipMenuStyles, SvgImage, iconCloseCircle } from '@graphcommerce/nex
|
|
|
3
3
|
import { Chip, ChipProps } from '@material-ui/core'
|
|
4
4
|
import clsx from 'clsx'
|
|
5
5
|
import React from 'react'
|
|
6
|
-
import {
|
|
6
|
+
import { useProductListLinkReplace } from '../../hooks/useProductListLinkReplace'
|
|
7
7
|
import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
|
|
8
8
|
import ProductListLink from '../ProductListLink/ProductListLink'
|
|
9
9
|
import { FilterIn } from './FilterEqualType'
|
|
@@ -19,7 +19,7 @@ export default function FilterCheckboxType(props: FilterCheckboxTypeProps) {
|
|
|
19
19
|
const { params } = useProductListParamsContext()
|
|
20
20
|
const classes = useChipMenuStyles(props)
|
|
21
21
|
const currentFilter = params.filters[attribute_code]
|
|
22
|
-
const
|
|
22
|
+
const replaceRoute = useProductListLinkReplace({ scroll: false })
|
|
23
23
|
|
|
24
24
|
if (!options?.[0]) return null
|
|
25
25
|
|
|
@@ -34,7 +34,7 @@ export default function FilterCheckboxType(props: FilterCheckboxTypeProps) {
|
|
|
34
34
|
filters={{ ...params.filters, [attribute_code]: filter }}
|
|
35
35
|
currentPage={undefined}
|
|
36
36
|
noLink
|
|
37
|
-
link={{ scroll: false }}
|
|
37
|
+
link={{ scroll: false, replace: true }}
|
|
38
38
|
>
|
|
39
39
|
<Chip
|
|
40
40
|
variant='outlined'
|
|
@@ -47,7 +47,7 @@ export default function FilterCheckboxType(props: FilterCheckboxTypeProps) {
|
|
|
47
47
|
delete linkParams.currentPage
|
|
48
48
|
delete linkParams.filters[attribute_code]
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
replaceRoute(linkParams)
|
|
51
51
|
}
|
|
52
52
|
: undefined
|
|
53
53
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '@material-ui/core'
|
|
12
12
|
import React from 'react'
|
|
13
13
|
import { SetRequired } from 'type-fest'
|
|
14
|
-
import {
|
|
14
|
+
import { useProductListLinkReplace } from '../../hooks/useProductListLinkReplace'
|
|
15
15
|
import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
|
|
16
16
|
import ProductListLink from '../ProductListLink/ProductListLink'
|
|
17
17
|
import { ProductListFiltersFragment } from './ProductListFilters.gql'
|
|
@@ -86,12 +86,14 @@ export default function FilterEqualType(props: FilterEqualTypeProps) {
|
|
|
86
86
|
const { attribute_code, count, label, options, ...chipProps } = props
|
|
87
87
|
const { params } = useProductListParamsContext()
|
|
88
88
|
const classes = useFilterEqualStyles()
|
|
89
|
-
const
|
|
89
|
+
const replaceRoute = useProductListLinkReplace({ scroll: false })
|
|
90
90
|
|
|
91
91
|
const currentFilter: FilterEqualTypeInput = cloneDeep(params.filters[attribute_code]) ?? {
|
|
92
92
|
in: [],
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
const anyFilterActive = Object.keys(params?.filters ?? {}).length >= 1
|
|
96
|
+
|
|
95
97
|
const currentLabels =
|
|
96
98
|
options
|
|
97
99
|
?.filter((option) => option && currentFilter.in?.includes(option.value))
|
|
@@ -101,7 +103,8 @@ export default function FilterEqualType(props: FilterEqualTypeProps) {
|
|
|
101
103
|
const linkParams = cloneDeep(params)
|
|
102
104
|
delete linkParams.filters[attribute_code]
|
|
103
105
|
delete linkParams.currentPage
|
|
104
|
-
|
|
106
|
+
|
|
107
|
+
replaceRoute(linkParams)
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
return (
|
|
@@ -138,6 +141,7 @@ export default function FilterEqualType(props: FilterEqualTypeProps) {
|
|
|
138
141
|
currentPage={undefined}
|
|
139
142
|
key={option?.value}
|
|
140
143
|
color='inherit'
|
|
144
|
+
link={{ replace: anyFilterActive }}
|
|
141
145
|
>
|
|
142
146
|
<ListItem dense className={classes.listItem}>
|
|
143
147
|
<div className={classes.listItemInnerContainer}>
|
|
@@ -3,8 +3,8 @@ import { FilterRangeTypeInput } from '@graphcommerce/graphql'
|
|
|
3
3
|
import { Money } from '@graphcommerce/magento-store'
|
|
4
4
|
import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
|
|
5
5
|
import { makeStyles, Mark, Slider, Theme } from '@material-ui/core'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
import {
|
|
6
|
+
import React, { useEffect } from 'react'
|
|
7
|
+
import { useProductListLinkReplace } from '../../hooks/useProductListLinkReplace'
|
|
8
8
|
import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
|
|
9
9
|
import { ProductListFiltersFragment } from './ProductListFilters.gql'
|
|
10
10
|
|
|
@@ -51,7 +51,7 @@ export default function FilterRangeType(props: FilterRangeTypeProps) {
|
|
|
51
51
|
const { attribute_code, label, options, ...chipProps } = props
|
|
52
52
|
const classes = useFilterRangeType(props)
|
|
53
53
|
const { params } = useProductListParamsContext()
|
|
54
|
-
const
|
|
54
|
+
const replaceRoute = useProductListLinkReplace({ scroll: false })
|
|
55
55
|
|
|
56
56
|
// eslint-disable-next-line no-case-declarations
|
|
57
57
|
const marks: { [index: number]: Mark } = {}
|
|
@@ -80,6 +80,10 @@ export default function FilterRangeType(props: FilterRangeTypeProps) {
|
|
|
80
80
|
paramValues ? [Number(paramValues.from), Number(paramValues.to)] : [min, max],
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!paramValues) setValue([min, max])
|
|
85
|
+
}, [max, min, paramValues])
|
|
86
|
+
|
|
83
87
|
const priceFilterUrl = cloneDeep(params)
|
|
84
88
|
delete priceFilterUrl.currentPage
|
|
85
89
|
priceFilterUrl.filters[attribute_code] = {
|
|
@@ -94,7 +98,7 @@ export default function FilterRangeType(props: FilterRangeTypeProps) {
|
|
|
94
98
|
delete linkParams.filters[attribute_code]
|
|
95
99
|
|
|
96
100
|
setValue([min, max])
|
|
97
|
-
|
|
101
|
+
replaceRoute(linkParams)
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
const currentFilter = params.filters[attribute_code] as FilterRangeTypeInput | undefined
|
|
@@ -156,7 +160,7 @@ export default function FilterRangeType(props: FilterRangeTypeProps) {
|
|
|
156
160
|
}}
|
|
157
161
|
onChangeCommitted={(e, newValue) => {
|
|
158
162
|
if (newValue[0] > min || newValue[1] < max) {
|
|
159
|
-
|
|
163
|
+
replaceRoute({ ...priceFilterUrl })
|
|
160
164
|
} else {
|
|
161
165
|
resetFilter()
|
|
162
166
|
}
|
|
@@ -7,7 +7,10 @@ import { ProductListParams } from '../ProductListItems/filterTypes'
|
|
|
7
7
|
|
|
8
8
|
export type ProductListLinkProps = PropsWithChildren<
|
|
9
9
|
LinkProps &
|
|
10
|
-
ProductListParams & {
|
|
10
|
+
ProductListParams & {
|
|
11
|
+
noLink?: boolean
|
|
12
|
+
link?: Omit<PageLinkProps, 'href' | 'passHref'>
|
|
13
|
+
}
|
|
11
14
|
>
|
|
12
15
|
|
|
13
16
|
const ProductListLink = React.forwardRef<HTMLAnchorElement, ProductListLinkProps>((props, ref) => {
|
|
@@ -4,7 +4,7 @@ import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
|
|
4
4
|
import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
|
|
5
5
|
import { ListItem, ListItemText } from '@material-ui/core'
|
|
6
6
|
import React from 'react'
|
|
7
|
-
import {
|
|
7
|
+
import { useProductListLinkReplace } from '../../hooks/useProductListLinkReplace'
|
|
8
8
|
import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
|
|
9
9
|
import ProductListLink from '../ProductListLink/ProductListLink'
|
|
10
10
|
import { ProductListSortFragment } from './ProductListSort.gql'
|
|
@@ -15,7 +15,7 @@ export type ProductListSortProps = ProductListSortFragment &
|
|
|
15
15
|
export default function ProductListSort(props: ProductListSortProps) {
|
|
16
16
|
const { sort_fields, total_count, ...filterMenuProps } = props
|
|
17
17
|
const { params } = useProductListParamsContext()
|
|
18
|
-
const
|
|
18
|
+
const replaceRoute = useProductListLinkReplace()
|
|
19
19
|
const { data: storeConfigQuery } = useQuery(StoreConfigDocument)
|
|
20
20
|
const defaultSort = storeConfigQuery?.storeConfig?.catalog_default_sort_by
|
|
21
21
|
|
|
@@ -27,7 +27,7 @@ export default function ProductListSort(props: ProductListSortProps) {
|
|
|
27
27
|
const removeFilter = () => {
|
|
28
28
|
const linkParams = cloneDeep(params)
|
|
29
29
|
linkParams.sort = {}
|
|
30
|
-
|
|
30
|
+
replaceRoute(linkParams)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
if (!total_count) return null
|
|
@@ -59,7 +59,7 @@ export default function ProductListSort(props: ProductListSortProps) {
|
|
|
59
59
|
{...linkParams}
|
|
60
60
|
color='inherit'
|
|
61
61
|
underline='none'
|
|
62
|
-
link={{ scroll: false }}
|
|
62
|
+
link={{ scroll: false, replace: true }}
|
|
63
63
|
/>
|
|
64
64
|
)}
|
|
65
65
|
>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { default as Router } from 'next/router'
|
|
2
|
+
import { ProductListParams } from '../components/ProductListItems/filterTypes'
|
|
3
|
+
import { createProductListLink } from './useProductListLink'
|
|
4
|
+
import { useProductListParamsContext } from './useProductListParamsContext'
|
|
5
|
+
|
|
6
|
+
type UseProductLinkPushProps = {
|
|
7
|
+
shallow?: boolean
|
|
8
|
+
locale?: string | false
|
|
9
|
+
scroll?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useProductListLinkReplace(props?: UseProductLinkPushProps) {
|
|
13
|
+
const { setParams } = useProductListParamsContext()
|
|
14
|
+
|
|
15
|
+
return (params: ProductListParams) => {
|
|
16
|
+
const queryUrl = Router.query.url ?? []
|
|
17
|
+
const comingFromURLWithoutFilters = !queryUrl.includes('q')
|
|
18
|
+
|
|
19
|
+
setParams(params)
|
|
20
|
+
|
|
21
|
+
const path = createProductListLink(params)
|
|
22
|
+
|
|
23
|
+
// push the first filter, so the new route (on browser back) will be e.g. /women/fruit instead of /women
|
|
24
|
+
if (comingFromURLWithoutFilters) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
26
|
+
Router.push(path, path, props)
|
|
27
|
+
} else {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
29
|
+
Router.replace(path, path, props)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/index.ts
CHANGED
|
@@ -4,6 +4,6 @@ export * from './Api/ProductListItem.gql'
|
|
|
4
4
|
export * from './Api/ProductPageItem.gql'
|
|
5
5
|
|
|
6
6
|
export * from './hooks/useProductLink'
|
|
7
|
-
export * from './hooks/
|
|
7
|
+
export * from './hooks/useProductListLinkReplace'
|
|
8
8
|
export * from './hooks/useProductListParamsContext'
|
|
9
9
|
export * from './hooks/ProductLink.gql'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphcommerce/magento-product",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
6
6
|
"browserslist": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@graphcommerce/framer-scroller": "^0.2.5",
|
|
25
25
|
"@graphcommerce/graphql": "^2.103.4",
|
|
26
26
|
"@graphcommerce/image": "^2.104.5",
|
|
27
|
-
"@graphcommerce/magento-cart": "^3.0.
|
|
27
|
+
"@graphcommerce/magento-cart": "^3.0.8",
|
|
28
28
|
"@graphcommerce/magento-store": "^3.0.7",
|
|
29
29
|
"@graphcommerce/next-ui": "^3.0.6",
|
|
30
30
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"schema-dts": "^1.0.0",
|
|
39
39
|
"type-fest": "^2.3.4"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5045f247ba0d84c53b16a1cc924677cfcd53b4b7"
|
|
42
42
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Router from 'next/router'
|
|
2
|
-
import { ProductListParams } from '../components/ProductListItems/filterTypes'
|
|
3
|
-
import { createProductListLink } from './useProductListLink'
|
|
4
|
-
import { useProductListParamsContext } from './useProductListParamsContext'
|
|
5
|
-
|
|
6
|
-
type UseProductLinkPushProps = {
|
|
7
|
-
shallow?: boolean
|
|
8
|
-
locale?: string | false
|
|
9
|
-
scroll?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useProductListLinkPush(props?: UseProductLinkPushProps) {
|
|
13
|
-
const { setParams } = useProductListParamsContext()
|
|
14
|
-
|
|
15
|
-
return (params: ProductListParams) => {
|
|
16
|
-
setParams(params)
|
|
17
|
-
|
|
18
|
-
const path = createProductListLink(params)
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
20
|
-
Router.push(path, path, props)
|
|
21
|
-
}
|
|
22
|
-
}
|