@graphcommerce/magento-product 3.0.4 → 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 +34 -0
- package/components/ProductAddToCart/ProductAddToCart.tsx +121 -0
- package/components/ProductListCount/index.tsx +1 -1
- package/components/ProductListFilters/FilterCheckboxType.tsx +5 -5
- package/components/ProductListFilters/FilterEqualType.tsx +9 -5
- package/components/ProductListFilters/FilterRangeType.tsx +10 -6
- package/components/ProductListFiltersContainer/index.tsx +1 -1
- package/components/ProductListItem/index.tsx +1 -1
- package/components/ProductListItems/ProductListItemsBase.tsx +5 -2
- package/components/ProductListLink/ProductListLink.tsx +4 -1
- package/components/ProductListPagination/index.tsx +1 -1
- package/components/ProductListPrice/index.tsx +1 -1
- package/components/ProductListSort/index.tsx +5 -5
- package/components/ProductSidebarDelivery/index.tsx +1 -1
- package/components/ProductSpecs/index.tsx +1 -1
- package/components/index.ts +3 -1
- package/hooks/useProductListLinkReplace.ts +32 -0
- package/index.ts +1 -1
- package/package.json +10 -9
- package/hooks/useProductListLinkPush.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,40 @@
|
|
|
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
|
+
|
|
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)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* with the latest version of graphql codegen the preresovled types inlined Maybe, make sure we reflect that ([7cb27b0](https://github.com/ho-nl/m2-pwa/commit/7cb27b04cbe31bee5ef4000d408f08bc9ac505c5))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## [3.0.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.4...@graphcommerce/magento-product@3.0.5) (2021-09-28)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* add to cart button ([8a69454](https://github.com/ho-nl/m2-pwa/commit/8a69454b1372a563020e1ef1b7c50363b8d29717))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
6
40
|
## [3.0.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.0...@graphcommerce/magento-product@3.0.1) (2021-09-27)
|
|
7
41
|
|
|
8
42
|
**Note:** Version bump only for package @graphcommerce/magento-product
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ProductInterface } from '@graphcommerce/graphql'
|
|
2
|
+
import { ApolloCartErrorAlert, useFormGqlMutationCart } from '@graphcommerce/magento-cart'
|
|
3
|
+
import { Money, MoneyProps } from '@graphcommerce/magento-store'
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
ButtonProps,
|
|
7
|
+
MessageSnackbar,
|
|
8
|
+
SvgImage,
|
|
9
|
+
TextInputNumber,
|
|
10
|
+
iconCheckmark,
|
|
11
|
+
iconChevronRight,
|
|
12
|
+
} from '@graphcommerce/next-ui'
|
|
13
|
+
import { Divider, makeStyles, Theme, Typography } from '@material-ui/core'
|
|
14
|
+
import PageLink from 'next/link'
|
|
15
|
+
import React from 'react'
|
|
16
|
+
import { ProductAddToCartDocument, ProductAddToCartMutationVariables } from './ProductAddToCart.gql'
|
|
17
|
+
|
|
18
|
+
const useStyles = makeStyles(
|
|
19
|
+
(theme: Theme) => ({
|
|
20
|
+
button: {
|
|
21
|
+
marginTop: theme.spacings.sm,
|
|
22
|
+
width: '100%',
|
|
23
|
+
},
|
|
24
|
+
messageIcon: {
|
|
25
|
+
marginBottom: '-2px',
|
|
26
|
+
marginRight: 5,
|
|
27
|
+
},
|
|
28
|
+
price: {
|
|
29
|
+
fontWeight: theme.typography.fontWeightBold,
|
|
30
|
+
margin: `${theme.spacings.sm} 0`,
|
|
31
|
+
},
|
|
32
|
+
divider: {
|
|
33
|
+
margin: `${theme.spacings.xs} 0`,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
{ name: 'AddToCart' },
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
export type AddToCartProps = React.ComponentProps<typeof ProductAddToCart>
|
|
40
|
+
|
|
41
|
+
export default function ProductAddToCart(
|
|
42
|
+
props: Pick<ProductInterface, 'name'> & {
|
|
43
|
+
variables: Omit<ProductAddToCartMutationVariables, 'cartId'>
|
|
44
|
+
name: string
|
|
45
|
+
price: MoneyProps
|
|
46
|
+
children?: React.ReactNode
|
|
47
|
+
} & Omit<ButtonProps, 'type' | 'name'>,
|
|
48
|
+
) {
|
|
49
|
+
const { name, children, variables, price, ...buttonProps } = props
|
|
50
|
+
|
|
51
|
+
const form = useFormGqlMutationCart(ProductAddToCartDocument, {
|
|
52
|
+
defaultValues: variables,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const { handleSubmit, formState, error, muiRegister, required } = form
|
|
56
|
+
const submitHandler = handleSubmit(() => {})
|
|
57
|
+
const classes = useStyles()
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<form onSubmit={submitHandler} noValidate>
|
|
61
|
+
<Divider className={classes.divider} />
|
|
62
|
+
|
|
63
|
+
<Typography variant='h4' className={classes.price}>
|
|
64
|
+
<Money {...price} />
|
|
65
|
+
</Typography>
|
|
66
|
+
|
|
67
|
+
<TextInputNumber
|
|
68
|
+
variant='outlined'
|
|
69
|
+
error={formState.isSubmitted && !!formState.errors.quantity}
|
|
70
|
+
required={required.quantity}
|
|
71
|
+
inputProps={{ min: 1 }}
|
|
72
|
+
{...muiRegister('quantity', { required: required.quantity })}
|
|
73
|
+
helperText={formState.isSubmitted && formState.errors.quantity}
|
|
74
|
+
disabled={formState.isSubmitting}
|
|
75
|
+
size='small'
|
|
76
|
+
/>
|
|
77
|
+
{children}
|
|
78
|
+
<Button
|
|
79
|
+
type='submit'
|
|
80
|
+
classes={{ root: classes.button }}
|
|
81
|
+
loading={formState.isSubmitting}
|
|
82
|
+
color='primary'
|
|
83
|
+
variant='pill'
|
|
84
|
+
size='large'
|
|
85
|
+
{...buttonProps}
|
|
86
|
+
>
|
|
87
|
+
Add to Cart
|
|
88
|
+
</Button>
|
|
89
|
+
|
|
90
|
+
<ApolloCartErrorAlert error={error} />
|
|
91
|
+
|
|
92
|
+
<MessageSnackbar
|
|
93
|
+
open={!formState.isSubmitting && formState.isSubmitSuccessful && !error?.message}
|
|
94
|
+
variant='pill'
|
|
95
|
+
color='default'
|
|
96
|
+
action={
|
|
97
|
+
<PageLink href='/cart'>
|
|
98
|
+
<Button
|
|
99
|
+
size='medium'
|
|
100
|
+
variant='pill'
|
|
101
|
+
color='secondary'
|
|
102
|
+
endIcon={<SvgImage src={iconChevronRight} shade='inverted' alt='chevron right' />}
|
|
103
|
+
>
|
|
104
|
+
View shopping cart
|
|
105
|
+
</Button>
|
|
106
|
+
</PageLink>
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
<div>
|
|
110
|
+
<SvgImage
|
|
111
|
+
src={iconCheckmark}
|
|
112
|
+
loading='eager'
|
|
113
|
+
alt='checkmark'
|
|
114
|
+
className={classes.messageIcon}
|
|
115
|
+
/>
|
|
116
|
+
<strong>{name}</strong> has been added to your shopping cart!
|
|
117
|
+
</div>
|
|
118
|
+
</MessageSnackbar>
|
|
119
|
+
</form>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cloneDeep } from '@apollo/client/utilities'
|
|
2
|
-
import { Chip, ChipProps } from '@material-ui/core'
|
|
3
2
|
import { useChipMenuStyles, SvgImage, iconCloseCircle } from '@graphcommerce/next-ui'
|
|
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
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { cloneDeep } from '@apollo/client/utilities'
|
|
2
|
+
import { FilterEqualTypeInput } from '@graphcommerce/graphql'
|
|
3
|
+
import { ChipMenu, ChipMenuProps, responsiveVal } from '@graphcommerce/next-ui'
|
|
2
4
|
import {
|
|
3
5
|
Checkbox,
|
|
4
6
|
ListItem,
|
|
@@ -7,11 +9,9 @@ import {
|
|
|
7
9
|
makeStyles,
|
|
8
10
|
Theme,
|
|
9
11
|
} from '@material-ui/core'
|
|
10
|
-
import { FilterEqualTypeInput } from '@graphcommerce/graphql'
|
|
11
|
-
import { ChipMenu, ChipMenuProps, responsiveVal } from '@graphcommerce/next-ui'
|
|
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}>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { cloneDeep } from '@apollo/client/utilities'
|
|
2
|
-
import { makeStyles, Mark, Slider, Theme } from '@material-ui/core'
|
|
3
2
|
import { FilterRangeTypeInput } from '@graphcommerce/graphql'
|
|
4
3
|
import { Money } from '@graphcommerce/magento-store'
|
|
5
4
|
import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
5
|
+
import { makeStyles, Mark, Slider, Theme } from '@material-ui/core'
|
|
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
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { makeStyles, Theme } from '@material-ui/core'
|
|
2
1
|
import { Scroller, ScrollerButton, ScrollerProvider } from '@graphcommerce/framer-scroller'
|
|
3
2
|
import {
|
|
4
3
|
iconChevronLeft,
|
|
@@ -6,6 +5,7 @@ import {
|
|
|
6
5
|
SvgImageSimple,
|
|
7
6
|
UseStyles,
|
|
8
7
|
} from '@graphcommerce/next-ui'
|
|
8
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
9
9
|
import clsx from 'clsx'
|
|
10
10
|
import { m, useMotionTemplate, useTransform, useViewportScroll } from 'framer-motion'
|
|
11
11
|
import React, { PropsWithChildren, useEffect, useRef, useState } from 'react'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Link as MuiLink, makeStyles, Theme, Typography } from '@material-ui/core'
|
|
2
1
|
import { Image, ImageProps } from '@graphcommerce/image'
|
|
3
2
|
import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import { Link as MuiLink, makeStyles, Theme, Typography } from '@material-ui/core'
|
|
4
4
|
import clsx from 'clsx'
|
|
5
5
|
import PageLink from 'next/link'
|
|
6
6
|
import { useRouter } from 'next/router'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Theme, makeStyles } from '@material-ui/core'
|
|
2
1
|
import { Maybe } from '@graphcommerce/graphql'
|
|
3
2
|
import { RenderType, UseStyles, responsiveVal } from '@graphcommerce/next-ui'
|
|
3
|
+
import { Theme, makeStyles } from '@material-ui/core'
|
|
4
4
|
import clsx from 'clsx'
|
|
5
5
|
import React from 'react'
|
|
6
6
|
import { ProductListItemFragment } from '../../Api/ProductListItem.gql'
|
|
@@ -23,7 +23,10 @@ export const useStyles = makeStyles(
|
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
export type ProductItemsGridProps = {
|
|
26
|
-
items?:
|
|
26
|
+
items?:
|
|
27
|
+
| Array<(ProductListItemFragment & ProductListItemProps) | null | undefined>
|
|
28
|
+
| null
|
|
29
|
+
| undefined
|
|
27
30
|
renderers: ProductListItemRenderer
|
|
28
31
|
loadingEager?: number
|
|
29
32
|
size?: 'normal' | 'small'
|
|
@@ -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) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PaginationProps } from '@material-ui/lab'
|
|
2
1
|
import { Pagination } from '@graphcommerce/next-ui'
|
|
2
|
+
import { PaginationProps } from '@material-ui/lab'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
|
|
5
5
|
import ProductListLink from '../ProductListLink/ProductListLink'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
2
1
|
import { Money } from '@graphcommerce/magento-store'
|
|
3
2
|
import { UseStyles } from '@graphcommerce/next-ui'
|
|
3
|
+
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import { ProductListPriceFragment } from './ProductListPrice.gql'
|
|
6
6
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useQuery } from '@apollo/client'
|
|
2
2
|
import { cloneDeep } from '@apollo/client/utilities'
|
|
3
|
-
import { ListItem, ListItemText } from '@material-ui/core'
|
|
4
3
|
import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
|
5
4
|
import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
|
|
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
|
>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
2
1
|
import { SvgImage, responsiveVal, iconBox } from '@graphcommerce/next-ui'
|
|
2
|
+
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
5
5
|
const useStyles = makeStyles(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { makeStyles, Theme } from '@material-ui/core'
|
|
2
1
|
import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
|
|
2
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
3
3
|
import { ProductSpecsFragment } from './ProductSpecs.gql'
|
|
4
4
|
|
|
5
5
|
const useStyles = makeStyles((theme: Theme) => ({
|
package/components/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './JsonLdProduct'
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export * from './ProductAddToCart/ProductAddToCart'
|
|
4
|
+
export { default as ProductAddToCart } from './ProductAddToCart/ProductAddToCart'
|
|
3
5
|
|
|
4
6
|
export * from './ProductList/ProductList.gql'
|
|
5
7
|
|
|
@@ -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": [
|
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@graphcommerce/browserslist-config-pwa": "^3.0.1",
|
|
17
|
-
"@graphcommerce/eslint-config-pwa": "^3.0.
|
|
17
|
+
"@graphcommerce/eslint-config-pwa": "^3.0.4",
|
|
18
18
|
"@graphcommerce/prettier-config-pwa": "^3.0.2",
|
|
19
|
-
"@graphcommerce/typescript-config-pwa": "^3.0
|
|
19
|
+
"@graphcommerce/typescript-config-pwa": "^3.1.0",
|
|
20
20
|
"@playwright/test": "^1.15.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@apollo/client": "^3.3.21",
|
|
24
|
-
"@graphcommerce/framer-scroller": "^0.2.
|
|
25
|
-
"@graphcommerce/graphql": "^2.103.
|
|
26
|
-
"@graphcommerce/image": "^2.104.
|
|
27
|
-
"@graphcommerce/magento-
|
|
28
|
-
"@graphcommerce/
|
|
24
|
+
"@graphcommerce/framer-scroller": "^0.2.5",
|
|
25
|
+
"@graphcommerce/graphql": "^2.103.4",
|
|
26
|
+
"@graphcommerce/image": "^2.104.5",
|
|
27
|
+
"@graphcommerce/magento-cart": "^3.0.8",
|
|
28
|
+
"@graphcommerce/magento-store": "^3.0.7",
|
|
29
|
+
"@graphcommerce/next-ui": "^3.0.6",
|
|
29
30
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
30
31
|
"@material-ui/core": "^4.12.3",
|
|
31
32
|
"@material-ui/lab": "^4.0.0-alpha.60",
|
|
@@ -37,5 +38,5 @@
|
|
|
37
38
|
"schema-dts": "^1.0.0",
|
|
38
39
|
"type-fest": "^2.3.4"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5045f247ba0d84c53b16a1cc924677cfcd53b4b7"
|
|
41
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
|
-
}
|