@graphcommerce/magento-product 11.0.0-canary.50 → 11.0.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.52
|
|
4
|
+
|
|
5
|
+
## 11.0.0-canary.51
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#2709](https://github.com/graphcommerce-org/graphcommerce/pull/2709) [`9c2a218`](https://github.com/graphcommerce-org/graphcommerce/commit/9c2a21881c446b78986865c6fec1a161824bf6f1) - `ProductFiltersPro` submits only when the filters differ from the current product list. The filter fields add empty filters to the form when they mount, so with `productFiltersLayout: 'SIDEBAR'` a direct load of `/shoes/page/2` or `/shoes?gclid=abc` went to `/shoes`. ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
10
|
+
|
|
3
11
|
## 11.0.0-canary.50
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ProductFiltersProContext } from '@graphcommerce/magento-product'
|
|
2
|
+
import { ProductFiltersPro, useProductFiltersPro } from '@graphcommerce/magento-product'
|
|
3
|
+
import { createTheme, ThemeProvider } from '@mui/material'
|
|
4
|
+
import { renderToString } from 'react-dom/server'
|
|
5
|
+
import { beforeEach, expect, it, vi } from 'vitest'
|
|
6
|
+
import type { ProductListParams } from '../ProductListItems/filterTypes'
|
|
7
|
+
|
|
8
|
+
const router = vi.hoisted(() => ({
|
|
9
|
+
asPath: '',
|
|
10
|
+
query: {},
|
|
11
|
+
push: vi.fn(async () => true),
|
|
12
|
+
replace: vi.fn(async () => true),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
vi.mock('next/router', () => ({ useRouter: () => router }))
|
|
16
|
+
|
|
17
|
+
const theme = { ...createTheme(), appShell: { headerHeightSm: '0px' } }
|
|
18
|
+
|
|
19
|
+
function renderFilters(params: Partial<ProductListParams>) {
|
|
20
|
+
let context: ProductFiltersProContext | undefined
|
|
21
|
+
|
|
22
|
+
function ReadContext() {
|
|
23
|
+
context = useProductFiltersPro()
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
renderToString(
|
|
28
|
+
<ThemeProvider theme={theme}>
|
|
29
|
+
<ProductFiltersPro
|
|
30
|
+
params={{ url: 'shoes', filters: {}, sort: {}, pageSize: null, search: null, ...params }}
|
|
31
|
+
aggregations={[]}
|
|
32
|
+
appliedAggregations={[]}
|
|
33
|
+
filterTypes={{}}
|
|
34
|
+
>
|
|
35
|
+
<ReadContext />
|
|
36
|
+
</ProductFiltersPro>
|
|
37
|
+
</ThemeProvider>,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return context as ProductFiltersProContext
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
router.push.mockClear()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('stays on the page of the list when the filter fields add empty filters', async () => {
|
|
48
|
+
router.asPath = '/shoes/page/2'
|
|
49
|
+
const { form, submit } = renderFilters({ currentPage: 2 })
|
|
50
|
+
|
|
51
|
+
form.setValue('filters.color', {})
|
|
52
|
+
await submit()
|
|
53
|
+
|
|
54
|
+
expect(router.push).not.toHaveBeenCalled()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('keeps the query string of the request when the filter fields add empty filters', async () => {
|
|
58
|
+
router.asPath = '/shoes?gclid=abc'
|
|
59
|
+
const { form, submit } = renderFilters({ currentPage: 1 })
|
|
60
|
+
|
|
61
|
+
form.setValue('filters.color', {})
|
|
62
|
+
await submit()
|
|
63
|
+
|
|
64
|
+
expect(router.push).not.toHaveBeenCalled()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('goes to the first page of the list for a changed filter', async () => {
|
|
68
|
+
router.asPath = '/shoes/page/2'
|
|
69
|
+
const { form, submit } = renderFilters({ currentPage: 2 })
|
|
70
|
+
|
|
71
|
+
form.setValue('filters.color', { in: ['red'] })
|
|
72
|
+
await submit()
|
|
73
|
+
|
|
74
|
+
expect(router.push).toHaveBeenCalledWith(
|
|
75
|
+
'/c/shoes/q/color/red',
|
|
76
|
+
'/c/shoes/q/color/red',
|
|
77
|
+
expect.anything(),
|
|
78
|
+
)
|
|
79
|
+
})
|
|
@@ -120,6 +120,10 @@ export function ProductFiltersPro(props: FilterFormProviderProps) {
|
|
|
120
120
|
|
|
121
121
|
const submit = useEventCallback(
|
|
122
122
|
form.handleSubmit(async (formValues) => {
|
|
123
|
+
// The filter fields add empty filters to the form when they mount.
|
|
124
|
+
if (productListLinkFromFilter(formValues) === productListLinkFromFilter(defaultValues))
|
|
125
|
+
return false
|
|
126
|
+
|
|
123
127
|
const path = productListLinkFromFilter({ ...formValues, currentPage: 1 })
|
|
124
128
|
if (router.asPath === path) return false
|
|
125
129
|
|
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": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.52",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"typescript": "5.9.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.
|
|
22
|
-
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.
|
|
23
|
-
"@graphcommerce/framer-next-pages": "^11.0.0-canary.
|
|
24
|
-
"@graphcommerce/framer-scroller": "^11.0.0-canary.
|
|
25
|
-
"@graphcommerce/graphql": "^11.0.0-canary.
|
|
26
|
-
"@graphcommerce/graphql-mesh": "^11.0.0-canary.
|
|
27
|
-
"@graphcommerce/image": "^11.0.0-canary.
|
|
28
|
-
"@graphcommerce/magento-cart": "^11.0.0-canary.
|
|
29
|
-
"@graphcommerce/magento-store": "^11.0.0-canary.
|
|
30
|
-
"@graphcommerce/next-ui": "^11.0.0-canary.
|
|
31
|
-
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.
|
|
32
|
-
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.
|
|
21
|
+
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.52",
|
|
22
|
+
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.52",
|
|
23
|
+
"@graphcommerce/framer-next-pages": "^11.0.0-canary.52",
|
|
24
|
+
"@graphcommerce/framer-scroller": "^11.0.0-canary.52",
|
|
25
|
+
"@graphcommerce/graphql": "^11.0.0-canary.52",
|
|
26
|
+
"@graphcommerce/graphql-mesh": "^11.0.0-canary.52",
|
|
27
|
+
"@graphcommerce/image": "^11.0.0-canary.52",
|
|
28
|
+
"@graphcommerce/magento-cart": "^11.0.0-canary.52",
|
|
29
|
+
"@graphcommerce/magento-store": "^11.0.0-canary.52",
|
|
30
|
+
"@graphcommerce/next-ui": "^11.0.0-canary.52",
|
|
31
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.52",
|
|
32
|
+
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.52",
|
|
33
33
|
"@lingui/core": "^5",
|
|
34
34
|
"@lingui/macro": "^5",
|
|
35
35
|
"@lingui/react": "^5",
|