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

Selecting a Product Variant does not replace the route anymore. #548

Merged
merged 9 commits into from
Feb 26, 2019

Conversation

devbucket
Copy link
Contributor

Description

Selecting a Variant on the Product Detail Page used to replace the route to trigger loading of the product data. This caused issues with the scrolling of the page. Now the page is not replaced but the current route is updated and the fetching of new data is based in the route's custom state, which holds the selected variant's ID.

Type of change

Please add an "x" into the option that is relevant:

  • [ ] Bug Fix 🐛 (non-breaking change which fixes an issue)
  • [ ] New Feature 🚀 (non-breaking change which adds functionality)
  • [ ] Breaking Change 💥 (fix or feature that would cause existing functionality to not work as expected)
  • [ x ] Polish 💅 (Just some cleanups)
  • [ ] Docs 📝 (Changes in the documentations)
  • [ ] Internal 🏠 Only relates to internal processes.

@devbucket devbucket added the enhancement New feature or request label Feb 21, 2019
@devbucket devbucket self-assigned this Feb 21, 2019
@coveralls
Copy link

coveralls commented Feb 22, 2019

Pull Request Test Coverage Report for Build 2075

  • 17 of 27 (62.96%) changed or added relevant lines in 6 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.008%) to 47.325%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/commerce/product/streams/index.js 13 14 92.86%
libraries/commerce/product/subscriptions/index.js 0 2 0.0%
libraries/tracking/subscriptions/product.js 0 3 0.0%
libraries/common/components/ProductCharacteristics/connector.js 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
libraries/common/reducers/router/index.js 1 61.9%
libraries/commerce/product/streams/index.js 2 70.45%
Totals Coverage Status
Change from base Build 2067: 0.008%
Covered Lines: 5062
Relevant Lines: 10026

💛 - Coveralls

export const productWillEnter$ = routeWillEnter$
.filter(({ action }) => (
action.route.pattern === ITEM_PATTERN &&
action.historyAction !== HISTORY_REPLACE_ACTION
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that the route isn't replaced anymore, this part of the condition can be removed. The rest needs to stay as it is and can't be substituted by productWillEnter$ from common-commerce, since this one also emits when the route is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -15,7 +15,7 @@ import {
RECEIVE_PRODUCT_RELATIONS,
} from '../constants';

export const productWillEnter$ = routeWillEnter$
export const productWillEnter$ = routeWillEnter$.merge(routeDidUpdate$)
.filter(({ action }) => action.route.pattern === ITEM_PATTERN);

export const variantWillUpdate$ = routeWillEnter$.filter(({ action }) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The variantWillUpdate$ stream also needs to be adjusted, since the HISTORY_REPLACE_ACTION action isn't dispatched anymore on variant changes. At the moment it doesn't emit anymore, but it's relevant for the variantDidChange$ stream which is used to reset the AddToCartBar and to track variant changes (pwa-tracking/subscriptions/product).

I've quickly tried to update the stream by branching it from routeDidUpdate$, but then variantDidChange$ emitted with the data of the parent product, instead of the variant data.

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 gets triggered now with the correct data.

Copy link
Collaborator

@fkloes fkloes left a comment

Choose a reason for hiding this comment

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

The basic theme logic seems to work now, but the variantSelected tracking event doesn't contain the correct data yet. Both properties within the event payload (baseProduct and variant) contain the parent product.

The reason for that is located within variantDidChange$ of pwa-tracking/subscriptions/product. There we grab the productId from the params of the Route state, and use it to select the tracking data.
I currently see two possible ways to fix this. You could either extend the logic to also consider the productId from the state, just take it from action.productData.id. action.productId is also possible when the receivedVisibleProduct$ stream emits for RECEIVE_PRODUCT, but RECEIVE_PRODUCT_CACHED doesn't deliver this property at the moment.

Additionally the tests seem to fail at the moment.

@fkloes fkloes merged commit 2bccba6 into v6.3.0 Feb 26, 2019
@fkloes fkloes deleted the PWA-1583-Variant-Selection-should-not-unmount-page branch February 26, 2019 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants