@graphcommerce/magento-product-configurable 9.0.4-canary.1 → 9.0.4-canary.11

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,29 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.4-canary.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2485](https://github.com/graphcommerce-org/graphcommerce/pull/2485) [`8b8807b`](https://github.com/graphcommerce-org/graphcommerce/commit/8b8807b8e24f1dba78dd988dfdc21316c616274f) - Solve issue where the GetConfigurableOptionsSelection query would be executed even if the product wasn't a ConfigurableProduct. ([@paales](https://github.com/paales))
8
+
9
+ ## 9.0.4-canary.10
10
+
11
+ ## 9.0.4-canary.9
12
+
13
+ ## 9.0.4-canary.8
14
+
15
+ ## 9.0.4-canary.7
16
+
17
+ ## 9.0.4-canary.6
18
+
19
+ ## 9.0.4-canary.5
20
+
21
+ ## 9.0.4-canary.4
22
+
23
+ ## 9.0.4-canary.3
24
+
25
+ ## 9.0.4-canary.2
26
+
3
27
  ## 9.0.4-canary.1
4
28
 
5
29
  ## 9.0.4-canary.0
@@ -39,6 +39,7 @@ export function ConfigurableProductOption(props: ConfigurableProductOptionProps)
39
39
  attribute_code,
40
40
  url_key,
41
41
  render,
42
+ __typename,
42
43
  ...other
43
44
  } = props
44
45
  const fieldName = `cartItems.${index}.selected_options.${optionIndex}` as const
@@ -55,7 +56,11 @@ export function ConfigurableProductOption(props: ConfigurableProductOptionProps)
55
56
  // .slice(0, optionIndex)
56
57
  .filter((o) => o !== selectedOption)
57
58
 
58
- const { configured } = useConfigurableOptionsForSelection({ url_key, selectedOptions })
59
+ const { configured } = useConfigurableOptionsForSelection({
60
+ __typename,
61
+ url_key,
62
+ selectedOptions,
63
+ })
59
64
 
60
65
  const available =
61
66
  configured?.configurable_product_options_selection?.options_available_for_selection?.find(
@@ -39,7 +39,7 @@ export function ConfigurableProductOptions(props: ConfigurableProductOptionsProp
39
39
  'values',
40
40
  ])
41
41
 
42
- const { configured } = useConfigurableOptionsSelection({ url_key: product.url_key, index })
42
+ const { configured } = useConfigurableOptionsSelection({ ...product, index })
43
43
  const unavailable =
44
44
  configured &&
45
45
  (configured?.configurable_product_options_selection?.options_available_for_selection ?? [])
@@ -75,6 +75,7 @@ export function ConfigurableProductOptions(props: ConfigurableProductOptionsProp
75
75
  index={index}
76
76
  optionIndex={optionIndex}
77
77
  sx={sx}
78
+ __typename={product.__typename}
78
79
  url_key={product.url_key}
79
80
  {...other}
80
81
  />
@@ -0,0 +1,4 @@
1
+ fragment UseConfigurableOptions on ProductInterface {
2
+ __typename
3
+ url_key
4
+ }
@@ -4,20 +4,18 @@ import { useFormAddProductsToCart } from '@graphcommerce/magento-product'
4
4
  import { findByTypename, nonNullable } from '@graphcommerce/next-ui'
5
5
  import { useWatch } from '@graphcommerce/react-hook-form'
6
6
  import { GetConfigurableOptionsSelectionDocument } from '../graphql/GetConfigurableOptionsSelection.gql'
7
-
8
- export type UseConfigurableOptionsSelection = { url_key?: string | null } & AddToCartItemSelector
7
+ import type { UseConfigurableOptionsFragment } from '../graphql/UseConfigurableOptions.gql'
9
8
 
10
9
  type UseConfigurableOptionsForSelection = {
11
- url_key?: string | null
12
10
  selectedOptions: string[]
13
- }
11
+ } & UseConfigurableOptionsFragment
14
12
 
15
13
  export function useConfigurableOptionsForSelection(variables: UseConfigurableOptionsForSelection) {
16
- const { url_key, selectedOptions } = variables
14
+ const { __typename, url_key, selectedOptions } = variables
17
15
 
18
16
  const selection = useQuery(GetConfigurableOptionsSelectionDocument, {
19
17
  variables: { urlKey: url_key ?? '', selectedOptions },
20
- skip: !url_key,
18
+ skip: __typename !== 'ConfigurableProduct' || !url_key,
21
19
  })
22
20
 
23
21
  const configured = selection.error
@@ -29,15 +27,17 @@ export function useConfigurableOptionsForSelection(variables: UseConfigurableOpt
29
27
  return { ...selection, configured }
30
28
  }
31
29
 
30
+ export type UseConfigurableOptionsSelection = UseConfigurableOptionsFragment & AddToCartItemSelector
31
+
32
32
  export function useConfigurableOptionsSelection(props: UseConfigurableOptionsSelection) {
33
- const { url_key, index = 0 } = props
33
+ const { __typename, url_key, index = 0 } = props
34
34
 
35
35
  const { control } = useFormAddProductsToCart()
36
36
  const selectedOptions = (useWatch({ control, name: `cartItems.${index}.selected_options` }) ?? [])
37
37
  .filter(nonNullable)
38
38
  .filter(Boolean)
39
39
 
40
- return useConfigurableOptionsForSelection({ url_key, selectedOptions })
40
+ return useConfigurableOptionsForSelection({ __typename, url_key, selectedOptions })
41
41
  }
42
42
 
43
43
  export function useConfigurableSelectedVariant(props: UseConfigurableOptionsSelection) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product-configurable",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.4-canary.1",
5
+ "version": "9.0.4-canary.11",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,23 +12,23 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/ecommerce-ui": "^9.0.4-canary.1",
16
- "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.1",
17
- "@graphcommerce/graphql": "^9.0.4-canary.1",
18
- "@graphcommerce/graphql-mesh": "^9.0.4-canary.1",
19
- "@graphcommerce/image": "^9.0.4-canary.1",
20
- "@graphcommerce/lingui-next": "9.0.4-canary.1",
21
- "@graphcommerce/magento-cart": "^9.0.4-canary.1",
22
- "@graphcommerce/magento-cart-items": "^9.0.4-canary.1",
23
- "@graphcommerce/magento-category": "^9.0.4-canary.1",
24
- "@graphcommerce/magento-customer": "^9.0.4-canary.1",
25
- "@graphcommerce/magento-product": "^9.0.4-canary.1",
26
- "@graphcommerce/magento-product-simple": "^9.0.4-canary.1",
27
- "@graphcommerce/magento-store": "^9.0.4-canary.1",
28
- "@graphcommerce/next-ui": "^9.0.4-canary.1",
29
- "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.1",
30
- "@graphcommerce/react-hook-form": "^9.0.4-canary.1",
31
- "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.1",
15
+ "@graphcommerce/ecommerce-ui": "^9.0.4-canary.11",
16
+ "@graphcommerce/eslint-config-pwa": "^9.0.4-canary.11",
17
+ "@graphcommerce/graphql": "^9.0.4-canary.11",
18
+ "@graphcommerce/graphql-mesh": "^9.0.4-canary.11",
19
+ "@graphcommerce/image": "^9.0.4-canary.11",
20
+ "@graphcommerce/lingui-next": "9.0.4-canary.11",
21
+ "@graphcommerce/magento-cart": "^9.0.4-canary.11",
22
+ "@graphcommerce/magento-cart-items": "^9.0.4-canary.11",
23
+ "@graphcommerce/magento-category": "^9.0.4-canary.11",
24
+ "@graphcommerce/magento-customer": "^9.0.4-canary.11",
25
+ "@graphcommerce/magento-product": "^9.0.4-canary.11",
26
+ "@graphcommerce/magento-product-simple": "^9.0.4-canary.11",
27
+ "@graphcommerce/magento-store": "^9.0.4-canary.11",
28
+ "@graphcommerce/next-ui": "^9.0.4-canary.11",
29
+ "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.11",
30
+ "@graphcommerce/react-hook-form": "^9.0.4-canary.11",
31
+ "@graphcommerce/typescript-config-pwa": "^9.0.4-canary.11",
32
32
  "@lingui/core": "^4.2.1",
33
33
  "@lingui/macro": "^4.2.1",
34
34
  "@lingui/react": "^4.2.1",
@@ -15,7 +15,7 @@ export function ProductPageDescription(
15
15
  props: PluginProps<ProductPageDescriptionProps & AddToCartItemSelector>,
16
16
  ) {
17
17
  const { Prev, product, index, ...rest } = props
18
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })
18
+ const variant = useConfigurableSelectedVariant({ ...product, index })
19
19
 
20
20
  return (
21
21
  <Prev
@@ -1,5 +1,6 @@
1
1
  import type { AddToCartItemSelector, ProductPageGalleryProps } from '@graphcommerce/magento-product'
2
2
  import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
3
+ import { isTypename } from '@graphcommerce/next-ui'
3
4
  import { useConfigurableOptionsSelection } from '../../hooks'
4
5
 
5
6
  export const config: PluginConfig = {
@@ -13,7 +14,7 @@ export function ProductPageGallery(
13
14
  ) {
14
15
  const { Prev, product, index, ...rest } = props
15
16
 
16
- const { configured } = useConfigurableOptionsSelection({ url_key: product.url_key, index })
17
+ const { configured } = useConfigurableOptionsSelection({ ...product, index })
17
18
  const media_gallery =
18
19
  (configured?.configurable_product_options_selection?.media_gallery?.length ?? 0) > 0 &&
19
20
  configured?.configurable_product_options_selection?.variant
@@ -16,6 +16,6 @@ export function ProductPageJsonLd<T extends { '@type': string }, P extends JsonL
16
16
  props: PluginProps<ProductPageJsonLdProps<T, P>> & AddToCartItemSelector,
17
17
  ) {
18
18
  const { Prev, product, index, ...rest } = props
19
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })
19
+ const variant = useConfigurableSelectedVariant({ ...product, index })
20
20
  return <Prev product={(variant ?? product) as P} {...rest} />
21
21
  }
@@ -16,7 +16,7 @@ export function ProductPageMeta(props: PluginProps<ProductPageMetaProps> & AddTo
16
16
  const { Prev, product, index, ...rest } = props
17
17
  const { replace, asPath } = useRouter()
18
18
 
19
- const variant = useConfigurableSelectedVariant({ url_key: product?.url_key, index })
19
+ const variant = useConfigurableSelectedVariant({ ...product, index })
20
20
 
21
21
  const isValidVariant = (variant?.url_rewrites ?? []).length > 0 && variant?.url_key
22
22
  const targetUrl = isValidVariant ? productLink(variant) : productLink(product)
@@ -10,6 +10,6 @@ export const config: PluginConfig = {
10
10
 
11
11
  export function ProductPageName(props: PluginProps<ProductPageNameProps> & AddToCartItemSelector) {
12
12
  const { Prev, product, index, ...rest } = props
13
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })
13
+ const variant = useConfigurableSelectedVariant({ ...product, index })
14
14
  return <Prev product={variant ?? product} {...rest} />
15
15
  }
@@ -11,7 +11,7 @@ export function ProductPagePrice(
11
11
  props: PluginProps<ProductPagePriceProps> & AddToCartItemSelector,
12
12
  ) {
13
13
  const { Prev, product, index, ...rest } = props
14
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })
14
+ const variant = useConfigurableSelectedVariant({ ...product, index })
15
15
 
16
16
  if (product.__typename !== 'ConfigurableProduct') return <Prev {...props} />
17
17
 
@@ -14,7 +14,7 @@ export function ProductPagePriceTiers(
14
14
  props: PluginProps<ProductPagePriceTiersProps> & AddToCartItemSelector,
15
15
  ) {
16
16
  const { Prev, product, index, ...rest } = props
17
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })
17
+ const variant = useConfigurableSelectedVariant({ ...product, index })
18
18
 
19
19
  if (!variant || product.__typename !== 'ConfigurableProduct')
20
20
  return <Prev product={product} {...rest} />
@@ -15,7 +15,7 @@ export function ProductShortDescription(
15
15
  props: PluginProps<ProductShortDescriptionProps> & AddToCartItemSelector,
16
16
  ) {
17
17
  const { Prev, product, ...rest } = props
18
- const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index: 0 })
18
+ const variant = useConfigurableSelectedVariant({ ...product, index: 0 })
19
19
 
20
20
  return (
21
21
  <Prev