Skip to content
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

Merged
merged 23 commits into from
Oct 8, 2019
Merged

ProductFullDetail talon #1814

merged 23 commits into from
Oct 8, 2019

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Oct 1, 2019

NOTE:

This PR refactors useCarousel to have a local state for activeIndex 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.

/>
</p>
</section>
<section className={classes.imageCarousel}>
<Carousel
images={mediaGalleryEntries.value}
key={mediaGalleryEntries.key}
Copy link
Contributor Author

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.

Copy link
Contributor

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.
Copy link
Contributor Author

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. 🤷

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Oct 1, 2019

Fails
🚫 Missing "Description" section. Please add it back, with detail.
🚫 Missing "Verification Steps" section. Please add it back, with detail.
🚫

No linked issue found. Please link a relevant open issue by adding the text "closes #<issue_number>" or including the associated JIRA ID in your PR.

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

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.

Generated by 🚫 dangerJS against 494395d

@sirugh sirugh added version: Patch This changeset includes backwards compatible bug fixes. hold On hold until another condition is fulfilled. labels Oct 1, 2019
@sirugh sirugh removed the hold On hold until another condition is fulfilled. label Oct 1, 2019
jimbo
jimbo previously approved these changes Oct 1, 2019
// 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new code.

@dpatil-magento
Copy link
Contributor

QA Pass, good to merge once review is approved.

} else {
setActiveItemIndex(images.length - 1);
}
}, [activeItemIndex, images]);
Copy link
Contributor

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]);
Copy link
Contributor

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}
Copy link
Contributor

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}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/magento/pwa-studio/pull/1814/files#diff-dd082926e212e0be673b35eb01025b3aL101

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.

jimbo
jimbo previously approved these changes Oct 7, 2019
@dpatil-magento
Copy link
Contributor

dpatil-magento commented Oct 7, 2019

@sirugh If user select fashion color and size and then clicks/loads 2nd or 3rd image and then click on Add to Cart, automatically first image gets loaded. On develop branch it stays on selected images only.

…ry component was triggering re-renders/remaps of thus triggering updates down the ProductFullDetail tree
@dpatil-magento
Copy link
Contributor

@sirugh Simple Product page does not load anymore https://pr-1814.pwa-venia-staging.com/carmina-earrings.html :(

@dpatil-magento
Copy link
Contributor

QA Pass, Need reviewer approval to get merged.

@jimbo jimbo merged commit 1b79b5c into develop Oct 8, 2019
@dpatil-magento dpatil-magento deleted the rugh/talon-productfulldetail branch October 8, 2019 20:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg:peregrine pkg:venia-ui version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants