-
Notifications
You must be signed in to change notification settings - Fork 134
[Shipping labels] Improve address validation errors #14468
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
base: trunk
Are you sure you want to change the base?
Conversation
This commit updates the `AddressNormalizationModel` to include a new `errors` field. The `WooShippingNetworkingMapper` is also updated to map the errors from the DTO to the model.
The `NormalizeAddressException` class is updated to accept a map of errors instead of a single error string. This allows for more granular error reporting, specifically differentiating between general errors and address-specific errors.
The error handling in `NormalizeAddress.kt` is updated to provide more specific error messages. - If the response model is null, an "Empty response" message is used. - `NormalizeAddressException` is now used when there are specific address errors. - A general `Exception` is used for other errors, incorporating the error message from the response if available.
The `AddressStatus` enum has been converted to a sealed class. This change allows for more detailed state representation, particularly for the `VerifyFailed` status, which can now optionally include a `NormalizeAddressException`.
Generated by 🚫 Danger |
edd4641
to
70a6a58
Compare
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.
I created this class to address the LargeClass
Detekt error in the WooShippingEditAddressViewModel
class.
@@ -12,22 +12,30 @@ class NormalizeAddress @Inject constructor( | |||
private val site: SelectedSite, | |||
) { | |||
suspend operator fun invoke(address: Address): Result<AddressNormalizationModel> { | |||
return site.getOrNull()?.let { |
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.
I changed site.getOrNull()
to site.get()
to align with the approach we use for our domain classes in the shipping label screens.
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
70a6a58
to
4b1fc71
Compare
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #14468 +/- ##
============================================
- Coverage 37.92% 37.92% -0.01%
- Complexity 9262 9266 +4
============================================
Files 2009 2010 +1
Lines 112908 112929 +21
Branches 14916 14932 +16
============================================
+ Hits 42823 42826 +3
- Misses 66186 66192 +6
- Partials 3899 3911 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Nice work @irfano, works well.
I just left a question, but I'm pre-approving.
val generalError: String? | ||
get() = errors[ERROR_GENERAL] | ||
val addressError: String? | ||
get() = errors[ERROR_ADDRESS] |
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.
Just a remark here, the iOS app exposes an error for the name
field (here), and the plugin takes this a step further by accepting an error for all fields (Check lines 43 to 49 of the file address-step/fields.jsx
).
I'm not sure how to trigger any of the other errors, so I'm not sure if we need to support this or not, WDYT?
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.
I didn't add errors for the other fields because I couldn't reproduce them. I reviewed address-step/fields.jsx
but still couldn't determine the mapping. In this PR, I mapped address
key to the "Address" field, but I couldn't find the keys for the other fields.
@itsmeichigo, since you used name
for the "Name" field errors, have you found a way to reproduce the name
error?
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.
I reviewed address-step/fields.jsx but still couldn't determine the mapping
You can find all the keys by looking for getProps
on the file: name
, company
, email
, phone
, country
, address
, city
, state
and postcode
. The mapping with of the error with the key
is done on line 43.
I didn't add errors for the other fields because I couldn't reproduce them
IMO we can add them without being able to reproduce them, in case the errors happen for some specific countries, but that's now a blocker for merging this PR.
Closes WOOMOB-904
Description
This PR adds support for displaying address field errors on the Edit Address screen, using the validation errors returned from the endpoint. For example, when the house number is missing, the API response looks like this:
Steps to reproduce
Testing information
Repeat the steps for the origin address as well, but ensure that unverified addresses can't be saved as origin addresses.
The tests that have been performed
Steps above
Images/gif
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.