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

Fixes Checkout Shipping Methods Inadvertent Error Message #2371

Merged
merged 11 commits into from
May 4, 2020

Conversation

supernova-at
Copy link
Contributor

Description

This PR updates the way the Shipping Methods component on the Checkout page loads its data which solves two problems:

  1. It was showing an error state when it didn't need to
  2. It was inefficient

1. Incorrectly Showing Error State

The talon determines the proper displayState for the component to be in by looking at cart.shipping_addresses[0].selected_shipping_method.

But it was also inadvertently waiting for the results of fetching all shipping methods before setting a selectedShippingMethod.

Therefore the CompletedView was being rendered before it had a selectedShippingMethod, which caused it to show an error message; it didn't have any data to show.

This PR updates how the talon sets selectedShippingMethod - it no longer waits for all shipping methods. This keeps the talon internally consistent and fixes the inadvertent display of an error message by the CompletedView.

2. Inefficiency

Previously it was only querying for carrier_code and method_code of the cart.shipping_addresses.selected_shipping_method.
Therefore in order to display what it needed to in the CompletedView, it had to wait for the query that fetched all shipping methods to return, and then .find the selected_shipping_method in the list of all available methods.

Instead, this PR modifies the query for selected_shipping_method to include all the fields it needs to display. This means the CompletedView can render immediately without having to wait for all the shipping methods to load first.

Related Issue

Closes PWA-550.

Acceptance

Verification Stakeholders

Specification

Verification Steps

Bug Resolution

  1. Add an item to your cart
  2. Go to the /checkout page
  3. Select a shipping address
  4. Select a shipping method
  5. Refresh the page
  6. See that the Shipping Method card no longer shows an error before displaying the selected shipping method

Shipping Method Full Regression

Because this PR changes how the selectedShippingMethod is determined, the Shipping Method component should get a full regression, including:

  • Changing the shipping address (to an international country) after selecting a shipping method. Ensure you are presented with the shipping radios again to re-select a shipping method. Ensure the order summary stays up to date.
  • Update the selected shipping method via the update modal by clicking "Edit". Verify that the method updates correctly.

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@m2-community-project m2-community-project bot added this to Ready for Review in Pull Request Progress Apr 30, 2020
@supernova-at supernova-at added the version: Patch This changeset includes backwards compatible bug fixes. label Apr 30, 2020
@supernova-at supernova-at changed the title Supernova/550 load methods Fixes Checkout Shipping Methods Inadvertent Error Message Apr 30, 2020
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Apr 30, 2020

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).
📖

Associated JIRA tickets: PWA-550.

Generated by 🚫 dangerJS against 8bbae51

Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

A few minor changes but otherwise functional and works!

.selected_shipping_method;
} catch (err) {
// We don't have data from our specific query to fetch the selected shipping method.
// Intentionally swallow this error.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we hide logs in production we can and should log the error just in case. Swallowing errors can make future us sad.

if (process.env.NODE_ENV === 'development') {
  console.log(err);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7318d2b.

This was never really an error worth showing anyone: I was using that try / catch as a way not to have to check each object in chosenShippingMethodData.cart.shipping_addresses[0].selected_shipping_method for existence but it turns out the only one we really have to check for is chosenShippingMethodData itself, so I just went ahead and did that.

Comment on lines 106 to 109
console.log(
'selected method from list of methods',
selectedMethod
); // has all display data needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(
'selected method from list of methods',
selectedMethod
); // has all display data needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks!

Fixed in 7318d2b.

@@ -46,11 +46,15 @@ const ShippingRadios = props => {
return { label, value };
});

// Match the serialization of method objects from the useShippingMethod talon.
const { carrier_code, method_code } = selectedShippingMethod;
const selectedShippingMethodSerializedValue = `${carrier_code}|${method_code}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic should probably move to useShippingRadios and then be handled by some utility function that is shared between useShippingMethod and useShippingRadios talons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I had the same thought and was on the fence about it.

Fixed in 7318d2b.

@m2-community-project m2-community-project bot moved this from Ready for Review to Changes Requested in Pull Request Progress May 1, 2020
Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

A+

Copy link
Contributor

@revanth0212 revanth0212 left a comment

Choose a reason for hiding this comment

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

Awesome 👍

@m2-community-project m2-community-project bot moved this from Review in Progress to Reviewer Approved in Pull Request Progress May 1, 2020
@devops-pwa-codebuild
Copy link
Collaborator

Performance Test Results

The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate.

https://pr-2371.pwa-venia.com/venia-tops.html : LH Performance Expected 0.75 Actual 0.66

@dpatil-magento
Copy link
Contributor

dpatil-magento commented May 4, 2020

@supernova-at After selecting Shipping method if we change address to other country then > Previously selected shipping methods loads for a sec and then new available shipping method loads.

Image from Gyazo

@dpatil-magento
Copy link
Contributor

Above mentioned will be handled separately.

@dpatil-magento dpatil-magento merged commit fb1d118 into develop May 4, 2020
@dpatil-magento dpatil-magento deleted the supernova/550_load_methods branch May 4, 2020 19:17
@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:venia-ui version: Patch This changeset includes backwards compatible bug fixes.
Development

Successfully merging this pull request may close these issues.

None yet

6 participants