@graphcommerce/magento-category 4.5.12 → 4.7.0

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,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1662](https://github.com/graphcommerce-org/graphcommerce/pull/1662) [`de8925aa9`](https://github.com/graphcommerce-org/graphcommerce/commit/de8925aa910b191c62041530c68c697a58a1e52d) Thanks [@paales](https://github.com/paales)! - Allow for a custom Component for magentoMenuToNavigation and allow React.ReactNode for items
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`0c21c5c23`](https://github.com/graphcommerce-org/graphcommerce/commit/0c21c5c233ebab15f6629c234e3de1cc8c0452e1), [`de8925aa9`](https://github.com/graphcommerce-org/graphcommerce/commit/de8925aa910b191c62041530c68c697a58a1e52d), [`f5eae0afd`](https://github.com/graphcommerce-org/graphcommerce/commit/f5eae0afdbd474b1f81c450425ffadf2d025187a)]:
12
+ - @graphcommerce/next-ui@4.28.0
13
+ - @graphcommerce/framer-scroller@2.1.40
14
+ - @graphcommerce/magento-product@4.7.1
15
+ - @graphcommerce/magento-store@4.3.1
16
+
17
+ ## 4.6.0
18
+
19
+ ### Minor Changes
20
+
21
+ - [#1659](https://github.com/graphcommerce-org/graphcommerce/pull/1659) [`6987ec7d2`](https://github.com/graphcommerce-org/graphcommerce/commit/6987ec7d21ce2d481fabbd6eda039702fcf5242b) Thanks [@Jessevdpoel](https://github.com/Jessevdpoel)! - Added product and category breadcrumbs
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`6987ec7d2`](https://github.com/graphcommerce-org/graphcommerce/commit/6987ec7d21ce2d481fabbd6eda039702fcf5242b)]:
26
+ - @graphcommerce/magento-product@4.7.0
27
+
3
28
  ## 4.5.12
4
29
 
5
30
  ### Patch Changes
@@ -1,5 +1,8 @@
1
1
  fragment CategoryBreadcrumb on CategoryInterface {
2
2
  uid
3
+ name
4
+ url_path
5
+ include_in_menu
3
6
  breadcrumbs {
4
7
  category_uid
5
8
  category_name
@@ -0,0 +1,32 @@
1
+ import { Trans } from '@lingui/react'
2
+ import { Breadcrumbs, BreadcrumbsProps, Container, Link, Typography } from '@mui/material'
3
+ import PageLink from 'next/link'
4
+ import { CategoryBreadcrumbFragment } from './CategoryBreadcrumb.gql'
5
+
6
+ type CategoryPageBreadcrumbsProps = CategoryBreadcrumbFragment & BreadcrumbsProps
7
+
8
+ export function CategoryBreadcrumb(props: CategoryPageBreadcrumbsProps) {
9
+ const { breadcrumbs, name } = props
10
+ return (
11
+ <Container maxWidth={false}>
12
+ <Breadcrumbs>
13
+ <PageLink href='/' passHref>
14
+ <Link underline='hover' color='inherit'>
15
+ <Trans id='Home' />
16
+ </Link>
17
+ </PageLink>
18
+ {breadcrumbs?.map((mapped_category, i) => (
19
+ <Link
20
+ underline='hover'
21
+ key={mapped_category?.category_uid}
22
+ color='inherit'
23
+ href={`/${mapped_category?.category_url_path}`}
24
+ >
25
+ {mapped_category?.category_name}
26
+ </Link>
27
+ ))}
28
+ <Typography color='text.primary'>{name}</Typography>
29
+ </Breadcrumbs>
30
+ </Container>
31
+ )
32
+ }
@@ -0,0 +1,2 @@
1
+ export * from './CategoryBreadcrumb'
2
+ export * from './CategoryBreadcrumb.gql'
package/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './components/CategoryHeroNav/CategoryHeroNavTitle'
5
5
  export * from './components/CategoryMeta/CategoryMeta'
6
6
  export * from './utils/magentoMenuToNavigation'
7
7
  export * from './queries/getCategoryStaticPaths'
8
+ export * from './components/CategoryBreadcrumb'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-category",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.5.12",
5
+ "version": "4.7.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,12 +19,12 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/framer-scroller": "2.1.39",
22
+ "@graphcommerce/framer-scroller": "2.1.40",
23
23
  "@graphcommerce/graphql": "3.4.8",
24
24
  "@graphcommerce/image": "3.1.9",
25
- "@graphcommerce/magento-product": "4.6.1",
26
- "@graphcommerce/magento-store": "4.3.0",
27
- "@graphcommerce/next-ui": "4.27.0"
25
+ "@graphcommerce/magento-product": "4.7.1",
26
+ "@graphcommerce/magento-store": "4.3.1",
27
+ "@graphcommerce/next-ui": "4.28.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@lingui/react": "^3.13.2",
@@ -1,7 +1,7 @@
1
- fragment NavigationItem on CategoryTree {
1
+ fragment NavigationItem on CategoryTree @injectable {
2
2
  uid
3
3
  include_in_menu
4
4
  name
5
5
  url_path
6
- children_count
6
+ level
7
7
  }
@@ -0,0 +1,86 @@
1
+ import {
2
+ NavigationNode,
3
+ NavigationNodeButton,
4
+ NavigationNodeHref,
5
+ NavigationNodeType,
6
+ nonNullable,
7
+ } from '@graphcommerce/next-ui'
8
+ import { i18n } from '@lingui/core'
9
+ import { MenuQueryFragment } from '../queries/MenuQueryFragment.gql'
10
+ import { NavigationItemFragment } from '../queries/NavigationItem.gql'
11
+
12
+ type Item = NonNullable<NonNullable<NonNullable<MenuQueryFragment['menu']>['items']>[0]>
13
+
14
+ export type MagentoNavigationItemProps = NavigationItemFragment
15
+
16
+ function categoryToNav(
17
+ props: Item | null | undefined,
18
+ Component?: React.ComponentType<MagentoNavigationItemProps>,
19
+ ): NavigationNode | undefined {
20
+ if (!props) return undefined
21
+ const { uid, children, include_in_menu, name, url_path, level } = props
22
+
23
+ if (!uid || include_in_menu !== 1 || !name) return undefined
24
+
25
+ const allName = i18n._(/* i18n */ 'All {name}', { name })
26
+ // If we've got children we make a button that navigates to childitems.
27
+ if (children && children.length > 0) {
28
+ const button: NavigationNodeButton = {
29
+ type: NavigationNodeType.BUTTON,
30
+ href: url_path ? `/${url_path}` : undefined,
31
+ name: Component ? <Component key={uid} {...props} /> : name,
32
+ id: uid,
33
+ childItems: [
34
+ ...(url_path
35
+ ? [
36
+ {
37
+ name: Component ? (
38
+ <Component key={uid} {...props} name={allName} level={(level ?? 0) + 1} />
39
+ ) : (
40
+ allName
41
+ ),
42
+ href: `/${url_path}`,
43
+ id: `${uid}-all`,
44
+ },
45
+ ]
46
+ : []),
47
+ ...children.map((child) => categoryToNav(child, Component)).filter(nonNullable),
48
+ ],
49
+ }
50
+ return button
51
+ }
52
+
53
+ // If we've got no children we make a href.
54
+ return {
55
+ name: Component ? <Component key={uid} {...props} /> : name,
56
+ id: uid,
57
+ href: `/${url_path}`,
58
+ } as NavigationNodeHref
59
+ }
60
+
61
+ /**
62
+ * Converts the Magento GraphQL category tree to a NavigationNode tree, which can be used in the
63
+ * Navigation component.
64
+ *
65
+ * To provide a custom renderer to the navigation items, pass a component as the third argument;
66
+ *
67
+ * ```tsx
68
+ * function MagentoNavigationItem(props: MagentoNavigationItemProps) {
69
+ * const { name, level } = props
70
+ * return (
71
+ * <>
72
+ * {name} {level}
73
+ * </>
74
+ * )
75
+ * }
76
+ * ```
77
+ */
78
+ export function magentoMenuToNavigation(
79
+ menu: MenuQueryFragment['menu'],
80
+ includeRoot: boolean,
81
+ Component?: React.ComponentType<MagentoNavigationItemProps>,
82
+ ) {
83
+ return ((includeRoot ? menu?.items : menu?.items?.[0]?.children) || [])
84
+ .map((child) => categoryToNav(child, Component))
85
+ .filter(nonNullable)
86
+ }
@@ -1,60 +0,0 @@
1
- import {
2
- NavigationNode,
3
- NavigationNodeButton,
4
- NavigationNodeHref,
5
- nonNullable,
6
- } from '@graphcommerce/next-ui'
7
- import { i18n } from '@lingui/core'
8
- import { MenuQueryFragment } from '../queries/MenuQueryFragment.gql'
9
-
10
- export type Item = NonNullable<NonNullable<MenuQueryFragment['menu']>['items']>[0]
11
-
12
- export function categoryToNav(props: Item | null | undefined): NavigationNode | undefined {
13
- if (!props) return undefined
14
- const { uid, children, include_in_menu, name, url_path } = props
15
-
16
- if (!uid || include_in_menu !== 1 || !name) return undefined
17
-
18
- // If we've got children we make a button that navigates to childitems.
19
- if (children && children.length > 0) {
20
- return {
21
- name,
22
- id: uid,
23
- childItems: [
24
- ...(url_path
25
- ? [
26
- {
27
- name: i18n._(/* i18n */ 'All {name}', { name }),
28
- href: `/${url_path}`,
29
- id: `${uid}-all`,
30
- },
31
- ]
32
- : []),
33
- ...children.map(categoryToNav).filter(nonNullable),
34
- ],
35
- } as NavigationNodeButton
36
- }
37
-
38
- // If we've got no children we make a href.
39
- return { name, id: uid, href: `/${url_path}` } as NavigationNodeHref
40
- }
41
-
42
- /**
43
- * Converts the Magento GraphQL category tree to a NavigationNode tree, which can be used in the
44
- * Navigation component.
45
- */
46
- export function magentoMenuToNavigation(menu: MenuQueryFragment['menu'], includeRoot: boolean) {
47
- return ((includeRoot ? menu?.items : menu?.items?.[0]?.children) || [])
48
- .map(categoryToNav)
49
- .filter(nonNullable)
50
- }
51
-
52
- /**
53
- * Converts the Magento GraphQL category tree to a NavigationNode tree, which can be used in the
54
- * Navigation component.
55
- *
56
- * @deprecated Please use magentoMenuToNavigation instead.
57
- */
58
- export function useMagentoMenuToNavigation(menu: MenuQueryFragment['menu'], includeRoot: boolean) {
59
- return magentoMenuToNavigation(menu, includeRoot)
60
- }