-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PWA-1124] Browsing and Viewing Virtual product #3052
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d81beb3
Display info message when product is not available for purchase
tjwiebell 7039a43
Stub out extension that replaces the query to fires on category pages…
tjwiebell aaa04d0
Break queries into fragments so extension is less fragile to breakage
tjwiebell 6a72c82
Fix version constraints and convert to ESM to resolve build error.
tjwiebell 12c2940
Finish up target and interception declaration to support rendering th…
tjwiebell a0c2431
Disable extension by default
tjwiebell 477bd43
UX adjustments based on feedback
tjwiebell 69022f0
Merge branch 'develop' into tommy/virtual-browse-view
tjwiebell 7880aff
Cover changes with tests
tjwiebell 824f3ab
Merge branch 'develop' into tommy/virtual-browse-view
dpatil-magento 8440cb6
Rename extension to denote reference implementation
tjwiebell 1eac198
Add test for new target
tjwiebell fece0ee
Merge branch 'develop' into tommy/virtual-browse-view
eug123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = targets => { | ||
targets.of('@magento/pwa-buildpack').specialFeatures.tap(features => { | ||
features[targets.name] = { | ||
cssModules: true, | ||
esModules: true, | ||
graphqlQueries: true | ||
}; | ||
}); | ||
|
||
const { talons } = targets.of('@magento/peregrine'); | ||
|
||
talons.tap(hooks => { | ||
const useCategory = hooks.RootComponents.Category.useCategory; | ||
useCategory.wrapWith( | ||
'@magento/venia-virtual-products/src/wrapUseCategory' | ||
); | ||
}); | ||
|
||
const { categoryListProductAttributes } = targets.of('@magento/venia-ui'); | ||
categoryListProductAttributes.tap(target => { | ||
target.insertAfterJSX({ | ||
matcher: 'Link className={classes.name}', | ||
importStatement: `import SubTypeAttribute from '@magento/venia-virtual-products/src/components/SubTypeAttribute'` | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@magento/venia-virtual-products", | ||
"version": "0.0.1", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Adds support for additional fields when rendering virtual products", | ||
"main": "./intercept.js", | ||
"scripts": { | ||
"clean": " " | ||
}, | ||
"repository": "github:magento/pwa-studio", | ||
"license": "(OSL-3.0 OR AFL-3.0)", | ||
"peerDependencies": { | ||
"@apollo/client": "~3.1.2", | ||
"@magento/peregrine": "~9.0.0", | ||
"@magento/pwa-buildpack": "~8.0.1", | ||
"@magento/venia-ui": "~6.0.1" | ||
}, | ||
"pwa-studio": { | ||
"targets": { | ||
"intercept": "./intercept" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/extensions/venia-virtual-products/src/__tests__/wrapUseCategory.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import wrapUseCategory from '../wrapUseCategory'; | ||
|
||
jest.mock('../category.gql', () => ({ | ||
GET_CATEGORY: jest.fn().mockName('GET_CATEGORY') | ||
})); | ||
|
||
test('injects custom query into talon props', () => { | ||
const mockTalon = jest.fn(); | ||
wrapUseCategory(mockTalon)({ talonProp: 'should be untouched' }); | ||
|
||
expect(mockTalon.mock.calls[0][0]).toMatchInlineSnapshot(` | ||
Object { | ||
"operations": Object { | ||
"getCategoryQuery": [MockFunction GET_CATEGORY], | ||
}, | ||
"talonProp": "should be untouched", | ||
} | ||
`); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/extensions/venia-virtual-products/src/category.gql.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
import { | ||
CategoryFragment, | ||
ProductsFragment | ||
} from '@magento/peregrine/lib/talons/RootComponents/Category/categoryFragments.gql'; | ||
|
||
export const GET_CATEGORY = gql` | ||
query GetCategoriesWithSubType( | ||
$id: Int! | ||
$pageSize: Int! | ||
$currentPage: Int! | ||
$filters: ProductAttributeFilterInput! | ||
$sort: ProductAttributeSortInput | ||
) { | ||
category(id: $id) { | ||
id | ||
...CategoryFragment | ||
} | ||
products( | ||
pageSize: $pageSize | ||
currentPage: $currentPage | ||
filter: $filters | ||
sort: $sort | ||
) { | ||
items { | ||
id | ||
sub_type | ||
} | ||
...ProductsFragment | ||
} | ||
} | ||
${CategoryFragment} | ||
${ProductsFragment} | ||
`; |
58 changes: 58 additions & 0 deletions
58
...venia-virtual-products/src/components/SubTypeAttribute/__tests__/subTypeAttribute.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import { useQuery } from '@apollo/client'; | ||
import createTestInstance from '@magento/peregrine/lib/util/createTestInstance'; | ||
|
||
import SubTypeAttribute from '../subTypeAttribute'; | ||
|
||
jest.mock('@apollo/client', () => ({ | ||
gql: jest.fn(), | ||
useQuery: jest.fn().mockReturnValue({}) | ||
})); | ||
|
||
test('renders null without sub_type', () => { | ||
const tree = createTestInstance(<SubTypeAttribute item={{ id: 1 }} />); | ||
|
||
expect(tree.toJSON()).toMatchInlineSnapshot(`null`); | ||
}); | ||
|
||
test('renders skeleton while fetching attribute metadata', () => { | ||
const tree = createTestInstance( | ||
<SubTypeAttribute item={{ id: 1, sub_type: 123 }} /> | ||
); | ||
|
||
expect(tree.toJSON()).toMatchInlineSnapshot(` | ||
<span | ||
className="root" | ||
/> | ||
`); | ||
}); | ||
|
||
test('renders attribute label with metadata', () => { | ||
useQuery.mockReturnValue({ | ||
data: { | ||
customAttributeMetadata: { | ||
items: [ | ||
{ | ||
attribute_options: [ | ||
{ label: 'Consultation', value: 456 }, | ||
{ label: 'Service', value: 123 }, | ||
{ label: 'Donation', value: 789 } | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
|
||
const tree = createTestInstance( | ||
<SubTypeAttribute item={{ id: 1, sub_type: 123 }} /> | ||
); | ||
|
||
expect(tree.toJSON()).toMatchInlineSnapshot(` | ||
<span | ||
className="root" | ||
> | ||
Service | ||
</span> | ||
`); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/extensions/venia-virtual-products/src/components/SubTypeAttribute/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './subTypeAttribute'; |
9 changes: 9 additions & 0 deletions
9
...es/extensions/venia-virtual-products/src/components/SubTypeAttribute/subTypeAttribute.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.root { | ||
color: rgb(var(--venia-global-color-text-hint)); | ||
font-size: var(--venia-typography-detail-L-fontSize); | ||
} | ||
|
||
.root:empty { | ||
background-color: rgb(var(--venia-global-color-gray)); | ||
min-height: 1rem; | ||
} |
22 changes: 22 additions & 0 deletions
22
...extensions/venia-virtual-products/src/components/SubTypeAttribute/subTypeAttribute.gql.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
const GET_ATTRIBUTE_METADATA = gql` | ||
query GetSubtypeMetadata { | ||
customAttributeMetadata( | ||
attributes: [ | ||
{ attribute_code: "sub_type", entity_type: "catalog_product" } | ||
] | ||
) { | ||
items { | ||
attribute_options { | ||
label | ||
value | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default { | ||
getAttributeMetadataQuery: GET_ATTRIBUTE_METADATA | ||
}; |
33 changes: 33 additions & 0 deletions
33
...ges/extensions/venia-virtual-products/src/components/SubTypeAttribute/subTypeAttribute.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useMemo } from 'react'; | ||
|
||
import classes from './subTypeAttribute.css'; | ||
import operations from './subTypeAttribute.gql'; | ||
import { useQuery } from '@apollo/client'; | ||
|
||
const SubTypeAttribute = props => { | ||
const { item } = props; | ||
const { sub_type } = item; | ||
|
||
const { getAttributeMetadataQuery } = operations; | ||
const { data } = useQuery(getAttributeMetadataQuery, { | ||
skip: !sub_type | ||
}); | ||
|
||
const attributeLabel = useMemo(() => { | ||
if (!sub_type || !data) return null; | ||
|
||
const attributeOptions = | ||
data.customAttributeMetadata.items[0].attribute_options; | ||
const attributeOption = attributeOptions.find( | ||
attribute => attribute.value == sub_type | ||
); | ||
|
||
return attributeOption.label; | ||
}, [data, sub_type]); | ||
|
||
if (!sub_type) return null; | ||
|
||
return <span className={classes.root}>{attributeLabel}</span>; | ||
}; | ||
|
||
export default SubTypeAttribute; |
14 changes: 14 additions & 0 deletions
14
packages/extensions/venia-virtual-products/src/wrapUseCategory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GET_CATEGORY } from './category.gql'; | ||
|
||
const wrapUseCategory = original => props => { | ||
const newProps = { | ||
...props, | ||
operations: { | ||
getCategoryQuery: GET_CATEGORY | ||
supernova-at marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
return original(newProps); | ||
}; | ||
|
||
export default wrapUseCategory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ const SUPPORTED_PRODUCT_TYPES = ['SimpleProduct', 'ConfigurableProduct']; | |
* handleSelectionChange: func, | ||
* handleSetQuantity: func, | ||
* isAddToCartDisabled: boolean, | ||
* isSupportedProductType: boolean, | ||
* mediaGalleryEntries: array, | ||
* productDetails: object, | ||
* quantity: number | ||
|
@@ -315,10 +316,8 @@ export const useProductFullDetail = props => { | |
handleAddToCart, | ||
handleSelectionChange, | ||
isAddToCartDisabled: | ||
!isSupportedProductType || | ||
isMissingOptions || | ||
isAddConfigurableLoading || | ||
isAddSimpleLoading, | ||
isMissingOptions || isAddConfigurableLoading || isAddSimpleLoading, | ||
isSupportedProductType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can list of supported product types be made a target in venia? Extensions can then add to this list.
supernova-at marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mediaGalleryEntries, | ||
productDetails | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this implementation is not going to be the final core implementation it would make sense to follow the sample naming convention and not use up the logical name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call out, I've gone ahead and made this change since this is really for reference given our specific sample data.