@graphcommerce/magento-product 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/Api/ProductListItem.gql.ts +16 -0
- package/Api/ProductListItem.graphql +18 -0
- package/Api/ProductPageItem.gql.ts +16 -0
- package/Api/ProductPageItem.graphql +11 -0
- package/CHANGELOG.md +280 -0
- package/_playwright/productURL.fixture.ts +28 -0
- package/components/JsonLdProduct/JsonLdProduct.gql.ts +16 -0
- package/components/JsonLdProduct/JsonLdProduct.graphql +22 -0
- package/components/JsonLdProduct/JsonLdProductOffer.gql.ts +16 -0
- package/components/JsonLdProduct/JsonLdProductOffer.graphql +13 -0
- package/components/JsonLdProduct/index.tsx +37 -0
- package/components/ProductAddToCart/ProductAddToCart.gql.ts +15 -0
- package/components/ProductAddToCart/ProductAddToCart.graphql +21 -0
- package/components/ProductCustomizable/CustomizableAreaOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableAreaOption.graphql +11 -0
- package/components/ProductCustomizable/CustomizableCheckboxOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableCheckboxOption.graphql +11 -0
- package/components/ProductCustomizable/CustomizableDateOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableDateOption.graphql +10 -0
- package/components/ProductCustomizable/CustomizableDropDownOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableDropDownOption.graphql +12 -0
- package/components/ProductCustomizable/CustomizableFieldOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableFieldOption.graphql +11 -0
- package/components/ProductCustomizable/CustomizableFileOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableFileOption.graphql +13 -0
- package/components/ProductCustomizable/CustomizableMultipleOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableMultipleOption.graphql +12 -0
- package/components/ProductCustomizable/CustomizableOption.gql.ts +20 -0
- package/components/ProductCustomizable/CustomizableOption.graphql +6 -0
- package/components/ProductCustomizable/CustomizableRadioOption.gql.ts +4 -0
- package/components/ProductCustomizable/CustomizableRadioOption.graphql +12 -0
- package/components/ProductCustomizable/ProductCustomizable.gql.ts +14 -0
- package/components/ProductCustomizable/ProductCustomizable.graphql +13 -0
- package/components/ProductList/ProductList.gql.ts +17 -0
- package/components/ProductList/ProductList.graphql +11 -0
- package/components/ProductList/ProductListQueryFragment.gql.ts +4 -0
- package/components/ProductList/ProductListQueryFragment.graphql +14 -0
- package/components/ProductListCount/ProductListCount.gql.ts +4 -0
- package/components/ProductListCount/ProductListCount.graphql +3 -0
- package/components/ProductListCount/index.tsx +55 -0
- package/components/ProductListFilters/FilterCheckboxType.tsx +66 -0
- package/components/ProductListFilters/FilterEqualType.tsx +169 -0
- package/components/ProductListFilters/FilterRangeType.tsx +170 -0
- package/components/ProductListFilters/ProductFiltersQueryFragment.gql.ts +4 -0
- package/components/ProductListFilters/ProductFiltersQueryFragment.graphql +5 -0
- package/components/ProductListFilters/ProductListFilters.gql.ts +4 -0
- package/components/ProductListFilters/ProductListFilters.graphql +12 -0
- package/components/ProductListFilters/index.tsx +61 -0
- package/components/ProductListFiltersContainer/index.tsx +140 -0
- package/components/ProductListItem/index.tsx +223 -0
- package/components/ProductListItems/ProductListItems.gql.ts +4 -0
- package/components/ProductListItems/ProductListItems.graphql +7 -0
- package/components/ProductListItems/ProductListItemsBase.tsx +60 -0
- package/components/ProductListItems/ProductListParamsProvider.tsx +20 -0
- package/components/ProductListItems/filterTypes.tsx +45 -0
- package/components/ProductListItems/filteredProductList.tsx +74 -0
- package/components/ProductListItems/getFilterTypes.ts +51 -0
- package/components/ProductListItems/index.tsx +6 -0
- package/components/ProductListItems/renderer.tsx +16 -0
- package/components/ProductListLink/ProductListLink.tsx +50 -0
- package/components/ProductListPagination/ProductListPagination.gql.ts +4 -0
- package/components/ProductListPagination/ProductListPagination.graphql +6 -0
- package/components/ProductListPagination/index.tsx +31 -0
- package/components/ProductListPrice/ProductListPrice.gql.ts +4 -0
- package/components/ProductListPrice/ProductListPrice.graphql +12 -0
- package/components/ProductListPrice/index.tsx +36 -0
- package/components/ProductListSort/ProductListSort.gql.ts +4 -0
- package/components/ProductListSort/ProductListSort.graphql +10 -0
- package/components/ProductListSort/index.tsx +72 -0
- package/components/ProductPage/ProductPageQueryFragment.gql.ts +4 -0
- package/components/ProductPage/ProductPageQueryFragment.graphql +10 -0
- package/components/ProductPageCategory/ProductPageCategory.gql.ts +16 -0
- package/components/ProductPageCategory/ProductPageCategory.graphql +8 -0
- package/components/ProductPageCategory/index.ts +17 -0
- package/components/ProductPageDescription/ProductPageDescription.gql.ts +16 -0
- package/components/ProductPageDescription/ProductPageDescription.graphql +9 -0
- package/components/ProductPageDescription/index.tsx +54 -0
- package/components/ProductPageGallery/ProductImage.gql.ts +4 -0
- package/components/ProductPageGallery/ProductImage.graphql +4 -0
- package/components/ProductPageGallery/ProductImage.tsx +10 -0
- package/components/ProductPageGallery/ProductPageGallery.gql.ts +16 -0
- package/components/ProductPageGallery/ProductPageGallery.graphql +10 -0
- package/components/ProductPageGallery/ProductVideo.gql.ts +4 -0
- package/components/ProductPageGallery/ProductVideo.graphql +10 -0
- package/components/ProductPageGallery/ProductVideo.tsx +11 -0
- package/components/ProductPageGallery/index.tsx +37 -0
- package/components/ProductPageMeta/ProductPageMeta.gql.ts +16 -0
- package/components/ProductPageMeta/ProductPageMeta.graphql +7 -0
- package/components/ProductPageMeta/index.tsx +17 -0
- package/components/ProductPagePrice/ProductPagePrice.gql.ts +16 -0
- package/components/ProductPagePrice/ProductPagePrice.graphql +50 -0
- package/components/ProductRelated/RelatedProducts.gql.ts +16 -0
- package/components/ProductRelated/RelatedProducts.graphql +5 -0
- package/components/ProductSidebarDelivery/index.tsx +47 -0
- package/components/ProductSpecs/ProductSpecs.gql.ts +4 -0
- package/components/ProductSpecs/ProductSpecs.graphql +12 -0
- package/components/ProductSpecs/index.tsx +52 -0
- package/components/ProductStaticPaths/ProductStaticPaths.gql.ts +13 -0
- package/components/ProductStaticPaths/ProductStaticPaths.graphql +12 -0
- package/components/ProductStaticPaths/getProductStaticPaths.ts +32 -0
- package/components/ProductUpsells/UpsellProducts.gql.ts +16 -0
- package/components/ProductUpsells/UpsellProducts.graphql +5 -0
- package/components/ProductWeight/ProductWeight.gql.ts +12 -0
- package/components/ProductWeight/ProductWeight.graphql +3 -0
- package/components/ProductWeight/index.tsx +30 -0
- package/components/index.ts +45 -0
- package/context/productListParamsContext.ts +7 -0
- package/hooks/ProductLink.gql.ts +16 -0
- package/hooks/ProductLink.graphql +5 -0
- package/hooks/useProductLink.ts +20 -0
- package/hooks/useProductListLink.ts +38 -0
- package/hooks/useProductListLinkPush.ts +22 -0
- package/hooks/useProductListParamsContext.ts +4 -0
- package/index.ts +9 -0
- package/next-env.d.ts +4 -0
- package/package.json +40 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export * from './JsonLdProduct'
|
|
2
|
+
export * from './ProductAddToCart/ProductAddToCart.gql'
|
|
3
|
+
|
|
4
|
+
export * from './ProductList/ProductList.gql'
|
|
5
|
+
|
|
6
|
+
export { default as ProductListItem } from './ProductListItem'
|
|
7
|
+
export * from './ProductListItem'
|
|
8
|
+
|
|
9
|
+
export { default as ProductListItems } from './ProductListItems'
|
|
10
|
+
export * from './ProductListItems/filteredProductList'
|
|
11
|
+
export * from './ProductListItems/filterTypes'
|
|
12
|
+
export { default as ProductListItemsBase } from './ProductListItems/ProductListItemsBase'
|
|
13
|
+
export * from './ProductListItems/ProductListItemsBase'
|
|
14
|
+
export * from './ProductListItems/getFilterTypes'
|
|
15
|
+
export * from './ProductListItems/renderer'
|
|
16
|
+
export * from './ProductListItems/ProductListItems.gql'
|
|
17
|
+
export { default as ProductListParamsProvider } from './ProductListItems/ProductListParamsProvider'
|
|
18
|
+
export * from './ProductListLink/ProductListLink'
|
|
19
|
+
export { default as ProductListLink } from './ProductListLink/ProductListLink'
|
|
20
|
+
|
|
21
|
+
export * from './ProductListCount'
|
|
22
|
+
export { default as ProductListCount } from './ProductListCount'
|
|
23
|
+
export { default as ProductSidebarDelivery } from './ProductSidebarDelivery'
|
|
24
|
+
export * from './ProductListFilters'
|
|
25
|
+
export { default as ProductListFilters } from './ProductListFilters'
|
|
26
|
+
export * from './ProductListFiltersContainer'
|
|
27
|
+
export { default as ProductListFiltersContainer } from './ProductListFiltersContainer'
|
|
28
|
+
|
|
29
|
+
export * from './ProductRelated/RelatedProducts.gql'
|
|
30
|
+
|
|
31
|
+
export * from './ProductListPagination'
|
|
32
|
+
export { default as ProductListPagination } from './ProductListPagination'
|
|
33
|
+
export * from './ProductListSort'
|
|
34
|
+
export { default as ProductListSort } from './ProductListSort'
|
|
35
|
+
export * from './ProductPageDescription'
|
|
36
|
+
export { default as ProductPageDescription } from './ProductPageDescription'
|
|
37
|
+
export * from './ProductSpecs'
|
|
38
|
+
export { default as ProductSpecs } from './ProductSpecs'
|
|
39
|
+
export { default as productPageCategory } from './ProductPageCategory'
|
|
40
|
+
export { default as ProductPageGallery } from './ProductPageGallery'
|
|
41
|
+
export { default as ProductPageMeta } from './ProductPageMeta'
|
|
42
|
+
export { getProductStaticPaths } from './ProductStaticPaths/getProductStaticPaths'
|
|
43
|
+
export { default as ProductWeight } from './ProductWeight'
|
|
44
|
+
|
|
45
|
+
export * from './ProductUpsells/UpsellProducts.gql'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { ProductListParams } from '../components/ProductListItems/filterTypes'
|
|
3
|
+
|
|
4
|
+
export const productListParamsContext = React.createContext<{
|
|
5
|
+
params: ProductListParams
|
|
6
|
+
setParams: React.Dispatch<React.SetStateAction<ProductListParams>>
|
|
7
|
+
}>({ params: { filters: {}, sort: {}, url: '' }, setParams: () => {} })
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import * as Types from '@graphcommerce/graphql';
|
|
3
|
+
|
|
4
|
+
export type ProductLink_BundleProduct_Fragment = { __typename: 'BundleProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
5
|
+
|
|
6
|
+
export type ProductLink_ConfigurableProduct_Fragment = { __typename: 'ConfigurableProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
7
|
+
|
|
8
|
+
export type ProductLink_DownloadableProduct_Fragment = { __typename: 'DownloadableProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
9
|
+
|
|
10
|
+
export type ProductLink_GroupedProduct_Fragment = { __typename: 'GroupedProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
11
|
+
|
|
12
|
+
export type ProductLink_SimpleProduct_Fragment = { __typename: 'SimpleProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
13
|
+
|
|
14
|
+
export type ProductLink_VirtualProduct_Fragment = { __typename: 'VirtualProduct', uid: string, url_key?: Types.Maybe<string> };
|
|
15
|
+
|
|
16
|
+
export type ProductLinkFragment = ProductLink_BundleProduct_Fragment | ProductLink_ConfigurableProduct_Fragment | ProductLink_DownloadableProduct_Fragment | ProductLink_GroupedProduct_Fragment | ProductLink_SimpleProduct_Fragment | ProductLink_VirtualProduct_Fragment;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProductLinkFragment } from './ProductLink.gql'
|
|
2
|
+
|
|
3
|
+
type ProductLinkProps = Omit<ProductLinkFragment, 'uid'>
|
|
4
|
+
|
|
5
|
+
export function productLink(link: ProductLinkProps) {
|
|
6
|
+
const { __typename, url_key } = link
|
|
7
|
+
const productRoute = __typename
|
|
8
|
+
.split(/(?=[A-Z])/)
|
|
9
|
+
.map((s) => s.toLowerCase())
|
|
10
|
+
.reverse()
|
|
11
|
+
|
|
12
|
+
// For Simple and Virtual products we're not navigating to a type specific page
|
|
13
|
+
if (__typename === 'SimpleProduct') productRoute.splice(1, 1)
|
|
14
|
+
|
|
15
|
+
return `/${productRoute.join('/')}/${url_key}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useProductLink(props: ProductLinkProps) {
|
|
19
|
+
return productLink(props)
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isFilterTypeEqual,
|
|
3
|
+
isFilterTypeMatch,
|
|
4
|
+
isFilterTypeRange,
|
|
5
|
+
ProductListParams,
|
|
6
|
+
} from '../components/ProductListItems/filterTypes'
|
|
7
|
+
|
|
8
|
+
export function createProductListLink(props: ProductListParams): string {
|
|
9
|
+
const { url, sort, currentPage, filters } = props
|
|
10
|
+
|
|
11
|
+
// base url path generation
|
|
12
|
+
let href = ``
|
|
13
|
+
|
|
14
|
+
if (currentPage && currentPage > 1) href += `/page/${currentPage}`
|
|
15
|
+
|
|
16
|
+
// todo(paales): How should the URL look like with multiple sorts?
|
|
17
|
+
// Something like: /sort/position,price/dir/asc,asc
|
|
18
|
+
const [sortBy] = Object.keys(sort)
|
|
19
|
+
if (sort && sortBy) href += `/sort/${sortBy}`
|
|
20
|
+
if (sort && sortBy && sort[sortBy] && sort[sortBy] === 'DESC') href += `/dir/desc`
|
|
21
|
+
|
|
22
|
+
// Apply filters
|
|
23
|
+
if (filters)
|
|
24
|
+
Object.entries(filters).forEach(([param, value]) => {
|
|
25
|
+
if (value && isFilterTypeEqual(value) && value.in?.length)
|
|
26
|
+
href += `/${param}/${value.in?.join(',')}`
|
|
27
|
+
if (value && isFilterTypeMatch(value)) href += `/${param}/${value.match}`
|
|
28
|
+
if (value && isFilterTypeRange(value))
|
|
29
|
+
href += `/${param}/${value.from ?? '*'}-${value.to ?? '*'}`
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
href = `/${url}${href && `/q${href}`}`
|
|
33
|
+
return href
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function useProductListLink(props: ProductListParams): string {
|
|
37
|
+
return createProductListLink({ ...props, url: `${props.url}` })
|
|
38
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Router from 'next/router'
|
|
2
|
+
import { ProductListParams } from '../components/ProductListItems/filterTypes'
|
|
3
|
+
import { createProductListLink } from './useProductListLink'
|
|
4
|
+
import { useProductListParamsContext } from './useProductListParamsContext'
|
|
5
|
+
|
|
6
|
+
type UseProductLinkPushProps = {
|
|
7
|
+
shallow?: boolean
|
|
8
|
+
locale?: string | false
|
|
9
|
+
scroll?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useProductListLinkPush(props?: UseProductLinkPushProps) {
|
|
13
|
+
const { setParams } = useProductListParamsContext()
|
|
14
|
+
|
|
15
|
+
return (params: ProductListParams) => {
|
|
16
|
+
setParams(params)
|
|
17
|
+
|
|
18
|
+
const path = createProductListLink(params)
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
20
|
+
Router.push(path, path, props)
|
|
21
|
+
}
|
|
22
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './components'
|
|
2
|
+
|
|
3
|
+
export * from './Api/ProductListItem.gql'
|
|
4
|
+
export * from './Api/ProductPageItem.gql'
|
|
5
|
+
|
|
6
|
+
export * from './hooks/useProductLink'
|
|
7
|
+
export * from './hooks/useProductListLinkPush'
|
|
8
|
+
export * from './hooks/useProductListParamsContext'
|
|
9
|
+
export * from './hooks/ProductLink.gql'
|
package/next-env.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphcommerce/magento-product",
|
|
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-store": "^3.0.1",
|
|
28
|
+
"@graphcommerce/next-ui": "^3.0.1",
|
|
29
|
+
"@graphql-typed-document-node/core": "^3.1.0",
|
|
30
|
+
"@material-ui/core": "^4.12.3",
|
|
31
|
+
"@material-ui/lab": "^4.0.0-alpha.60",
|
|
32
|
+
"clsx": "^1.1.1",
|
|
33
|
+
"framer-motion": "^4.1.17",
|
|
34
|
+
"next": "^11.1.2",
|
|
35
|
+
"react": "^17.0.2",
|
|
36
|
+
"react-dom": "^17.0.2",
|
|
37
|
+
"schema-dts": "^1.0.0",
|
|
38
|
+
"type-fest": "^2.1.0"
|
|
39
|
+
}
|
|
40
|
+
}
|