-
Notifications
You must be signed in to change notification settings - Fork 214
@W-18597952 - Scroll bar implementation for bonus products in the modal #2689
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
Merged
sf-vrushal-kulkarni
merged 4 commits into
feature/bonus-products
from
t/cc-sharks/W-18597952New
Jun 30, 2025
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5c84cdf
Scrolling and Refactored code to extract bonus product item sub-compo…
sf-vrushal-kulkarni afef9da
Merge branch 'feature/bonus-products' of https://github.com/Salesforc…
sf-vrushal-kulkarni e35cd34
Refactored code to extract bonus product item
sf-vrushal-kulkarni c0f9666
Fixed imports
sf-vrushal-kulkarni 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
116 changes: 116 additions & 0 deletions
116
packages/template-retail-react-app/app/components/bonus-product-item/bonus-product-item.jsx
This file contains hidden or 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,116 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import React, {useMemo} from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import { | ||
| VStack, | ||
| AspectRatio, | ||
| Skeleton, | ||
| Text, | ||
| Box, | ||
| Checkbox | ||
| } from '@salesforce/retail-react-app/app/components/shared/ui' | ||
| import DynamicImage from '@salesforce/retail-react-app/app/components/dynamic-image' | ||
| import {findImageGroupBy} from '@salesforce/retail-react-app/app/utils/image-groups-utils' | ||
| import {filterImageGroups} from '@salesforce/retail-react-app/app/utils/product-utils' | ||
|
|
||
| const BonusProductItem = ({product, productData, isSelected, onToggle, isLoading}) => { | ||
| const productName = product?.productName || product?.title | ||
|
|
||
| // Get the appropriate image group from the passed product data | ||
| // Use filterImageGroups to get variant-specific images when available | ||
| const imageGroup = useMemo(() => { | ||
| if (!productData?.imageGroups) return null | ||
|
|
||
| // If the product has variationValues, use filterImageGroups to get variant-specific images | ||
| if (productData.variationValues && Object.keys(productData.variationValues).length > 0) { | ||
| const filteredGroups = filterImageGroups(productData.imageGroups, { | ||
| viewType: 'small', | ||
| variationValues: productData.variationValues | ||
| }) | ||
| return filteredGroups?.[0] || null | ||
| } | ||
|
|
||
| // Fallback to the original logic for non-variant products | ||
| return findImageGroupBy(productData.imageGroups, { | ||
| viewType: 'small' | ||
| }) | ||
| }, [productData]) | ||
|
|
||
| const image = imageGroup?.images?.[0] | ||
| const showLoading = isLoading | ||
|
|
||
| if (showLoading) { | ||
| return ( | ||
| <VStack spacing={3} p={4} bg="gray.50"> | ||
| <AspectRatio ratio={1} width="150px" minWidth="150px"> | ||
| <Skeleton data-testid="skeleton" /> | ||
| </AspectRatio> | ||
| <VStack spacing={2} align="center"> | ||
| <Skeleton height="16px" width="100px" data-testid="skeleton" /> | ||
| <Skeleton height="20px" width="20px" data-testid="skeleton" /> | ||
| </VStack> | ||
| </VStack> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <VStack spacing={3} p={4} bg="white"> | ||
| <AspectRatio | ||
| ratio={1} | ||
| width="150px" | ||
| minWidth="150px" | ||
| cursor="pointer" | ||
| onClick={() => onToggle(product)} | ||
| > | ||
| {image && ( | ||
| <DynamicImage | ||
| src={`${image.disBaseLink || image.link}[?sw={width}&q=60]`} | ||
| widths={{ | ||
| base: '150px' | ||
| }} | ||
| imageProps={{ | ||
| alt: productName, | ||
| borderRadius: 'md', | ||
| objectFit: 'cover' | ||
| }} | ||
| /> | ||
| )} | ||
| </AspectRatio> | ||
| <VStack spacing={2} align="center" width="full"> | ||
| <Text | ||
| fontSize="sm" | ||
| fontWeight="semibold" | ||
| lineHeight="1.2" | ||
| textAlign="center" | ||
| noOfLines={{base: 2, md: 2}} | ||
| width={{base: '150px', md: 'full'}} | ||
| > | ||
| {productName} | ||
| </Text> | ||
| <Box width="full" display="flex" justifyContent="center"> | ||
| <Checkbox | ||
| isChecked={isSelected} | ||
| onChange={() => onToggle(product)} | ||
| cursor="pointer" | ||
| aria-label={`Select bonus product: ${productName}`} | ||
| /> | ||
| </Box> | ||
| </VStack> | ||
| </VStack> | ||
| ) | ||
| } | ||
|
|
||
| BonusProductItem.propTypes = { | ||
| product: PropTypes.object.isRequired, | ||
| productData: PropTypes.object, | ||
| isSelected: PropTypes.bool.isRequired, | ||
| onToggle: PropTypes.func.isRequired, | ||
| isLoading: PropTypes.bool | ||
| } | ||
|
|
||
| export default BonusProductItem | ||
100 changes: 100 additions & 0 deletions
100
...s/template-retail-react-app/app/components/bonus-product-item/bonus-product-item.test.jsx
This file contains hidden or 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,100 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import React from 'react' | ||
| import {screen} from '@testing-library/react' | ||
| import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils' | ||
| import BonusProductItem from 'components/bonus-product-item/bonus-product-item' | ||
|
|
||
| const baseProduct = { | ||
| id: '1', | ||
| productId: '1', | ||
| productName: 'Test Product', | ||
| title: 'Test Product' | ||
| } | ||
|
|
||
| const baseProductData = { | ||
| id: '1', | ||
| imageGroups: [ | ||
| { | ||
| viewType: 'small', | ||
| images: [{link: 'test-image.jpg'}] | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| describe('BonusProductItem', () => { | ||
| test('renders product name and image', () => { | ||
| renderWithProviders( | ||
| <BonusProductItem | ||
| product={baseProduct} | ||
| productData={baseProductData} | ||
| isSelected={false} | ||
| onToggle={jest.fn()} | ||
| isLoading={false} | ||
| /> | ||
| ) | ||
| expect(screen.getByText('Test Product')).toBeInTheDocument() | ||
| expect(screen.getByRole('checkbox')).toBeInTheDocument() | ||
| // Image alt text | ||
| expect(screen.getByAltText('Test Product')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders loading state', () => { | ||
| renderWithProviders( | ||
| <BonusProductItem | ||
| product={baseProduct} | ||
| productData={baseProductData} | ||
| isSelected={false} | ||
| onToggle={jest.fn()} | ||
| isLoading={true} | ||
| /> | ||
| ) | ||
| expect(screen.getAllByTestId('skeleton').length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| test('checkbox is checked when isSelected is true', () => { | ||
| renderWithProviders( | ||
| <BonusProductItem | ||
| product={baseProduct} | ||
| productData={baseProductData} | ||
| isSelected={true} | ||
| onToggle={jest.fn()} | ||
| isLoading={false} | ||
| /> | ||
| ) | ||
| expect(screen.getByRole('checkbox')).toBeChecked() | ||
| }) | ||
|
|
||
| test('checkbox is not checked when isSelected is false', () => { | ||
| renderWithProviders( | ||
| <BonusProductItem | ||
| product={baseProduct} | ||
| productData={baseProductData} | ||
| isSelected={false} | ||
| onToggle={jest.fn()} | ||
| isLoading={false} | ||
| /> | ||
| ) | ||
| expect(screen.getByRole('checkbox')).not.toBeChecked() | ||
| }) | ||
|
|
||
| test('checkbox has correct aria-label', () => { | ||
| renderWithProviders( | ||
| <BonusProductItem | ||
| product={baseProduct} | ||
| productData={baseProductData} | ||
| isSelected={false} | ||
| onToggle={jest.fn()} | ||
| isLoading={false} | ||
| /> | ||
| ) | ||
| expect(screen.getByRole('checkbox')).toHaveAttribute( | ||
| 'aria-label', | ||
| 'Select bonus product: Test Product' | ||
| ) | ||
| }) | ||
| }) |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.