Skip to content
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

Update origin address errors #13612

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from

Conversation

atorresveiga
Copy link
Contributor

@atorresveiga atorresveiga commented Feb 21, 2025

Part of: #12439

Description

This PR handles errors in the normalization/update address error flow. The errors will be displayed in a SnackBar with a retry action. Updating the address while an error is displayed will dismiss the SnackBar. This PR handles the normalization and address update errors. Navigation will be handled in the next PR, finishing with the update.

Testing information

TC1

  1. Open the orders tab
  2. Tap on an order eligible for shipping label creation
  3. Expand the shipment details section
  4. Expand the origin address selection (3 dots)
  5. Tap on the pencil
  6. Update the address with an invalid value
  7. Tap on Validate & Save
  8. Check that when the response fails, a SnackBar message is displayed informing about the error with a retry action
  9. Check that the retry button retry the action
  10. Check that updating the address dismisses the error message

TC2
Apply the following patch

Patch
Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/NormalizeAddress.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/NormalizeAddress.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/NormalizeAddress.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/NormalizeAddress.kt	(revision 3c3054b603de22bc8fa3678a243afdba4ff32cbd)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/NormalizeAddress.kt	(date 1740175623640)
@@ -4,6 +4,7 @@
 import com.woocommerce.android.tools.SelectedSite
 import com.woocommerce.android.ui.orders.wooshippinglabels.models.AddressNormalizationModel
 import com.woocommerce.android.ui.orders.wooshippinglabels.networking.WooShippingLabelRepository
+import kotlinx.coroutines.delay
 import javax.inject.Inject
 
 class NormalizeAddress @Inject constructor(
@@ -11,17 +12,7 @@
     private val site: SelectedSite,
 ) {
     suspend operator fun invoke(address: Address): Result<AddressNormalizationModel> {
-        return site.getOrNull()?.let {
-            val response = repository.normalizeAddress(it, address)
-            val result = response.model
-            when {
-                response.isError || result == null -> {
-                    val message =
-                        response.error.message ?: if (result == null) "Empty response" else "Unknown error"
-                    Result.failure(Exception(message))
-                }
-                else -> Result.success(result)
-            }
-        } ?: Result.failure(Exception("No site selected"))
+        delay(400)
+        return Result.failure(Exception("No site selected"))
     }
 }

  1. Open the orders tab
  2. Tap on an order eligible for shipping label creation
  3. Expand the shipment details section
  4. Expand the origin address selection (3 dots)
  5. Tap on the pencil
  6. Update the address
  7. Tap on Validate & Save
  8. Check that when the response fails, a SnackBar message is displayed informing about the error with a retry action
  9. Check that the retry button retry the action
  10. Check that updating the address dismisses the error message

TC3
Apply the following patch

Patch
Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt	(revision 3c3054b603de22bc8fa3678a243afdba4ff32cbd)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt	(date 1740176147292)
@@ -5,6 +5,7 @@
 import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress
 import com.woocommerce.android.ui.orders.wooshippinglabels.networking.WooShippingLabelRepository
 import com.woocommerce.android.util.CoroutineDispatchers
+import kotlinx.coroutines.delay
 import kotlinx.coroutines.withContext
 import javax.inject.Inject
 
@@ -17,21 +18,7 @@
         address: Address,
         addressId: String?
     ): Result<OriginShippingAddress> {
-        return withContext(coroutineDispatchers.io) {
-            selectedSite.getOrNull()?.let {
-                val response = shippingRepository.updateOriginAddress(it, address, addressId)
-                val result = response.model
-                when {
-                    response.isError || result == null -> {
-                        val message =
-                            response.error.message
-                                ?: if (result == null) "Empty response" else "Unknown error"
-                        Result.failure(Exception(message))
-                    }
-
-                    else -> Result.success(result)
-                }
-            } ?: Result.failure(Exception("No site selected"))
-        }
+        delay(400)
+        return Result.failure(Exception("Not implemented"))
     }
 }
  1. Open the orders tab
  2. Tap on an order eligible for shipping label creation
  3. Expand the shipment details section
  4. Expand the origin address selection (3 dots)
  5. Tap on the pencil
  6. Update the address
  7. Tap on Validate & Save
  8. Tap on confirm changes
  9. Check that when the response fails, a SnackBar message is displayed informing about the error with a retry action
  10. Check that the retry button retry the action
  11. Check that selecting another address dismisses the error message

TC4
Apply the following patch

Patch
Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt	(revision 3c3054b603de22bc8fa3678a243afdba4ff32cbd)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/UpdateOriginAddress.kt	(date 1740176147292)
@@ -5,6 +5,7 @@
 import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress
 import com.woocommerce.android.ui.orders.wooshippinglabels.networking.WooShippingLabelRepository
 import com.woocommerce.android.util.CoroutineDispatchers
+import kotlinx.coroutines.delay
 import kotlinx.coroutines.withContext
 import javax.inject.Inject
 
@@ -17,21 +18,7 @@
         address: Address,
         addressId: String?
     ): Result<OriginShippingAddress> {
-        return withContext(coroutineDispatchers.io) {
-            selectedSite.getOrNull()?.let {
-                val response = shippingRepository.updateOriginAddress(it, address, addressId)
-                val result = response.model
-                when {
-                    response.isError || result == null -> {
-                        val message =
-                            response.error.message
-                                ?: if (result == null) "Empty response" else "Unknown error"
-                        Result.failure(Exception(message))
-                    }
-
-                    else -> Result.success(result)
-                }
-            } ?: Result.failure(Exception("No site selected"))
-        }
+        delay(400)
+        return Result.failure(Exception("Not implemented"))
     }
 }

  1. Open the orders tab
  2. Tap on an order eligible for shipping label creation
  3. Expand the shipment details section
  4. Expand the origin address selection (3 dots)
  5. Tap on the pencil
  6. Update the name field
  7. Tap on Save changes
  8. Check that when the response fails, a SnackBar message is displayed informing about the error with a retry action
  9. Check that the retry button retry the action
  10. Check that updating the address dismisses the error message

The tests that have been performed

Images/gif

Screen_recording_20250221_161755.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@atorresveiga atorresveiga added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Feb 21, 2025
@atorresveiga atorresveiga added this to the 21.9 milestone Feb 21, 2025
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 21, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit1e8817c
Direct Downloadwoocommerce-wear-prototype-build-pr13612-1e8817c.apk

@atorresveiga atorresveiga mentioned this pull request Feb 21, 2025
4 tasks
Base automatically changed from issue/12439-update-origin-address to trunk February 21, 2025 22:32
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 21, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit1e8817c
Direct Downloadwoocommerce-prototype-build-pr13612-1e8817c.apk

}
)

if (error != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SnackBars are not displayed on top of a BottomSheetDialog, I needed to define a new SnackBar on top of the BottomSheetDialog

@@ -27,16 +31,20 @@
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ButtonDefaults

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Snackbar

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
import androidx.compose.material.SnackbarDuration
import androidx.compose.material.SnackbarHost
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.SnackbarResult
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton

Check warning

Code scanning / Android Lint

material and material3 are separate, incompatible design system libraries Warning

Using a material import while also using the material3 library
@ThomazFB ThomazFB self-assigned this Feb 25, 2025
Copy link
Contributor

@ThomazFB ThomazFB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as described! Looks good :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants