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

[Shipping labels] Error handling for load shipping rates fails #13653

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

irfano
Copy link
Contributor

@irfano irfano commented Mar 4, 2025

Closes: #13327

Description

This updates the error view for load shipping rates.

Steps to reproduce

To create fake error for loading shipping rates

  1. Go to Menu → Settings → Developer Options → API Faker
  2. Tap + button.
  3. Enter these settings:
Type: WordPress REST API
HTTP Method: GET
Path: /wcshipping/v1/label/rate
Status Code: 500

Error view

  1. Use a site that is eligible for shipping labels.
  2. Go to orders.
  3. Create a new order and complete the payment.
  4. Open the order details and tap the "Create shipping label" button.
  5. Tap the "Select a package button"
  6. Add a package.
  7. Verify that the error screen appears.
  8. Tap "APIFaker Enabled" banner and disable APIFaker.
  9. Tap the Retry button.
  10. Verify that the error screen disappears.

The tests that have been performed

Steps above

Images/gif

Network error No internet Large text
  • 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.

@irfano irfano added the feature: shipping labels Related to creating, ordering, or printing shipping labels. label Mar 4, 2025
@irfano irfano added this to the 21.9 milestone Mar 4, 2025
Copy link

coderabbitai bot commented Mar 4, 2025

📝 Walkthrough

Walkthrough

This PR refactors error handling in the WooCommerce shipping labels module. The ErrorMessageWithButton component has been updated to remove vertical scrolling and center the error text. Additionally, the ShippingRatesSection composable now leverages the new ErrorMessageWithButton for displaying errors, replacing the previous inline implementation. A new string resource for shipping rates error messaging has also been added. No changes were made to public APIs.

Changes

File(s) Change Summary
WooCommerce/.../packages/components/ErrorMessageWithButton.kt Removed vertical scrolling (verticalScroll(rememberScrollState())) and added centered text alignment (textAlign = TextAlign.Center).
WooCommerce/.../rates/ui/ShippingRatesSection.kt Replaced inline error display (using a Column with Text and WCColoredButton) with a call to the new ErrorMessageWithButton composable. Removed unused imports; added import for ErrorMessageWithButton.
WooCommerce/.../res/values/strings.xml Added new string resource woo_shipping_labels_package_creation_shipping_rates_loading_error with value "We are unable to load shipping rates."

Sequence Diagram(s)

sequenceDiagram
    participant S as ShippingRatesSection
    participant E as ErrorMessageWithButton
    participant U as User

    S->>E: Invoke ErrorMessageWithButton (pass error message & retry handler)
    U->>E: Clicks retry button
    E->>S: Trigger retry logic
Loading

Possibly related PRs

Suggested reviewers

  • atorresveiga
  • samiuelson

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@irfano irfano requested a review from atorresveiga March 4, 2025 00:07
@wpmobilebot
Copy link
Collaborator

📲 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
Commit4c14a8c
Direct Downloadwoocommerce-wear-prototype-build-pr13653-4c14a8c.apk

@wpmobilebot
Copy link
Collaborator

📲 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
Commit4c14a8c
Direct Downloadwoocommerce-prototype-build-pr13653-4c14a8c.apk

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 38.04%. Comparing base (11f67d0) to head (4c14a8c).
Report is 59 commits behind head on trunk.

Files with missing lines Patch % Lines
...wooshippinglabels/rates/ui/ShippingRatesSection.kt 0.00% 4 Missing ⚠️
...bels/packages/components/ErrorMessageWithButton.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #13653   +/-   ##
=========================================
  Coverage     38.03%   38.04%           
  Complexity     9089     9089           
=========================================
  Files          2063     2063           
  Lines        113096   113088    -8     
  Branches      14351    14350    -1     
=========================================
  Hits          43021    43021           
+ Misses        66164    66156    -8     
  Partials       3911     3911           

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

@atorresveiga atorresveiga self-assigned this Mar 4, 2025
@ParaskP7
Copy link
Contributor

ParaskP7 commented Mar 4, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Mar 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/ErrorMessageWithButton.kt (1)

45-45: Improved text readability with centered alignment.

Adding textAlign = TextAlign.Center enhances the user experience by ensuring the error message is properly centered, making it more readable and visually balanced, especially for multi-line text messages.

Consider adding a content padding modifier to provide some spacing around the text for longer error messages:

Text(
    text = stringResource(message),
    style = MaterialTheme.typography.subtitle1,
    textAlign = TextAlign.Center,
+   modifier = Modifier.padding(horizontal = 16.dp),
    color = MaterialTheme.colors.onSurface,
)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11f67d0 and 4c14a8c.

📒 Files selected for processing (3)
  • WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/ErrorMessageWithButton.kt (2 hunks)
  • WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/rates/ui/ShippingRatesSection.kt (2 hunks)
  • WooCommerce/src/main/res/values/strings.xml (1 hunks)
🔇 Additional comments (4)
WooCommerce/src/main/res/values/strings.xml (1)

4462-4462: Well-phrased error message for shipping rates loading.

This new string resource provides a clear error message when shipping rates cannot be loaded, which helps improve the user experience by explaining what went wrong. The wording is consistent with other error messages in the application.

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/components/ErrorMessageWithButton.kt (1)

17-17: Added import for TextAlign to enable text centering.

The TextAlign import supports the new text alignment feature added to the error message.

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/rates/ui/ShippingRatesSection.kt (2)

8-11: Added imports for error handling refactoring.

Appropriate imports added to support the ErrorMessageWithButton component implementation.


31-35:

✅ Verification successful

Improved error handling with reusable component.

Replaced inline error UI code with the reusable ErrorMessageWithButton component, which improves code maintainability and consistency across the app. The specific error message and minimum height constraint ensure a good user experience.


🏁 Script executed:

#!/bin/bash
# Check if the string resource is properly defined for the error message

# Look for the string resource definition used in this component
grep -r "woo_shipping_labels_package_creation_shipping_rates_loading_error" --include="*.xml" .

Length of output: 273


Error Message UI Component Approved – Resource Validated

The reusable ErrorMessageWithButton usage for improved error handling was verified. The error message resource (woo_shipping_labels_package_creation_shipping_rates_loading_error) is correctly defined in the strings resource file, ensuring consistency and a good user experience.

@ParaskP7
Copy link
Contributor

ParaskP7 commented Mar 4, 2025

@coderabbitai review

A mistake Irfan, I wanted to trigger this on my own PRs while looking at yours, just because I wanted to look at something unrelated (Buildkite), apologies for the unnecessary noise... 😊

Copy link

coderabbitai bot commented Mar 4, 2025

Tip

For best results, initiate chat on the files or code changes.

@ParaskP7 No problem at all! These things happen. I understand you were just looking at this PR while trying to check something related to Buildkite on your own PRs. No worries about the accidental review trigger - it's not an issue.

Copy link
Contributor

@atorresveiga atorresveiga left a comment

Choose a reason for hiding this comment

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

Works as described!

LGTM! :shipit:

@atorresveiga atorresveiga merged commit 8edc004 into trunk Mar 5, 2025
17 of 18 checks passed
@atorresveiga atorresveiga deleted the issue/13327-load-shipping-rates-fails branch March 5, 2025 14:26
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load shipping rates fails
5 participants