This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Remove useSelectShippingRate
hook and adjust how local state works for PackageRates
#5802
Merged
Conversation
This file contains 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
mikejolley
added
skip-changelog
PRs that you don't want to appear in the changelog.
status: needs review
block: checkout
Issues related to the checkout block.
labels
Feb 9, 2022
rubikuserbot
requested review from
a team and
opr
and removed request for
a team
February 9, 2022 16:11
Size Change: +375 B (0%) Total Size: 813 kB
ℹ️ View Unchanged
|
opr
approved these changes
Feb 9, 2022
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 works well, thanks for taking care of this Mike! I left a few TS comments and one about naming, but those are non-blocking.
assets/js/base/context/hooks/shipping/use-select-shipping-rates.ts
Outdated
Show resolved
Hide resolved
There was an idea to use loading states from @tarhi-saad which could also work, but I think we should avoid this for now until #5365 has had a proper review. I don't think we should introduce more loading states until existing have been reviewed. |
sunyatasattva
added
the
type: enhancement
The issue is a request for an enhancement.
label
Feb 14, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
block: checkout
Issues related to the checkout block.
skip-changelog
PRs that you don't want to appear in the changelog.
type: enhancement
The issue is a request for an enhancement.
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.
While looking at #5734 I've established that we do need local state, but we can make some improvements so it's more clear as to why.
If the radio buttons are controlled inputs, without a local state you click on shipping options and get no UI feedback until the request completes and the shipping methods update. This is poor UX.
if the radio buttons are uncontrolled inputs, you get instant feedback when selecting a shipping option, but if the shipping method changes elsewhere (on the server, or on another tab) it becomes out of sync with the data stores.
Therefore, the best solution is to store the checked option in local state, and update it both on click, and when the data stores update post-update.
You can see in this PR I was able to remove
useSelectShippingRate
, remove it's local state, and move the logic touseSelectShippingRates
.I've moved the Radio button local state into
PackageRates
. There it just stores the value of the selected option. This also reacts to updates from the server usinguseEffect
.RadioControl
has also been changed to TypeScript.Closes #5734
Testing
How to test the changes in this Pull Request: