-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix editing Shipping methods auto-saving #38431
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
Fix editing Shipping methods auto-saving #38431
Conversation
|
Hi @louwie17, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: 0d86f40
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
louwie17
left a comment
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.
@octaedro unfortunately this looks like it will require a whole lot more work, as the request to woocommerce_shipping_zone_add_method already saves the shipping method.
As I am looking at this, it looks like these steps should be implemented, if we really wanted to do it well (otherwise we should just add some clarifying notes in different places):
- New Ajax call to retrieve all the shipping method data ( title, description, etc )
- On add shipping method replace call to
woocommerce_shipping_zone_add_methodwith retrieving all shipping method data (with new ajax call) and display within table (keep track of this data ) - Keep track of changes within shipping method changes and change Save changes button to Done or something to that affect.
- When user hits Save changes we submit all the changed data ( new methods, and updated method changes, etc...)
@pmcpinto this was to address a bug found during one of the user flow calls and turns out to be quite a big task and re-factor that will probably take a good week (or longer ) of developer time.
Did we potentially want to re-consider this?
I am also trying to think of alternate (less dev heavy ) solutions, like maybe just adding a note that adding a new shipping method auto saves the form?
| ); | ||
| } | ||
| } | ||
| // Trigger save if there are changes, or just re-render |
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.
Hmm although these changes do prevent the Save changes from being disabled again, it is actually the request above that saves the data. So even if I don't hit Save changes and refresh the page the new shipping method is still in the list.
|
Hey @louwie17 thanks for the heads up.
Given the time it will take, it makes total sense to reconsider this. Displaying a snackbar informing the user that all the changes were saved could be a good workaround. It's not perfect but it does the job. @jarekmorawski what do you think? |
A quick follow up as I also talked with @octaedro about this more. This issue does address the issue where a user may edit the zone name and then add a shipping method, that only the shipping methods are saved and the user still has to click Save changes for the zone name update. If we want, we could keep that structure, where all the changes within the shipping methods (adding/removing/editing) is saved automatically, but outside of that requires the call to Save changes? |
|
Hi @octaedro! I reviewed the changes in the E2E tests and they look good. I ran them in multiple combinations (the whole spec in headless, headed and UI mode, as well as running all these tests individually) and they always passed. I also ran them several times consecutively in order to spot potential flaky issues, but they seem to be pretty consistent. I don't know if it will need any further changes based on the recent comments, in that case, let us know and we'll happily review the testing details again. Thank you! |
louwie17
left a comment
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.
Overall this is testing quite well, nice work on this @octaedro!
I did leave two suggestions, on the window confirmation dialog before removing and showing a window alert instead of a console alert.
| model.set( 'methods', methods ); | ||
| model.logChanges( changes ); | ||
| view.render(); | ||
| shippingMethodView.block(); |
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.
We also discussed showing a confirmation dialog first, to see if the user really wanted to delete the shipping method, could we still add that?
| shippingMethodView.unblock(); | ||
| }, | ||
| error: function( jqXHR, textStatus, errorThrown ) { | ||
| console.error( 'There was an error removing the shipping method.', errorThrown ); |
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.
Instead of a console.error I think we should trigger a window.alert similar to other places within this JS file.
See window.alert( data.strings.save_failed ); cases. We did have to add a new localized string, it looks like there is already one for add_method_failed, so we could also create one for remove_method_failed?
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.
Good call @louwie17! I just added the changes you mentioned. Could you take another look at this PR?
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.
Please scratch my comment. I'll add a couple of e2e tests before pinging you for a re review.
This approach can work well. @jarekmorawski what do you think? |
louwie17
left a comment
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.
LGTM 🚀 Thanks for your hard work on this @octaedro and for adding the E2E tests as well, nice work!!!
4758bcf to
0d86f40
Compare
* Fix Shipping Methods auto save * Add changelog * Fix e2e tests * Fix e2e tests * Add `shipping_zone_remove_method` * Fix `onDeleteRow` * Fix lint * Fix delete method * Add confirmation prompt and error message * Fix lint * Fix js * Add e2e test * Fix tests
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR fixes the issue with Shipping Methods auto-saving the entire form. Now, when a shipping method is added and there is another change in the form, the
Save changesbutton will remain enabled, and no other change will be saved except for the added method.Closes #38114.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
WooCommerce>Settings>Shipping(URL:wp-admin/admin.php?page=wc-settings&tab=shipping).Save changes.Zone name).Save changesbutton is still enabled and only the added shipping method is saved.We currently don't have a method to delete shipping zones individually, which is why I opted for this workaround. The form will be saved automatically if we add a new shipping method. However, if another change is made, then pressing
Save changeswill be necessary to save it.When editing a specific shipping method, all the changes in the form will be saved after pressing the
Save changesbutton inside the modal.