@graphcommerce/magento-category 4.2.3 → 4.4.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,50 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1591](https://github.com/graphcommerce-org/graphcommerce/pull/1591) [`eee08c956`](https://github.com/graphcommerce-org/graphcommerce/commit/eee08c956fbcc4fe8d915b6fa8b399dafca69acd) Thanks [@ErwinOtten](https://github.com/ErwinOtten)! - Remove need for rootCategory query
8
+
9
+ * [#1591](https://github.com/graphcommerce-org/graphcommerce/pull/1591) [`79f057889`](https://github.com/graphcommerce-org/graphcommerce/commit/79f057889847c61d75db7f567fd6575a57cf1022) Thanks [@ErwinOtten](https://github.com/ErwinOtten)! - Remove need for query rootCategory
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1596](https://github.com/graphcommerce-org/graphcommerce/pull/1596) [`3a619b70d`](https://github.com/graphcommerce-org/graphcommerce/commit/3a619b70d082804b8de46a8e8232f9431479a8b7) Thanks [@paales](https://github.com/paales)! - Make sure the canonical of a page doesn’t contain a double forward slash
14
+
15
+ - Updated dependencies [[`43822fd61`](https://github.com/graphcommerce-org/graphcommerce/commit/43822fd61c949215b8ddce9fb37d09f29b638426), [`3a619b70d`](https://github.com/graphcommerce-org/graphcommerce/commit/3a619b70d082804b8de46a8e8232f9431479a8b7)]:
16
+ - @graphcommerce/next-ui@4.20.0
17
+ - @graphcommerce/framer-scroller@2.1.31
18
+ - @graphcommerce/magento-product@4.4.24
19
+ - @graphcommerce/magento-store@4.2.26
20
+
21
+ ## 4.3.1
22
+
23
+ ### Patch Changes
24
+
25
+ - [#1588](https://github.com/graphcommerce-org/graphcommerce/pull/1588) [`42030e04b`](https://github.com/graphcommerce-org/graphcommerce/commit/42030e04b2ebe004379c6f052e10407c2f5df18f) Thanks [@paales](https://github.com/paales)! - Make sure the canonical of a page doesn’t contain a double forward slash
26
+
27
+ - Updated dependencies [[`b6d3a3c13`](https://github.com/graphcommerce-org/graphcommerce/commit/b6d3a3c13ea63ef0f691f497507f07c0e094de5b)]:
28
+ - @graphcommerce/next-ui@4.19.0
29
+ - @graphcommerce/framer-scroller@2.1.30
30
+ - @graphcommerce/magento-product@4.4.23
31
+ - @graphcommerce/magento-store@4.2.25
32
+
33
+ ## 4.3.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [#1577](https://github.com/graphcommerce-org/graphcommerce/pull/1577) [`ad55e6c50`](https://github.com/graphcommerce-org/graphcommerce/commit/ad55e6c50c3a3223ee2c17826881808fa9d8f27c) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Added improvements voor the category pages' meta description
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`6ce2cbaf2`](https://github.com/graphcommerce-org/graphcommerce/commit/6ce2cbaf2cf27e21b753f7cb71e7e74826294de6), [`6ce2cbaf2`](https://github.com/graphcommerce-org/graphcommerce/commit/6ce2cbaf2cf27e21b753f7cb71e7e74826294de6), [`6ce2cbaf2`](https://github.com/graphcommerce-org/graphcommerce/commit/6ce2cbaf2cf27e21b753f7cb71e7e74826294de6)]:
42
+ - @graphcommerce/magento-product@4.4.22
43
+ - @graphcommerce/graphql@3.4.5
44
+ - @graphcommerce/next-ui@4.18.0
45
+ - @graphcommerce/magento-store@4.2.24
46
+ - @graphcommerce/framer-scroller@2.1.29
47
+
3
48
  ## 4.2.3
4
49
 
5
50
  ### Patch Changes
@@ -1,32 +1,50 @@
1
1
  import { ProductListParams } from '@graphcommerce/magento-product'
2
2
  import { PageMeta } from '@graphcommerce/magento-store'
3
3
  import { PageMetaProps } from '@graphcommerce/next-ui'
4
+ import { i18n } from '@lingui/core'
4
5
  import { CategoryMetaFragment } from './CategoryMeta.gql'
5
6
 
6
- type CategoryMetaProps = CategoryMetaFragment &
7
- Omit<PageMetaProps, 'title' | 'metaDescription'> & {
7
+ export type CategoryMetaProps = CategoryMetaFragment &
8
+ Partial<PageMetaProps> & {
8
9
  params?: ProductListParams
9
10
  current_page?: number | null | undefined
10
11
  }
11
12
 
12
13
  export function CategoryMeta(props: CategoryMetaProps) {
13
- const { name, meta_title, meta_description, current_page, params, ...pageMetaProps } = props
14
+ const { meta_title, meta_description, name, params, current_page } = props
15
+ let {
16
+ title = meta_title ?? name ?? '',
17
+ metaDescription = meta_description ?? undefined,
18
+ metaRobots,
19
+ canonical,
20
+ } = props
21
+
22
+ if (params?.url && !canonical) canonical = `/${params.url}`
23
+
14
24
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
15
25
  const anyFilterActive = Object.keys(params?.filters ?? {}).length > 0
26
+ const currentPage = params?.currentPage ?? 1
27
+ const isPaginated = currentPage > 1 && !anyFilterActive
28
+
29
+ const titleTrans =
30
+ title && isPaginated
31
+ ? i18n._(/* i18n */ '{title} - Page {currentPage}', { title, currentPage })
32
+ : title
33
+
34
+ const metaDescriptionTrans =
35
+ metaDescription && isPaginated
36
+ ? i18n._(/* i18n */ '{metaDescription} - Page {currentPage}', {
37
+ metaDescription,
38
+ currentPage,
39
+ })
40
+ : metaDescription
16
41
 
17
42
  return (
18
43
  <PageMeta
19
- title={`${meta_title ?? name ?? ''} ${
20
- current_page && current_page > 1 ? `- Page ${current_page}` : ''
21
- }`}
22
- metaDescription={`${meta_description ?? undefined} ${
23
- current_page && current_page > 1 ? `- Page ${current_page}` : ''
24
- }`}
25
- metaRobots={anyFilterActive ? ['noindex'] : undefined}
26
- canonical={`/${params?.url}${
27
- (params?.currentPage ?? 1) > 1 ? `/q/page/${params?.currentPage}` : ''
28
- }`}
29
- {...pageMetaProps}
44
+ title={titleTrans}
45
+ metaDescription={metaDescriptionTrans}
46
+ metaRobots={anyFilterActive ? ['noindex'] : metaRobots}
47
+ canonical={isPaginated ? `${canonical}/q/page/${currentPage}` : canonical}
30
48
  />
31
49
  )
32
50
  }
@@ -13,7 +13,7 @@ export function categoryToNav(props: Item | null | undefined): NavigationNode |
13
13
  if (!props) return undefined
14
14
  const { uid, children, include_in_menu, name, url_path } = props
15
15
 
16
- if (!uid || include_in_menu !== 1 || !url_path || !name) return undefined
16
+ if (!uid || include_in_menu !== 1 || !name) return undefined
17
17
 
18
18
  // If we've got children we make a button that navigates to childitems.
19
19
  if (children && children.length > 0) {
@@ -21,7 +21,15 @@ export function categoryToNav(props: Item | null | undefined): NavigationNode |
21
21
  name,
22
22
  id: uid,
23
23
  childItems: [
24
- { name: i18n._(/* i18n */ 'All {name}', { name }), href: `/${url_path}`, id: `${uid}-all` },
24
+ ...(url_path
25
+ ? [
26
+ {
27
+ name: i18n._(/* i18n */ 'All {name}', { name }),
28
+ href: `/${url_path}`,
29
+ id: `${uid}-all`,
30
+ },
31
+ ]
32
+ : []),
25
33
  ...children.map(categoryToNav).filter(nonNullable),
26
34
  ],
27
35
  } as NavigationNodeButton
@@ -35,6 +43,8 @@ export function categoryToNav(props: Item | null | undefined): NavigationNode |
35
43
  * Converts the Magento GraphQL category tree to a NavigationNode tree, which can be used in the
36
44
  * Navigation component.
37
45
  */
38
- export function useMagentoMenuToNavigation(menu: MenuQueryFragment['menu']) {
39
- return (menu?.items ?? []).map(categoryToNav).filter(nonNullable)
46
+ export function useMagentoMenuToNavigation(menu: MenuQueryFragment['menu'], includeRoot: boolean) {
47
+ return ((includeRoot ? menu?.items : menu?.items?.[0]?.children) || [])
48
+ .map(categoryToNav)
49
+ .filter(nonNullable)
40
50
  }
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.2.3",
5
+ "version": "4.4.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.28",
23
- "@graphcommerce/graphql": "3.4.4",
22
+ "@graphcommerce/framer-scroller": "2.1.31",
23
+ "@graphcommerce/graphql": "3.4.5",
24
24
  "@graphcommerce/image": "3.1.7",
25
- "@graphcommerce/magento-product": "4.4.21",
26
- "@graphcommerce/magento-store": "4.2.23",
27
- "@graphcommerce/next-ui": "4.17.0"
25
+ "@graphcommerce/magento-product": "4.4.24",
26
+ "@graphcommerce/magento-store": "4.2.26",
27
+ "@graphcommerce/next-ui": "4.20.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@lingui/react": "^3.13.2",
@@ -1,5 +1,5 @@
1
- query GetCategoryStaticPaths($rootCategory: String!) {
2
- categories(filters: { parent_category_uid: { eq: $rootCategory } }) {
1
+ query GetCategoryStaticPaths {
2
+ categories {
3
3
  items {
4
4
  uid
5
5
  url_path
@@ -12,6 +12,14 @@ query GetCategoryStaticPaths($rootCategory: String!) {
12
12
  children {
13
13
  uid
14
14
  url_path
15
+ children {
16
+ uid
17
+ url_path
18
+ children {
19
+ uid
20
+ url_path
21
+ }
22
+ }
15
23
  }
16
24
  }
17
25
  }
@@ -1,6 +1,7 @@
1
1
  fragment MenuQueryFragment on Query {
2
- menu: categories(filters: { parent_category_uid: { eq: $rootCategory } }) {
2
+ menu: categories {
3
3
  items {
4
+ uid
4
5
  ...NavigationItem
5
6
  children {
6
7
  uid
@@ -8,6 +9,10 @@ fragment MenuQueryFragment on Query {
8
9
  children {
9
10
  uid
10
11
  ...NavigationItem
12
+ children {
13
+ uid
14
+ ...NavigationItem
15
+ }
11
16
  }
12
17
  }
13
18
  }
@@ -12,12 +12,8 @@ const getCategoryStaticPaths = async (
12
12
  client: ApolloClient<NormalizedCacheObject>,
13
13
  locale: string,
14
14
  ) => {
15
- const rootCategory =
16
- (await client.query({ query: StoreConfigDocument })).data.storeConfig?.root_category_uid ?? ''
17
-
18
15
  const { data } = await client.query({
19
16
  query: GetCategoryStaticPathsDocument,
20
- variables: { rootCategory },
21
17
  })
22
18
 
23
19
  const paths: StaticPathsResult['paths'] = []