-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ProductFullDetail talon #1814
ProductFullDetail talon #1814
Conversation
packages/peregrine/lib/talons/ProductFullDetail/useProductFullDetail.js
Outdated
Show resolved
Hide resolved
/> | ||
</p> | ||
</section> | ||
<section className={classes.imageCarousel}> | ||
<Carousel | ||
images={mediaGalleryEntries.value} | ||
key={mediaGalleryEntries.key} |
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.
key
didn't seem used so I deleted the code generating it and just returned the computed entries.
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.
Just from looking quickly, I think it's safe to say there was a valid reason to calculate that key before. Did something change so that it's no longer necessary?
@@ -24,6 +24,8 @@ class Options extends Component { | |||
const { handleSelectionChange, props } = this; | |||
const { product, selectedValues = [] } = props; | |||
|
|||
// TODO: Do this check in parent and only pass `configurable_options` | |||
// instead of the entire `product` as a prop. |
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.
Fun note, we already do this in the mini cart product options page but we don't do it in the PFD. 🤷
If your PR is missing information, check against the original template here. At a minimum you must have the section headers from the template and provide some information in each section. |
// Selections are initialized to "code => undefined". Once we select a value, like color, the selections change. This filters out unselected options. | ||
const optionsSelected = | ||
Array.from(optionSelections.values()).filter(value => !!value).length > | ||
0; |
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.
This is new code.
QA Pass, good to merge once review is approved. |
} else { | ||
setActiveItemIndex(images.length - 1); | ||
} | ||
}, [activeItemIndex, images]); |
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.
When using useCallback
, look out for scenarios like this one. As written, handlePrevious
will be recreated whenever activeItemIndex
changes, and since handlePrevious
itself changes activeItemIndex
, this memoization is pointless.
Before, we were keeping index
in a reducer so that handlePrevious
could be memoized. If you're going to remove the reducer in favor of useState
, you'll want to use the functional update form.
const handlePrevious = useCallback(() => {
setActiveItemIndex(prev => prev > 0 ? prev - 1 : images.length - 1)
}, [images])
); | ||
const handleNext = useCallback(() => { | ||
setActiveItemIndex((activeItemIndex + 1) % images.length); | ||
}, [activeItemIndex, images]); |
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.
This memoization also fails, for the same reason.
const handleNext = useCallback(() => {
setActiveItemIndex(prev => (prev + 1) % images.length)
}, [images])
/> | ||
</p> | ||
</section> | ||
<section className={classes.imageCarousel}> | ||
<Carousel | ||
images={mediaGalleryEntries.value} | ||
key={mediaGalleryEntries.key} |
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.
Just from looking quickly, I think it's safe to say there was a valid reason to calculate that key before. Did something change so that it's no longer necessary?
<p className={classes.productPrice}> | ||
<Price | ||
currencyCode={productPrice.currency} | ||
value={productPrice.value} | ||
currencyCode={productDetails.price.currency} |
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.
Is there any way this could result in an error being thrown?
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.
productPrice
was previously just amount
which is an object containing currency
and value
props. The normalization done in the talon is equivalent with only a rename of productPrice
to productDetails.price
.
Technically the old way (and the new method) can both throw if any of the values are undefined in the chain. Since we don't yet have option chaining I can leave these to some default.
@sirugh If user select fashion color and size and then clicks/loads 2nd or 3rd image and then click on |
…ry component was triggering re-renders/remaps of thus triggering updates down the ProductFullDetail tree
@sirugh Simple Product page does not load anymore https://pr-1814.pwa-venia-staging.com/carmina-earrings.html :( |
QA Pass, Need reviewer approval to get merged. |
NOTE:
This PR refactors
useCarousel
to have a local state foractiveIndex
instead of using a reducer. This is because of a bug found in using the hook with a variable length input array of images.This PR also changes the PDP to show the correct amount of images when the PDP first renders and to show the correct image after a color is selected.