Skip to content

Conversation

@octaedro
Copy link
Contributor

@octaedro octaedro commented May 24, 2023

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 changes button will remain enabled, and no other change will be saved except for the added method.

Screen Capture on 2023-05-26 at 12-27-00

Closes #38114.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Go WooCommerce > Settings > Shipping (URL: wp-admin/admin.php?page=wc-settings&tab=shipping).
  2. Create a shipping zone and click edit.
  3. Update the zone name and add a new shipping method
  4. Notice how the loading icon shows up on the shipping method table, and the form gets saved without clicking Save changes.
  5. Add another change to the form (like changing Zone name).
  6. Add another shipping method.
  7. Verify that the Save changes button 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 changes will be necessary to save it.

When editing a specific shipping method, all the changes in the form will be saved after pressing the Save changes button inside the modal.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 24, 2023
@octaedro octaedro marked this pull request as ready for review May 24, 2023 17:42
@octaedro octaedro self-assigned this May 24, 2023
@octaedro octaedro requested a review from a team May 24, 2023 17:47
@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2023

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:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2023

Test Results Summary

Commit SHA: 0d86f40

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 12s
E2E Tests1950010020515m 15s

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.

@github-actions github-actions bot added the focus: e2e tests Issues related to e2e tests label May 25, 2023
Copy link
Contributor

@louwie17 louwie17 left a 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_method with 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
Copy link
Contributor

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.

@pmcpinto
Copy link

Hey @louwie17 thanks for the heads up.

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?

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?

@louwie17
Copy link
Contributor

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?

@alopezari
Copy link
Contributor

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!

@octaedro octaedro requested a review from louwie17 June 1, 2023 01:14
Copy link
Contributor

@louwie17 louwie17 left a 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();
Copy link
Contributor

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 );
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

@octaedro octaedro requested a review from louwie17 June 1, 2023 20:53
@pmcpinto
Copy link

pmcpinto commented Jun 2, 2023

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?

This approach can work well. @jarekmorawski what do you think?

Copy link
Contributor

@louwie17 louwie17 left a 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!!!

@octaedro octaedro force-pushed the fix/38114_editing_shipping_methods_auto_saves branch from 4758bcf to 0d86f40 Compare June 5, 2023 14:01
@octaedro octaedro merged commit f2aae0a into trunk Jun 5, 2023
@octaedro octaedro deleted the fix/38114_editing_shipping_methods_auto_saves branch June 5, 2023 16:07
@github-actions github-actions bot added this to the 7.9.0 milestone Jun 5, 2023
moon0326 pushed a commit that referenced this pull request Jun 6, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editing Shipping Methods auto saves the entire form which is confusing behaviour

5 participants