[Shipping labels] Init shipping service separately from loading the label rates #14557
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
WooShippingServiceViewModel
):loadLabelRates(for:)
method.empty
case to theLabelRatesState
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.WooShippingCreateLabelsViewModel
):selectedPackage
is set. Instead, we set it once when the view model is initialized.handleNewSelectedPackage(_:)
to handle the selected package. It sets theselectedPackage
property and also callsloadLabelRates(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.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: