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

[Woo POS] Coupons: Fetch from remote #15423

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

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Mar 26, 2025

Closes: #15324

Description

This PR adds the ability to fetch coupons from remote to the coupons service. First, we attempt to fetch from the remote. If this fails, we'll attempt to fetch from storage. If fails, we just return an empty list of coupons (for the moment)

We might change the fetching strategy, for now it seemed adequate to attempt remote first and local storage later.

Screen.Recording.2025-03-26.at.13.58.58.mov

Testing information

  • On POS, tap the coupons button
  • Observe the loading screen and coupons being loaded from remote
  • Stop the app and throw an error from CouponsRemote.loadAllCoupons():
    public func loadAllCoupons(for siteID: Int64,
                               pageNumber: Int = CouponsRemote.Default.pageNumber,
                               pageSize: Int = CouponsRemote.Default.pageSize) async throws -> [Coupon] {
        throw NSError(domain: "oops", code: -1)
        try await withCheckedThrowingContinuation { continuation in
   ...
    }
  • Observe that we'll still load coupons, but this time they come from the storage fallback:
"Failed to load coupons from remote:" Error Domain=oops Code=-1 "(null)"

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

@iamgabrielma iamgabrielma added type: task An internally driven task. feature: coupons Related to basic fulfillment such as order tracking. feature: POS labels Mar 26, 2025
@iamgabrielma iamgabrielma added this to the 22.1 milestone Mar 26, 2025
@iamgabrielma iamgabrielma requested a review from staskus March 26, 2025 07:07
@iamgabrielma
Copy link
Contributor Author

We might change the fetching strategy, for now it seemed adequate to attempt remote first and local storage later.

I'm not sure but I think we might have discussed to do the opposite? Storage first and remote later?

@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 Numberpr15423-d47f648
Version22.0
Bundle IDcom.automattic.alpha.woocommerce
Commitd47f648
App Center BuildWooCommerce - Prototype Builds #13419
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@staskus
Copy link
Contributor

staskus commented Mar 26, 2025

I'm not sure but I think we might have discussed to do the opposite? Storage first and remote later?

@iamgabrielma Yes, I imagined we could do local first so the results would appear immediately, but update them with remote ones. How does the current IPP implementation work? As I understand, it's storage-first. My idea was to keep the same strategy as IPP to save time on coming up with alternatives.

Observe the loading screen and coupons being loaded from remote

A full-screen loading doesn't work here. A good point is that we need to ask a designer to consider how we display a loading state. Asked here p1742974197820449-slack-C070SJRA8DP

@staskus
Copy link
Contributor

staskus commented Mar 26, 2025

This is how IPP works.

I added a new coupon and returned to the screen. After a moment, a new coupon appeared. We could sync with the design on this as well. Maybe we could show a small loading indicator somewhere as well while the network request is ongoing. Wdyt?

ScreenRecording_03-26-2025.09-36-12_1.mov

Base automatically changed from task/15416-pos-provide-coupons-to-ui to trunk March 26, 2025 13:45
@iamgabrielma
Copy link
Contributor Author

iamgabrielma commented Mar 28, 2025

we could do local first so the results would appear immediately, but update them with remote ones. How does the current IPP implementation work? As I understand, it's storage-first. My idea was to keep the same strategy as IPP to save time on coming up with alternatives.

That sounds good, I'll take a deeper look of how we do it in coupons in the app and make the changes to do local first -> then update with remote results. I'll see if I can change the loading indicator on this PR as well or add the "ghost rows" separately 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: coupons Related to basic fulfillment such as order tracking. feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Woo POS] Coupons: Fetch all coupons from remote
3 participants