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] Init shipping service separately from loading the label rates #14557

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

rachelmcr
Copy link
Contributor

Part of: #14522

Description

We want to display the selected package from the "Add Package" section on the main screen in the Woo Shipping label creation flow. Once the package is selected, we will be able to change the package or update its weight. Any change to the selected package will update the available rates in the shipping service.

This PR is the first step for doing that: It separates the shipping service VM init method from the action to load label rates. That way we can init the VM once and load the label rates each time there are updates to the selected package.

How

  • Changes to the shipping service VM (WooShippingServiceViewModel):
    • This removes the selected package from the view model's init method, since it's only used to load the label rates from remote. Any time the selected package changes, we can call the loadLabelRates(for:) method.
    • We add an empty case to the LabelRatesState enum and set that as the default state. We can use this if we ever need to show an empty state for the shipping services.
  • Changes to the main screen VM (WooShippingCreateLabelsViewModel):
    • We no longer set the shipping service VM every time selectedPackage is set. Instead, we set it once when the view model is initialized.
    • We have a new method handleNewSelectedPackage(_:) to handle the selected package. It sets the selectedPackage property and also calls loadLabelRates(for:) to get the rates for the package.

Note: We don't yet use the handleNewSelectedPackage(_:) method. The next PR will integrate this into the "Add Package" flow so we can set the selected package.

Testing information

This is a preliminary step in preparation for setting the selected package in the "Add Package" flow. For now, confirm that tests pass (the shipping service works as expected when label rates are loaded).

This can also be tested by manually triggering the handleNewSelectedPackage(_:) method with mock package data.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

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 all devices (phone/tablet) and no regressions are added.

@rachelmcr rachelmcr added the feature: shipping labels Related to creating, ordering, or printing shipping labels. label Nov 28, 2024
@rachelmcr rachelmcr added this to the 21.3 milestone Nov 28, 2024
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

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

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14557-35f404d
Version21.2
Bundle IDcom.automattic.alpha.woocommerce
Commit35f404d
App Center BuildWooCommerce - Prototype Builds #11842
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@rachelmcr rachelmcr merged commit d082f93 into trunk Nov 28, 2024
19 checks passed
@rachelmcr rachelmcr deleted the issue/14522-handle-selected-package-changes branch November 28, 2024 18:07
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.

3 participants