@graphcommerce/magento-category 3.0.1
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 +163 -0
- package/components/CategoryBreadcrumb/CategoryBreadcrumb.gql.ts +4 -0
- package/components/CategoryBreadcrumb/CategoryBreadcrumb.graphql +8 -0
- package/components/CategoryChildren/CategoryChildren.gql.ts +4 -0
- package/components/CategoryChildren/CategoryChildren.graphql +9 -0
- package/components/CategoryChildren/CategoryChildren.tsx +91 -0
- package/components/CategoryDescription/CategoryDescription.gql.ts +4 -0
- package/components/CategoryDescription/CategoryDescription.graphql +6 -0
- package/components/CategoryDescription/CategoryDescription.tsx +38 -0
- package/components/CategoryHeroNav/CategoryHeroNav.gql.ts +4 -0
- package/components/CategoryHeroNav/CategoryHeroNav.graphql +11 -0
- package/components/CategoryHeroNav/CategoryHeroNav.tsx +119 -0
- package/components/CategoryHeroNav/CategoryHeroNavTitle.tsx +35 -0
- package/components/CategoryMeta/CategoryMeta.gql.ts +4 -0
- package/components/CategoryMeta/CategoryMeta.graphql +6 -0
- package/components/CategoryMeta/CategoryMeta.tsx +27 -0
- package/components/FilterInputTypes/FilterInputTypes.graphql +10 -0
- package/index.ts +7 -0
- package/next-env.d.ts +4 -0
- package/package.json +37 -0
- package/queries/CategoryPage.gql.ts +12 -0
- package/queries/CategoryPage.graphql +3 -0
- package/queries/CategoryQueryFragment.gql.ts +4 -0
- package/queries/CategoryQueryFragment.graphql +12 -0
- package/queries/GetCategoryStaticPaths.gql.ts +12 -0
- package/queries/GetCategoryStaticPaths.graphql +20 -0
- package/queries/MenuQueryFragment.gql.ts +4 -0
- package/queries/MenuQueryFragment.graphql +10 -0
- package/queries/getCategoryStaticPaths.ts +35 -0
- package/tsconfig.json +5 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [3.0.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@3.0.0...@graphcommerce/magento-category@3.0.1) (2021-09-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @graphcommerce/magento-category
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 3.0.0 (2021-09-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **app-shell-header:** title offset top not correctly set ([c144309](https://github.com/ho-nl/m2-pwa/commit/c1443095317c1779074f3a4058f4041159c8e31b))
|
|
20
|
+
* **app-shell:** pages after app shell changes ([fb74510](https://github.com/ho-nl/m2-pwa/commit/fb74510121f6124009db72ad2ddebf6459c52a85))
|
|
21
|
+
* canonical urls ([9ff8d3f](https://github.com/ho-nl/m2-pwa/commit/9ff8d3f950098fb28440f31f5dd93a835dce0bda))
|
|
22
|
+
* category children and swatch renderer ([1ee008d](https://github.com/ho-nl/m2-pwa/commit/1ee008d9ecf3bf5ec4b2d82243e4bcbbec384411))
|
|
23
|
+
* category children mobile positioning ([fafa02d](https://github.com/ho-nl/m2-pwa/commit/fafa02d393919cdb7f89d72afa17da07228f8093))
|
|
24
|
+
* category hero nav margin top ([31f8dee](https://github.com/ho-nl/m2-pwa/commit/31f8deed1d545d78bb856d4cfdfe0c7ec8671308))
|
|
25
|
+
* CategoryHeroNav styles ([6f185e7](https://github.com/ho-nl/m2-pwa/commit/6f185e74ee4c756efdf94ebcdee9b4593077f415))
|
|
26
|
+
* empty grid rows still have a gap ([7ba50c7](https://github.com/ho-nl/m2-pwa/commit/7ba50c740aa7ac5133b933b3e6a22fab853b55a6))
|
|
27
|
+
* filters sometimes do not apply ([b8bc412](https://github.com/ho-nl/m2-pwa/commit/b8bc4122c82c6b27bdc76481dd6ece1da021266a))
|
|
28
|
+
* **framer-next-page:** usePageRouter in SharedLayout ([c2fb164](https://github.com/ho-nl/m2-pwa/commit/c2fb164b342770089b787378a3f79529c36d2152))
|
|
29
|
+
* getStaticPaths shouldn’t have the url suffix ([0fc9e1c](https://github.com/ho-nl/m2-pwa/commit/0fc9e1cec78ba653e32de042fb60a3ca88eb494d))
|
|
30
|
+
* ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
31
|
+
* implement next-ui barrel imports ([75bea70](https://github.com/ho-nl/m2-pwa/commit/75bea703dba898f18a2a1dfa3243ebd0a4e6f0e1))
|
|
32
|
+
* remove conflicting files ([0c17ae4](https://github.com/ho-nl/m2-pwa/commit/0c17ae46be62b775ac83b35f11c532ce2d9401a3))
|
|
33
|
+
* remove magento-category package from magento-product solving a circular dependency ([7379e6e](https://github.com/ho-nl/m2-pwa/commit/7379e6ede4829392b35008c17743181d9cac0636))
|
|
34
|
+
* search page routes ([4161179](https://github.com/ho-nl/m2-pwa/commit/4161179aaf2ecbc0fde0efbba891a7b85524e283))
|
|
35
|
+
* since all links are of next/link we need to add passHref for custom components ([16fb931](https://github.com/ho-nl/m2-pwa/commit/16fb93100d367203ea79bb4f93357221253f2ecd))
|
|
36
|
+
* solve issue if an attribute was named ‘size’ ([dab088e](https://github.com/ho-nl/m2-pwa/commit/dab088ed5f1a2916dc991a7d5c0b8d703a2ea3b7))
|
|
37
|
+
* spelling errors, wrong imports ([01cb889](https://github.com/ho-nl/m2-pwa/commit/01cb889513d69ce0555ac7aaa1a37702d75b0a0d))
|
|
38
|
+
* update magento-product imports ([63621b4](https://github.com/ho-nl/m2-pwa/commit/63621b44be7149014f4a5af8ac87ad1c4b0327be))
|
|
39
|
+
* word-break for category hero nav ([be47595](https://github.com/ho-nl/m2-pwa/commit/be4759519a23889950430d60a9264d9806df552c))
|
|
40
|
+
* yarn workspace packages hot reload ([d03fc9f](https://github.com/ho-nl/m2-pwa/commit/d03fc9fdda3486476761786f2b56a934cc92befc))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
|
|
45
|
+
* add barrel file for magento-category ([c5ba8c9](https://github.com/ho-nl/m2-pwa/commit/c5ba8c98cbb8192f1c1c85242ff6efa83b1fbdcc))
|
|
46
|
+
* add getFilterTypes to shared client, faster generation ([beccfde](https://github.com/ho-nl/m2-pwa/commit/beccfde6ebc8aaf6223f0e8b33fabf4f5039efed))
|
|
47
|
+
* add graphcms asset to category page ([a760f25](https://github.com/ho-nl/m2-pwa/commit/a760f2547485e56b1fd4ecb03dd3cfb0a1c4819e))
|
|
48
|
+
* animated filters ([846e233](https://github.com/ho-nl/m2-pwa/commit/846e233c9653821afbe9cfe7742dc42bb869a078))
|
|
49
|
+
* better 404 handling and simplified getStaticProps ([321ace1](https://github.com/ho-nl/m2-pwa/commit/321ace1850642ee3eddfa674c37e6fca8adcdb74))
|
|
50
|
+
* canonical urls using abstract page meta component ([7d52cfc](https://github.com/ho-nl/m2-pwa/commit/7d52cfc76af2766dedf883b1e3fa5a5101eca823))
|
|
51
|
+
* category navigation ([00d1997](https://github.com/ho-nl/m2-pwa/commit/00d199741bb1ab266900869d27ac7251841aaf94))
|
|
52
|
+
* created stable layout for category filters ([08d9351](https://github.com/ho-nl/m2-pwa/commit/08d9351dac5c9ede864ff336a60d758875d8efe4))
|
|
53
|
+
* created stacked-pages package ([d86008e](https://github.com/ho-nl/m2-pwa/commit/d86008ee659ccb25b194a41d624b394a1ddbd088))
|
|
54
|
+
* data agnostic animated header ([17047a6](https://github.com/ho-nl/m2-pwa/commit/17047a6d754494d9443c8f2e486cc232cf199c45))
|
|
55
|
+
* **framer-next-pages:** implemented the FullPageShell for the remaining pages ([88386b4](https://github.com/ho-nl/m2-pwa/commit/88386b4652abb7765d6e755c7fb7a3cb6285a0e7))
|
|
56
|
+
* **framer-scroller:** implemented the scroller on all pages ([73fb518](https://github.com/ho-nl/m2-pwa/commit/73fb518eff74edb2b3212e892b3d8cc2b088011b))
|
|
57
|
+
* **graphql:** introduced new graphql package that holds all generated files ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
|
|
58
|
+
* i18n routing added (/ and /fr for demo) ([bb3b339](https://github.com/ho-nl/m2-pwa/commit/bb3b339fbc9fceddd264a891ad81f00327a241ae))
|
|
59
|
+
* **image:** introduced completely rewritten Image component ([e3413b3](https://github.com/ho-nl/m2-pwa/commit/e3413b3a57392d6571ea64cb8d9c8dca05ea31df))
|
|
60
|
+
* introduced magento-product-types package ([1a0932b](https://github.com/ho-nl/m2-pwa/commit/1a0932b5d882608dcf8fd2e3b17ee9868f5f5776))
|
|
61
|
+
* introduces framer-next-pages and framer-sheet to next-ui and soxbase package ([e04ad8a](https://github.com/ho-nl/m2-pwa/commit/e04ad8a94cd1fd5a7c5575c9db7916b6e8a88f16))
|
|
62
|
+
* **magento-graphql:** added core magentoTypePolicies ([bdf15d0](https://github.com/ho-nl/m2-pwa/commit/bdf15d0d3c04e88339a8385d76f3b1ab9589fde3))
|
|
63
|
+
* major performance refactor ([03f8e2f](https://github.com/ho-nl/m2-pwa/commit/03f8e2fa16ef919bd6bd6eadd36922d0245ed960))
|
|
64
|
+
* next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
|
|
65
|
+
* **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
|
66
|
+
* remove wrapper div from ScrollSnapSlider ([476add8](https://github.com/ho-nl/m2-pwa/commit/476add8db64811f2c7e3fc482487967cd7573cf6))
|
|
67
|
+
* renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
|
|
68
|
+
* upgrade to node 14 ([d079a75](https://github.com/ho-nl/m2-pwa/commit/d079a751e9bfd8dc7f5009d2c9f31c336a0c96ab))
|
|
69
|
+
* upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
70
|
+
* video support for CategoryHeroNav ([e24fe60](https://github.com/ho-nl/m2-pwa/commit/e24fe600f776aaf41735178472b2d1343c5252e6))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Reverts
|
|
74
|
+
|
|
75
|
+
* Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## 2.0.8 (2020-10-28)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Bug Fixes
|
|
83
|
+
|
|
84
|
+
* make sure themes extensions are found ([5aa18db](https://github.com/ho-nl/m2-pwa/commit/5aa18db514fd2e2f50681367e39523f8e742ece0))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Features
|
|
88
|
+
|
|
89
|
+
* added generated graphql.ts files ([3e44415](https://github.com/ho-nl/m2-pwa/commit/3e44415b018e74b502e9e98479aa5e84041f337d))
|
|
90
|
+
* split into packages ([2ee7fd6](https://github.com/ho-nl/m2-pwa/commit/2ee7fd6c0056f467d114f04d92c6c0ddf622d151))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### BREAKING CHANGES
|
|
94
|
+
|
|
95
|
+
* huge folder structure refactor, please read README to reinstall
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Change Log
|
|
102
|
+
|
|
103
|
+
All notable changes to this project will be documented in this file. See
|
|
104
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
105
|
+
|
|
106
|
+
# [2.103.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.102.10...@graphcommerce/magento-category@2.103.0) (2021-09-01)
|
|
107
|
+
|
|
108
|
+
### Features
|
|
109
|
+
|
|
110
|
+
- **framer-scroller:** implemented the scroller on all pages
|
|
111
|
+
([73fb518](https://github.com/ho-nl/m2-pwa/commit/73fb518eff74edb2b3212e892b3d8cc2b088011b))
|
|
112
|
+
|
|
113
|
+
## [2.102.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.102.8...@graphcommerce/magento-category@2.102.9) (2021-08-27)
|
|
114
|
+
|
|
115
|
+
### Bug Fixes
|
|
116
|
+
|
|
117
|
+
- **app-shell:** pages after app shell changes
|
|
118
|
+
([fb74510](https://github.com/ho-nl/m2-pwa/commit/fb74510121f6124009db72ad2ddebf6459c52a85))
|
|
119
|
+
|
|
120
|
+
# [2.102.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.101.9...@graphcommerce/magento-category@2.102.0) (2021-08-12)
|
|
121
|
+
|
|
122
|
+
### Features
|
|
123
|
+
|
|
124
|
+
- upgraded to nextjs 11
|
|
125
|
+
([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
|
|
126
|
+
|
|
127
|
+
## [2.101.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.101.8...@graphcommerce/magento-category@2.101.9) (2021-08-09)
|
|
128
|
+
|
|
129
|
+
### Reverts
|
|
130
|
+
|
|
131
|
+
- Revert "chore: upgrade @apollo/client"
|
|
132
|
+
([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
|
|
133
|
+
|
|
134
|
+
## [2.101.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.101.4...@graphcommerce/magento-category@2.101.5) (2021-08-03)
|
|
135
|
+
|
|
136
|
+
### Bug Fixes
|
|
137
|
+
|
|
138
|
+
- remove magento-category package from magento-product solving a circular
|
|
139
|
+
dependency
|
|
140
|
+
([7379e6e](https://github.com/ho-nl/m2-pwa/commit/7379e6ede4829392b35008c17743181d9cac0636))
|
|
141
|
+
|
|
142
|
+
# [2.101.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.100.18...@graphcommerce/magento-category@2.101.0) (2021-07-26)
|
|
143
|
+
|
|
144
|
+
### Features
|
|
145
|
+
|
|
146
|
+
- **playwright:** added new playwright package to enable browser testing
|
|
147
|
+
([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
|
|
148
|
+
|
|
149
|
+
## [2.100.17](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.100.16...@graphcommerce/magento-category@2.100.17) (2021-07-23)
|
|
150
|
+
|
|
151
|
+
### Bug Fixes
|
|
152
|
+
|
|
153
|
+
- **app-shell-header:** title offset top not correctly set
|
|
154
|
+
([c144309](https://github.com/ho-nl/m2-pwa/commit/c1443095317c1779074f3a4058f4041159c8e31b))
|
|
155
|
+
- category hero nav margin top
|
|
156
|
+
([31f8dee](https://github.com/ho-nl/m2-pwa/commit/31f8deed1d545d78bb856d4cfdfe0c7ec8671308))
|
|
157
|
+
|
|
158
|
+
## [2.100.11](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-category@2.100.10...@graphcommerce/magento-category@2.100.11) (2021-07-20)
|
|
159
|
+
|
|
160
|
+
### Bug Fixes
|
|
161
|
+
|
|
162
|
+
- ignore md files from triggering version updates
|
|
163
|
+
([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type CategoryBreadcrumbFragment = { uid: string, breadcrumbs?: Types.Maybe<Array<Types.Maybe<{ category_uid: string, category_name?: Types.Maybe<string>, category_url_path?: Types.Maybe<string> }>>> };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type CategoryChildrenFragment = { uid: string, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, name?: Types.Maybe<string>, level?: Types.Maybe<number>, url_path?: Types.Maybe<string> }>>> };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { cloneDeep } from '@apollo/client/utilities'
|
|
2
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
3
|
+
import { Scroller, ScrollerProvider } from '@graphcommerce/framer-scroller'
|
|
4
|
+
import { ProductListLink, ProductListParams } from '@graphcommerce/magento-product'
|
|
5
|
+
import { UseStyles } from '@graphcommerce/next-ui'
|
|
6
|
+
import React from 'react'
|
|
7
|
+
import { CategoryChildrenFragment } from './CategoryChildren.gql'
|
|
8
|
+
|
|
9
|
+
const useStyles = makeStyles(
|
|
10
|
+
(theme: Theme) => ({
|
|
11
|
+
container: {
|
|
12
|
+
display: 'flex',
|
|
13
|
+
justifyContent: 'center',
|
|
14
|
+
marginBottom: theme.spacings.sm,
|
|
15
|
+
},
|
|
16
|
+
scroller: {
|
|
17
|
+
display: 'grid',
|
|
18
|
+
gridAutoFlow: 'column',
|
|
19
|
+
},
|
|
20
|
+
link: {
|
|
21
|
+
whiteSpace: 'nowrap',
|
|
22
|
+
display: 'block',
|
|
23
|
+
marginRight: `${theme.spacings.xxs}`,
|
|
24
|
+
marginLeft: `${theme.spacings.xxs}`,
|
|
25
|
+
...theme.typography.h6,
|
|
26
|
+
position: 'relative',
|
|
27
|
+
paddingBottom: 8,
|
|
28
|
+
'&:before': {
|
|
29
|
+
content: '""',
|
|
30
|
+
width: 40,
|
|
31
|
+
height: 2,
|
|
32
|
+
background: theme.palette.primary.main,
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
bottom: -8,
|
|
35
|
+
left: 0,
|
|
36
|
+
right: 0,
|
|
37
|
+
margin: '0 auto',
|
|
38
|
+
opacity: 0,
|
|
39
|
+
transition: 'opacity .2s ease, bottom .2s ease',
|
|
40
|
+
},
|
|
41
|
+
'&:hover': {
|
|
42
|
+
'&:before': {
|
|
43
|
+
opacity: 1,
|
|
44
|
+
bottom: 5,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
{
|
|
50
|
+
name: 'CategoryChildren',
|
|
51
|
+
},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
type CategoryChildrenProps = Omit<CategoryChildrenFragment, 'uid'> & {
|
|
55
|
+
params: ProductListParams
|
|
56
|
+
} & UseStyles<typeof useStyles>
|
|
57
|
+
|
|
58
|
+
export default function CategoryChildren(props: CategoryChildrenProps) {
|
|
59
|
+
const { children, params } = props
|
|
60
|
+
const classes = useStyles(props)
|
|
61
|
+
|
|
62
|
+
if (!children || children.length === 0) return null
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ScrollerProvider scrollSnapAlign='none'>
|
|
66
|
+
<div className={classes.container}>
|
|
67
|
+
<Scroller className={classes.scroller}>
|
|
68
|
+
{children.map((cat) => {
|
|
69
|
+
if (!cat?.url_path || !cat.name) return null
|
|
70
|
+
|
|
71
|
+
const linkParams = cloneDeep(params)
|
|
72
|
+
linkParams.url = cat.url_path
|
|
73
|
+
delete linkParams.currentPage
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<ProductListLink
|
|
77
|
+
key={cat.url_path}
|
|
78
|
+
underline='none'
|
|
79
|
+
color='inherit'
|
|
80
|
+
{...linkParams}
|
|
81
|
+
className={classes.link}
|
|
82
|
+
>
|
|
83
|
+
{cat.name}
|
|
84
|
+
</ProductListLink>
|
|
85
|
+
)
|
|
86
|
+
})}
|
|
87
|
+
</Scroller>
|
|
88
|
+
</div>
|
|
89
|
+
</ScrollerProvider>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
2
|
+
import { UseStyles } from '@graphcommerce/next-ui'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { CategoryDescriptionFragment } from './CategoryDescription.gql'
|
|
5
|
+
|
|
6
|
+
type CategoryDescriptionProps = Omit<CategoryDescriptionFragment, 'uid'> &
|
|
7
|
+
JSX.IntrinsicElements['div'] &
|
|
8
|
+
UseStyles<typeof useStyles>
|
|
9
|
+
|
|
10
|
+
const useStyles = makeStyles(
|
|
11
|
+
(theme: Theme) => ({
|
|
12
|
+
root: {
|
|
13
|
+
gridArea: 'description',
|
|
14
|
+
margin: '0 auto',
|
|
15
|
+
textAlign: 'center',
|
|
16
|
+
maxWidth: 732,
|
|
17
|
+
marginTop: theme.spacings.md,
|
|
18
|
+
marginBottom: theme.spacings.sm,
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
{ name: 'CategoryDescription' },
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export default function CategoryDescription(props: CategoryDescriptionProps) {
|
|
25
|
+
const { name, description, display_mode, ...divProps } = props
|
|
26
|
+
const classes = useStyles(props)
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div {...divProps} className={classes.root}>
|
|
30
|
+
<Typography variant='h2' component='h1' align='center'>
|
|
31
|
+
{name}
|
|
32
|
+
</Typography>
|
|
33
|
+
{/* todo: replace with proper content renderer */}
|
|
34
|
+
{/* eslint-disable-next-line react/no-danger */}
|
|
35
|
+
{description && <div dangerouslySetInnerHTML={{ __html: description }} />}
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type CategoryHeroNavFragment = { uid: string, level?: Types.Maybe<number>, is_anchor?: Types.Maybe<number>, name?: Types.Maybe<string>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, url_path?: Types.Maybe<string>, name?: Types.Maybe<string> }>>> };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { makeStyles, Theme, Typography } from '@material-ui/core'
|
|
2
|
+
import { ProductListLink } from '@graphcommerce/magento-product'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { CategoryHeroNavFragment } from './CategoryHeroNav.gql'
|
|
5
|
+
|
|
6
|
+
const useStyles = makeStyles(
|
|
7
|
+
(theme: Theme) => ({
|
|
8
|
+
wrapper: {
|
|
9
|
+
display: 'grid',
|
|
10
|
+
gridTemplateColumns: '1fr',
|
|
11
|
+
gridTemplateAreas: `"title" "categories" "placeholder"`,
|
|
12
|
+
gridTemplateRows: 'auto 60vw',
|
|
13
|
+
borderBottom: '1px solid rgba(0,0,0,0.15)',
|
|
14
|
+
marginBottom: theme.spacings.xl,
|
|
15
|
+
paddingRight: 0,
|
|
16
|
+
paddingBottom: theme.page.vertical,
|
|
17
|
+
[theme.breakpoints.up('md')]: {
|
|
18
|
+
rowGap: theme.spacings.md,
|
|
19
|
+
width: '100%',
|
|
20
|
+
paddingRight: theme.page.horizontal,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
categories: {
|
|
24
|
+
gridArea: 'categories',
|
|
25
|
+
display: 'grid',
|
|
26
|
+
gridColumnGap: theme.spacings.xl,
|
|
27
|
+
gridTemplateColumns: 'repeat(2, min-content)',
|
|
28
|
+
gridRowGap: theme.spacings.lg,
|
|
29
|
+
height: 'min-content',
|
|
30
|
+
alignSelf: 'center',
|
|
31
|
+
maxWidth: '80vw',
|
|
32
|
+
justifySelf: 'center',
|
|
33
|
+
[theme.breakpoints.up('md')]: {
|
|
34
|
+
gridColumnGap: theme.spacings.md,
|
|
35
|
+
gridRowGap: theme.spacings.md,
|
|
36
|
+
gridTemplateColumns: 'repeat(2, 1fr)',
|
|
37
|
+
maxWidth: '100vw',
|
|
38
|
+
width: '100%',
|
|
39
|
+
alignSelf: 'flex-start',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
title: {
|
|
43
|
+
gridArea: 'title',
|
|
44
|
+
position: 'relative',
|
|
45
|
+
alignSelf: 'center',
|
|
46
|
+
[theme.breakpoints.up('md')]: {
|
|
47
|
+
alignSelf: 'flex-end',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
placeholder: {
|
|
51
|
+
gridArea: 'placeholder',
|
|
52
|
+
background: '#fff',
|
|
53
|
+
minHeight: '40vh',
|
|
54
|
+
overflow: 'hidden',
|
|
55
|
+
|
|
56
|
+
'& *': {
|
|
57
|
+
width: '100%',
|
|
58
|
+
height: '100%',
|
|
59
|
+
objectFit: 'cover',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
[theme.breakpoints.up('md')]: {
|
|
63
|
+
placeholder: {
|
|
64
|
+
minHeight: '80vh',
|
|
65
|
+
},
|
|
66
|
+
wrapper: {
|
|
67
|
+
paddingTop: 0,
|
|
68
|
+
gridColumnGap: 0,
|
|
69
|
+
display: 'grid',
|
|
70
|
+
gridTemplateAreas: `
|
|
71
|
+
". title . placeholder"
|
|
72
|
+
". categories . placeholder"
|
|
73
|
+
`,
|
|
74
|
+
gridTemplateColumns: '1fr 4.6fr 0.4fr 8fr',
|
|
75
|
+
gridTemplateRows: '0.3fr 0.7fr',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
{ name: 'CategoryHeroNav' },
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
type Props = {
|
|
83
|
+
title: React.ReactNode
|
|
84
|
+
asset?: React.ReactNode
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type CategoryHeroNavProps = Props & CategoryHeroNavFragment
|
|
88
|
+
|
|
89
|
+
export default function CategoryHeroNav({ children, title, asset }: CategoryHeroNavProps) {
|
|
90
|
+
const classes = useStyles()
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<>
|
|
94
|
+
<div className={classes.wrapper}>
|
|
95
|
+
<div className={classes.title}>{title}</div>
|
|
96
|
+
<div className={classes.categories}>
|
|
97
|
+
{children?.map((category) => {
|
|
98
|
+
if (!category?.url_path || !category.uid || !category.name) return null
|
|
99
|
+
return (
|
|
100
|
+
<ProductListLink
|
|
101
|
+
underline='none'
|
|
102
|
+
color='textPrimary'
|
|
103
|
+
url={category.url_path}
|
|
104
|
+
filters={{}}
|
|
105
|
+
sort={{}}
|
|
106
|
+
key={category.uid}
|
|
107
|
+
>
|
|
108
|
+
<Typography variant='h4' component='span'>
|
|
109
|
+
{category.name}
|
|
110
|
+
</Typography>
|
|
111
|
+
</ProductListLink>
|
|
112
|
+
)
|
|
113
|
+
})}
|
|
114
|
+
</div>
|
|
115
|
+
<div className={classes.placeholder}>{asset}</div>
|
|
116
|
+
</div>
|
|
117
|
+
</>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { makeStyles, Theme } from '@material-ui/core'
|
|
2
|
+
import { AppShellTitle } from '@graphcommerce/next-ui'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
const useStyles = makeStyles(
|
|
6
|
+
(theme: Theme) => ({
|
|
7
|
+
root: {
|
|
8
|
+
marginTop: 0,
|
|
9
|
+
marginBottom: 0,
|
|
10
|
+
},
|
|
11
|
+
container: {
|
|
12
|
+
padding: 0,
|
|
13
|
+
},
|
|
14
|
+
title: {
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
[theme.breakpoints.up('md')]: {
|
|
18
|
+
alignItems: 'flex-start',
|
|
19
|
+
justifyContent: 'flex-end',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
{ name: 'CategoryHeroNavTitle' },
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
type CategoryHeroNavTitleProps = {
|
|
27
|
+
children: React.ReactNode
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function CategoryHeroNavTitle(props: CategoryHeroNavTitleProps) {
|
|
31
|
+
const { children } = props
|
|
32
|
+
const classes = useStyles()
|
|
33
|
+
|
|
34
|
+
return <AppShellTitle classes={classes}>{children}</AppShellTitle>
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ProductListParams } from '@graphcommerce/magento-product'
|
|
2
|
+
import { PageMeta } from '@graphcommerce/magento-store'
|
|
3
|
+
import { PageMetaProps } from '@graphcommerce/next-ui'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import { CategoryMetaFragment } from './CategoryMeta.gql'
|
|
6
|
+
|
|
7
|
+
type CategoryMetaProps = CategoryMetaFragment &
|
|
8
|
+
Omit<PageMetaProps, 'title' | 'metaDescription'> & {
|
|
9
|
+
params?: ProductListParams
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function CategoryMeta(props: CategoryMetaProps) {
|
|
13
|
+
const { name, meta_title, meta_description, params, ...pageMetaProps } = props
|
|
14
|
+
const anyFilterActive = Object.keys(params?.filters ?? {}).length > 0
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<PageMeta
|
|
18
|
+
title={meta_title ?? name ?? ''}
|
|
19
|
+
metaDescription={meta_description ?? undefined}
|
|
20
|
+
metaRobots={anyFilterActive ? ['noindex'] : undefined}
|
|
21
|
+
canonical={`${params?.url}${
|
|
22
|
+
(params?.currentPage ?? 1) > 1 ? `/q/page/${params?.currentPage}` : ''
|
|
23
|
+
}`}
|
|
24
|
+
{...pageMetaProps}
|
|
25
|
+
/>
|
|
26
|
+
)
|
|
27
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as CategoryChildren } from './components/CategoryChildren/CategoryChildren'
|
|
2
|
+
export { default as CategoryDescription } from './components/CategoryDescription/CategoryDescription'
|
|
3
|
+
export { default as CategoryHeroNav } from './components/CategoryHeroNav/CategoryHeroNav'
|
|
4
|
+
export { default as CategoryHeroNavTitle } from './components/CategoryHeroNav/CategoryHeroNavTitle'
|
|
5
|
+
export { default as CategoryMeta } from './components/CategoryMeta/CategoryMeta'
|
|
6
|
+
|
|
7
|
+
export * from './queries/getCategoryStaticPaths'
|
package/next-env.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/magento-category",
|
|
3
|
+
"version": "3.0.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
6
|
+
"browserslist": [
|
|
7
|
+
"extends @graphcommerce/browserslist-config-pwa"
|
|
8
|
+
],
|
|
9
|
+
"eslintConfig": {
|
|
10
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": "./tsconfig.json"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@graphcommerce/browserslist-config-pwa": "^3.0.1",
|
|
17
|
+
"@graphcommerce/eslint-config-pwa": "^3.0.1",
|
|
18
|
+
"@graphcommerce/prettier-config-pwa": "^3.0.1",
|
|
19
|
+
"@graphcommerce/typescript-config-pwa": "^3.0.1",
|
|
20
|
+
"@playwright/test": "^1.14.1"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@apollo/client": "^3.3.21",
|
|
24
|
+
"@graphcommerce/framer-scroller": "^0.2.1",
|
|
25
|
+
"@graphcommerce/graphql": "^2.103.1",
|
|
26
|
+
"@graphcommerce/image": "^2.104.1",
|
|
27
|
+
"@graphcommerce/magento-product": "^3.0.1",
|
|
28
|
+
"@graphcommerce/magento-store": "^3.0.1",
|
|
29
|
+
"@graphcommerce/next-ui": "^3.0.1",
|
|
30
|
+
"@graphql-typed-document-node/core": "^3.1.0",
|
|
31
|
+
"@material-ui/core": "^4.12.3",
|
|
32
|
+
"next": "^11.1.2",
|
|
33
|
+
"react": "^17.0.2",
|
|
34
|
+
"react-dom": "^17.0.2",
|
|
35
|
+
"type-fest": "^2.1.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
+
|
|
6
|
+
export const CategoryPageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"CategoryPage"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"url"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"categories"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"url_path"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"url"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"display_mode"}},{"kind":"Field","name":{"kind":"Name","value":"children"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"level"}},{"kind":"Field","name":{"kind":"Name","value":"url_path"}}]}},{"kind":"Field","name":{"kind":"Name","value":"meta_title"}},{"kind":"Field","name":{"kind":"Name","value":"meta_description"}},{"kind":"Field","name":{"kind":"Name","value":"level"}},{"kind":"Field","name":{"kind":"Name","value":"is_anchor"}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CategoryInterface"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"breadcrumbs"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"category_uid"}},{"kind":"Field","name":{"kind":"Name","value":"category_name"}},{"kind":"Field","name":{"kind":"Name","value":"category_url_path"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<CategoryPageQuery, CategoryPageQueryVariables>;
|
|
7
|
+
export type CategoryPageQueryVariables = Types.Exact<{
|
|
8
|
+
url: Types.Scalars['String'];
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export type CategoryPageQuery = { categories?: Types.Maybe<{ items?: Types.Maybe<Array<Types.Maybe<{ uid: string, description?: Types.Maybe<string>, name?: Types.Maybe<string>, display_mode?: Types.Maybe<string>, meta_title?: Types.Maybe<string>, meta_description?: Types.Maybe<string>, level?: Types.Maybe<number>, is_anchor?: Types.Maybe<number>, breadcrumbs?: Types.Maybe<Array<Types.Maybe<{ category_uid: string, category_name?: Types.Maybe<string>, category_url_path?: Types.Maybe<string> }>>>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, name?: Types.Maybe<string>, level?: Types.Maybe<number>, url_path?: Types.Maybe<string> }>>> }>>> }> };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type CategoryQueryFragment = { categories?: Types.Maybe<{ items?: Types.Maybe<Array<Types.Maybe<{ uid: string, description?: Types.Maybe<string>, name?: Types.Maybe<string>, display_mode?: Types.Maybe<string>, meta_title?: Types.Maybe<string>, meta_description?: Types.Maybe<string>, level?: Types.Maybe<number>, is_anchor?: Types.Maybe<number>, breadcrumbs?: Types.Maybe<Array<Types.Maybe<{ category_uid: string, category_name?: Types.Maybe<string>, category_url_path?: Types.Maybe<string> }>>>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, name?: Types.Maybe<string>, level?: Types.Maybe<number>, url_path?: Types.Maybe<string> }>>> }>>> }> };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
5
|
+
|
|
6
|
+
export const GetCategoryStaticPathsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCategoryStaticPaths"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"rootCategory"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"categories"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"parent_category_uid"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"rootCategory"}}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"url_path"}},{"kind":"Field","name":{"kind":"Name","value":"children"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"url_path"}},{"kind":"Field","name":{"kind":"Name","value":"children"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"url_path"}},{"kind":"Field","name":{"kind":"Name","value":"children"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"uid"}},{"kind":"Field","name":{"kind":"Name","value":"url_path"}}]}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetCategoryStaticPathsQuery, GetCategoryStaticPathsQueryVariables>;
|
|
7
|
+
export type GetCategoryStaticPathsQueryVariables = Types.Exact<{
|
|
8
|
+
rootCategory: Types.Scalars['String'];
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export type GetCategoryStaticPathsQuery = { categories?: Types.Maybe<{ items?: Types.Maybe<Array<Types.Maybe<{ uid: string, url_path?: Types.Maybe<string>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, url_path?: Types.Maybe<string>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, url_path?: Types.Maybe<string>, children?: Types.Maybe<Array<Types.Maybe<{ uid: string, url_path?: Types.Maybe<string> }>>> }>>> }>>> }>>> }> };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
query GetCategoryStaticPaths($rootCategory: String!) {
|
|
2
|
+
categories(filters: { parent_category_uid: { eq: $rootCategory } }) {
|
|
3
|
+
items {
|
|
4
|
+
uid
|
|
5
|
+
url_path
|
|
6
|
+
children {
|
|
7
|
+
uid
|
|
8
|
+
url_path
|
|
9
|
+
children {
|
|
10
|
+
uid
|
|
11
|
+
url_path
|
|
12
|
+
children {
|
|
13
|
+
uid
|
|
14
|
+
url_path
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type MenuQueryFragment = { menu?: Types.Maybe<{ items?: Types.Maybe<Array<Types.Maybe<{ uid: string, name?: Types.Maybe<string>, url_path?: Types.Maybe<string>, include_in_menu?: Types.Maybe<number> }>>> }> };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ApolloClient, NormalizedCacheObject } from '@apollo/client'
|
|
2
|
+
import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
|
3
|
+
import { GetStaticPathsResult } from 'next'
|
|
4
|
+
import {
|
|
5
|
+
GetCategoryStaticPathsDocument,
|
|
6
|
+
GetCategoryStaticPathsQuery,
|
|
7
|
+
} from './GetCategoryStaticPaths.gql'
|
|
8
|
+
|
|
9
|
+
type StaticPathsResult = GetStaticPathsResult<{ url: string[] }>
|
|
10
|
+
|
|
11
|
+
const getCategoryStaticPaths = async (
|
|
12
|
+
client: ApolloClient<NormalizedCacheObject>,
|
|
13
|
+
locale: string,
|
|
14
|
+
) => {
|
|
15
|
+
const rootCategory =
|
|
16
|
+
(await client.query({ query: StoreConfigDocument })).data.storeConfig?.root_category_uid ?? ''
|
|
17
|
+
|
|
18
|
+
const { data } = await client.query({
|
|
19
|
+
query: GetCategoryStaticPathsDocument,
|
|
20
|
+
variables: { rootCategory },
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const paths: StaticPathsResult['paths'] = []
|
|
24
|
+
|
|
25
|
+
type Category = NonNullable<NonNullable<GetCategoryStaticPathsQuery['categories']>['items']>[0]
|
|
26
|
+
const add = (cat: Category) => {
|
|
27
|
+
if (cat?.url_path) paths.push({ params: { url: cat.url_path.split('/') }, locale })
|
|
28
|
+
if (cat?.children) cat.children.forEach(add)
|
|
29
|
+
}
|
|
30
|
+
data.categories?.items?.forEach(add)
|
|
31
|
+
|
|
32
|
+
return process.env.VERCEL_ENV !== 'production' ? paths.slice(0, 1) : paths
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { getCategoryStaticPaths }
|