-
Notifications
You must be signed in to change notification settings - Fork 22
WC 6.9 compatibility: Fix the incorrect form states of shipping settings #1750
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
Conversation
…form state will be incorrect when the selection of shipping rate is 'complex'
Tested locally, the UI behaves as expected, however, |
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.
Thanks, @eason9487, I have tested the code and it is fixing the issue with the shipping_time
state 👍
However I have some concerns about the root of this problem, when I was debugging this PR I saw that we have a similar issue with the values.offer_free_shipping
state, for example:
- when the rate is 0 and
values.offer_free_shipping
was previously set to "Y"
The state is not updated correctly, values.offer_free_shipping
should be updated to 'undefined'. See video:
Screen.Capture.on.2022-11-08.at.16-51-02.mp4
From what I can see it seems that there is an issue when setValue
and getInputProps( 'name' ).onChange
are combined and the state is somehow overridden.
google-listings-and-ads/js/src/components/shipping-rate-section/flat-shipping-rates-input-cards.js
Lines 25 to 29 in e464c76
if ( ! newShippingRates.some( isNonFreeShippingRate ) ) { | |
setValue( 'offer_free_shipping', undefined ); | |
} | |
onChange( newShippingRates ); |
A similar case in the ShippingRateSection
prior this PR:
What do you think?
Give, we have conceptually the components as follows:
The way I understood the desired data flow here looks like this: conceptually
However, the way I read the implementation it's more like this: implementation
Steps 3-6 seem to me like unnecessary ping pong. Can we make it simpler by putting state management into a single component? |
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.
Tested locally, reviewed the code, LGTM
Thanks for the reviews, @tomalec @jorgemd24
I was unable to reproduce this. Could you provide the replication steps? And I will find another time to circle back this #1750 (comment) 🙏
Nice finding! I will push a new commit to this PR for fixing that one together. |
One more additional fix:This processing has the same issue as well. It should be fixed by 2daefb2. Actual behavior:The value of Minimum Order Quantity...: is not cleared after selecting the "No" option for free shipping. Kapture.2022-11-09.at.20.55.31.mp4Screenshots (Expected behavior):Kapture.2022-11-09.at.20.54.47.mp4Detailed test instructions:
|
Hi @tomalec, as we discussed during the dev call. To make all relevant issues of WC |
🚧 After the last commit
Screencast.from.09.11.2022.21.21.38.webm |
I don't see why 2daefb2 is different than previous ones. Seems we reached the limit of workarounds for colliding versions of React components |
Here is how I logged it Repro steps:
|
@tomalec, thanks for the review!
I guess you were testing with WC 7.1? I have to say I was very lucky because I only tested it with WC 6.9 and 7.0. However, I was just aware of the I couldn't run the code to confirm it right now but the codes below look like lead to trigger
Probably it needs more hacks since WC 7.1 has been released. 😂 |
Yes, exactly.
Confirmed, that's the case. 🤦
Our code already consists of mostly workarounds for WC & WP quirks, maybe it's time to finally clean the field. |
…'s `Form`. Address: - #1750 (comment) - #1750 (comment) - #1750 (comment)
@tomalec, thanks for confirming the root cause
Since this issue belongs to the WC 7.1 compatibility issue, I was addressing it in a separate PR #1759. If #1759 is feasible and gets approved, I think this PR could be merged together in order by then. |
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.
Reviewed and tested together with https://github.com/woocommerce/google-listings-and-ads/pull/1759/files# LGTM
…management hierarchy. Ref: #1750 (comment)
Hi @tomalec, thanks for your patience in waiting for me to get back to the question raised almost two months ago. Quoted from myself:
TopicQuoted from #1750 (comment):
Thanks for bringing up this question. For me, this question has always been considered a code smell, and it has been buried in my mind for many months. Possible causesI think the primary cause for this result is the strategy for managing data and states, and the secondary is the limitations imposed by the WC
ContextBefore going further, I would like to mention some context of this case based on the current implementation.
Possible alternativesNext, there are several alternatives.
Thoughts on the first two possible alternatives above1️⃣ Use
|
Changes proposed in this Pull Request:
Closes #1747
shipping_time
of the form state will be incorrect when the selection of shipping rate is 'complex'.Detailed test instructions:
gla/mc/settings
API request to see if the saved data are correct.google-listings-and-ads/js/src/components/free-listings/setup-free-listings/index.js
Lines 126 to 127 in e464c76
Additional details:
Form
component and the need to satisfy business logic, this warning might not be avoided, even though the final form state will still be synchronized.Changelog entry