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

Initial changes for saving product images upload statuses in UserDefaults #15196

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

Conversation

pmusolino
Copy link
Member

@pmusolino pmusolino commented Feb 18, 2025

Description

  • Purpose: Implement initial changes to save product image upload statuses in UserDefaults. (The actual save will happen in another PR) Ref. pe5sF9-3Uc
  • Why:
    • Required for background image uploads.
    • Ensure a stored queue of image statuses persists when the app is in the background.
    • Queue includes siteID and productID.
  • Background:
    • URLSession background configuration doesn't have access to ServiceLocator or similar classes.
    • System processes every element in scheduled URLSession upload tasks.
    • A queue must function even when the app isn't running.
  • Implementation:
    • Introduces ProductImagesUserDefaultsStatuses for storing statuses in UserDefaults.
    • Not currently used; will be implemented in a future PR.
    • Suggest skipping the review of ProductImagesUserDefaultsStatuses due to significant changes in a subsequent PR.
  • Additional Changes:
    • More changes than expected due to file relocations.

Questions that may arise:

  • Why use siteID and productID in ProductImageStatus?:
    • Background URLSession doesn't allow request updates during execution or scheduling. If the app goes in background, we do not have any power on it.
    • After user actions like pressing save, updating requests isn't feasible.
    • Then, Storing IDs helps check statuses from UserDefaults and send subsequent requests at the end of every future upload request.
    • Facilitates progress recovery and error management upon app re-launch from the background.

Main changes applied in this PR:

  • File Movements:
    • Moved ProductImageStatus to the Networking layer for background URLSession access.
    • Moved ProductOrVariationID enum to Networking layer for consistency.
  • Enhancements:
    • ProductImageStatus and ProductImageAssetType now conform to Codable for UserDefaults storage.
    • ProductImageStatus enum cases (uploading, remote, uploadFailure) now accept siteID and productID.
  • New Implementation:
    • ProductImagesUserDefaultsStatuses for ProductImageStatus storage.
    • Future changes expected, with unit tests to be added.
  • Code Updates:
    • Updated image upload classes to handle siteID and productID.
    • Updated related unit tests.

Testing information

  • Scenarios Tested:
    • Uploading multiple images in a new product, both before and after publishing.
    • Uploading multiple images in an existing product, both before and after saving.
    • Selecting and saving new images from the WordPress media library.
    • Ensuring image re-ordering functionality.
    • Uploading images to product variations and saving them before/after upload completion.
    • Managing image upload errors effectively.

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

…es in UserDefaults

- Modify `ProductImageStatus.swift` to add Codable conformance and additional properties
- Create `ProductImagesUserDefaultsStatuses.swift` for managing product image statuses in User Defaults
- Move `ProductOrVariationID` in a separate file to define a type-safe identifier for products and variations
- Update `Model.swift` to include `ProductOrVariationID` typealias
- Update `ProductImagesCollectionViewDataSource.swift` to include siteID and productID in `ProductImageStatus` cases.
- Modify `ProductImagesHeaderTableViewCell.swift` to handle additional parameters in `ProductImageStatus`.
- Adjust `Product+Media.swift` to pass siteID and productID when mapping images to `ProductImageStatus`.
- Change `ProductImageActionHandler.swift` to incorporate siteID and productID in `ProductImageStatus` handling and updating.
- Update `ProductImageStatus+Extension.swift` to manage new parameters in `ProductImageStatus`.
- Amend `ProductImagesCollectionViewController.swift` to handle siteID and productID in status cases.
- Modify `ProductImagesSaver.swift` to use siteID and productID in status comparison and updates.
- Adjust `ProductImagesViewController.swift` to manage `ProductImageStatus` with siteID and productID.
… all statuses without the correct value are now updated. This ensures that even if the statuses were initially created with a nil or outdated productID, they will be updated to the new remoteProductID.
…uploading` and `uploadFailure` cases

- Modify `ProductImagesUserDefaultsStatuses.swift` to handle optional `productID` in filtering statuses
@pmusolino pmusolino added this to the 21.8 milestone Feb 18, 2025
@pmusolino pmusolino added feature: product details Related to adding or editing products, including Product Settings. feature: add/edit products Related to adding or editing products. labels Feb 18, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 18, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 18, 2025

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 Numberpr15196-e012096
Version21.8
Bundle IDcom.automattic.alpha.woocommerce
Commite012096
App Center BuildWooCommerce - Prototype Builds #13134
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@pmusolino pmusolino changed the title Feat/save product image upload statuses in user defaults Initial changes for saving product images upload statuses in UserDefaults Feb 18, 2025
@wpmobilebot wpmobilebot modified the milestones: 21.8, 21.9 Feb 21, 2025
@wpmobilebot
Copy link
Collaborator

Version 21.8 has now entered code-freeze, so the milestone of this PR has been updated to 21.9.

…e-product-image-upload-statuses-in-user-defaults
…iationID` in `uploading` and `uploadFailure` cases

- Update unit tests
…pending upload, then trigger the media upload after adding the observer.
…ic. Instead of direct PHAsset comparison, compare localIdentifier to ensure accurate detection and state updates from "uploading" to "remote." This resolves the issue where hasUnsavedChangesOnImages(...) incorrectly returns true after saving, fixing related test failures.
@pmusolino pmusolino marked this pull request as ready for review February 24, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: add/edit products Related to adding or editing products. feature: product details Related to adding or editing products, including Product Settings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants