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

Country support in edit origin address screen #13407

Merged
merged 15 commits into from
Jan 30, 2025

Conversation

atorresveiga
Copy link
Contributor

@atorresveiga atorresveiga commented Jan 28, 2025

Part of: #12439
Closes: #13561

Description

This PR adds support for country selection in the edit origin address screen. Besides country selection, it also handles the loading state and errors while fetching countries from the API.

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 on the origin address selection (3 dots)
  5. Tap on the pencil
  6. Tap on countries
  7. Check that the app navigates to the countries selection screen
  8. Select a country
  9. Check that the country is updated in the edit origin address screen

TC2

Apply the patch below to delay the countries response and return an error

Patch

Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/GetAcceptedOriginCountries.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/GetAcceptedOriginCountries.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/GetAcceptedOriginCountries.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/GetAcceptedOriginCountries.kt	(revision a8acdd380a9d5cc0f6504d6e23b2efe5713c5747)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/GetAcceptedOriginCountries.kt	(date 1738168477625)
@@ -2,19 +2,16 @@
 
 import com.woocommerce.android.model.Location
 import com.woocommerce.android.ui.orders.wooshippinglabels.address.GetAllCountries
+import kotlinx.coroutines.delay
 import javax.inject.Inject
 
 class GetAcceptedOriginCountries @Inject constructor(
     private val getCountries: GetAllCountries
 ) {
     suspend operator fun invoke(): Result<List<Location>> {
-        val result = getCountries()
-        return if (result.isSuccess) {
-            val acceptedCountries = result.getOrThrow().filter { ACCEPTED_USPS_ORIGIN_COUNTRIES.contains(it.code) }
-            Result.success(acceptedCountries)
-        } else {
-            result
-        }
+        getCountries()
+        delay(10_000)
+        return Result.failure(Exception("Error"))
     }
 
     companion object {

  1. Open the orders tab
  2. Tap on an order eligible for shipping label creation
  3. Expand the shipment details section
  4. Expand on the origin address selection (3 dots)
  5. Tap on the pencil
  6. Tap on countries before 10s as passed since the screen is displayed
  7. Check that a loading indicator is displayed
  8. Wait 10s
  9. Check that when the response fails, a message is displayed in a Snackbar with a retry action
  10. Check that tapping on the retry action refreshes the countries

The tests that have been performed

  • Checking the UI works as expected

Images/gif

Screen_recording_20250129_135535.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.

@dangermattic
Copy link
Collaborator

dangermattic commented Jan 28, 2025

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class CountriesState is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 28, 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
Commita600e9d
Direct Downloadwoocommerce-wear-prototype-build-pr13407-a600e9d.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 28, 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
Commita600e9d
Direct Downloadwoocommerce-prototype-build-pr13407-a600e9d.apk

@atorresveiga atorresveiga changed the title Issue/12439 countries support Countries support in edit origin address screen Jan 29, 2025
@atorresveiga atorresveiga requested a review from ThomazFB January 29, 2025 16:56
@atorresveiga atorresveiga added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Jan 29, 2025
@atorresveiga atorresveiga added this to the 21.6 milestone Jan 29, 2025
@atorresveiga atorresveiga marked this pull request as ready for review January 29, 2025 16:57
@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 73.56322% with 23 lines in your changes missing coverage. Please review.

Project coverage is 41.26%. Comparing base (975c78d) to head (a600e9d).
Report is 14921 commits behind head on trunk.

Files with missing lines Patch % Lines
...s/address/origin/WooShippingEditOriginViewModel.kt 64.15% 16 Missing and 3 partials ⚠️
...rders/wooshippinglabels/address/GetAllCountries.kt 87.50% 0 Missing and 2 partials ⚠️
...abels/address/origin/GetAcceptedOriginCountries.kt 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #13407      +/-   ##
============================================
+ Coverage     41.22%   41.26%   +0.03%     
- Complexity     6541     6551      +10     
============================================
  Files          1326     1328       +2     
  Lines         77687    77765      +78     
  Branches      10697    10709      +12     
============================================
+ Hits          32030    32089      +59     
- Misses        42815    42830      +15     
- Partials       2842     2846       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@atorresveiga atorresveiga changed the title Countries support in edit origin address screen Country support in edit origin address screen Jan 29, 2025
import com.woocommerce.android.ui.orders.wooshippinglabels.address.GetAllCountries
import javax.inject.Inject

class GetAcceptedOriginCountries @Inject constructor(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created two different use cases so we can reuse the get all countries use case when working on the edit destination address

@ThomazFB ThomazFB self-assigned this Jan 30, 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.

I can confirm that both the GetAllCountries and GetAcceptedOriginCountries are working as expected, and the list presented in the Origin Address Editing is only the small list accepted by USPS. Selection works just fine too!

LGTM! :shipit:

import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.CircularProgressIndicator

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.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarDuration

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.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarDuration
import androidx.compose.material.SnackbarHost

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.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarDuration
import androidx.compose.material.SnackbarHost
import androidx.compose.material.SnackbarHostState

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

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.SnackbarHost
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.SnackbarResult
import androidx.compose.material.Surface

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
@atorresveiga atorresveiga merged commit 6288b27 into trunk Jan 30, 2025
15 checks passed
@atorresveiga atorresveiga deleted the issue/12439-countries-support branch January 30, 2025 23:19
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. unit-tests-exemption
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get Countries
5 participants