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

[Product Creation AI v2] Select package image #13193

Merged
merged 17 commits into from
Jul 2, 2024

Conversation

selanthiraiyan
Copy link
Contributor

@selanthiraiyan selanthiraiyan commented Jun 28, 2024

Part of: #13104

Description

Adds a way to select a package photo for the product creation with AI flow.

Changes

  • Add coordinator to select package photo.
  • Show the selected package image.
  • Add Menu to view, replace and remove selected package photo.

Steps to reproduce

  1. Create a JN site with Jetpack AI plugin
  2. Turn on productCreationAIv2M1 feature flag
  3. Build and run the app
  4. Navigate to the products tab
  5. Tap + button on top right
  6. Tap "Create a product with AI"
  7. Tap "Read text from product photo" button below the text field
  8. Validate that selecting a photo from device/camera/media library works.
  9. The selected photo should be displayed on the button below the text field.
  10. Tap the ellipsis button and validate that the menu with options "View Photo", "Replace Photo" and "Remove Photo"
  11. Tap on "Replace Photo" and validate the image selection flow opens again.
  12. Tap on "Remove Photo", and the selected image is removed, and the button returns to the button with the "Read text from product photo" title.

Screenshots

PackageSelection.mp4

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

@selanthiraiyan selanthiraiyan mentioned this pull request Jun 28, 2024
3 tasks
@selanthiraiyan selanthiraiyan added type: task An internally driven task. feature: add/edit products Related to adding or editing products. and removed type: task An internally driven task. labels Jun 28, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jun 28, 2024

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 Numberpr13193-a9c8a49
Version19.3
Bundle IDcom.automattic.alpha.woocommerce
Commita9c8a49
App Center BuildWooCommerce - Prototype Builds #9834
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@selanthiraiyan selanthiraiyan added this to the 19.4 milestone Jun 28, 2024
@selanthiraiyan selanthiraiyan marked this pull request as ready for review June 28, 2024 13:56
@itsmeichigo itsmeichigo self-assigned this Jul 1, 2024
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

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

This works as expected 👍 I left some nit-picking comments below.

Comment on lines +15 to +17
viewModel.startingInfoViewModel.onPickPackagePhoto = { [weak self] source in
await self?.presentImageSelectionFlow(source: source)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❓Could you explain why need to use async here? It seems to me that we're mixing the logic of presenting the selection flow with the selected image.

Would it be possible to separate the logic like what we did previously with the old flow? i.e. We keep the presentation of the image picker flow synchronous; and when an image is selected, we trigger a method in startingInfoViewModel with the selected image. Would that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you explain why need to use async here? It seems to me that we're mixing the logic of presenting the selection flow with the selected image.

We are using async because we will send the image view into a loading state and wait for the image to be received from this method. Code here

Would it be possible to separate the logic like what we did previously with the old flow? i.e. We keep the presentation of the image picker flow synchronous; and when an image is selected, we trigger a method in startingInfoViewModel with the selected image. Would that work?

I actually followed the pattern from AddProductFromImageCoordinator and made this method async. We use the same pattern in BlazeEditAdHostingController as well. Please correct me if I am misunderstanding things.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer a more naive implementation for separation of concerns. I'm also worried about the use of async because it could potentially come with complications when migrating to Swift 6. Please use your own judgement to decide whether to rewrite this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input, Huong!

After considering this, I prefer to keep the implementation as is.

My thoughts are,

  1. Separation of concerns wise, SelectPackageImageCoordinator takes care of selecting and downloading the image. SelectPackageImageCoordinator also encapsulates the different paths of camera capture, device media library and WP Media library image selection. After initial selection, all those paths require async operations to prepare the MediaPickerImage. i.e. We present the selection flow and wait to get back a MediaPickerImage.
  2. Using await in ProductCreationAIStartingInfoViewModel makes it easy to maintain the previous image state and display a loading indicator until the image is ready.
  3. We can alter this if we find any complications while migrating to Swift 6. SelectPackageImageCoordinator along with BlazeEditAdHostingController (We will remove AddProductFromImageCoordinator while removing package flow code)

Please let me know if you still think we need to change this. I will add a subtask and work on this at the end of the project. 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with keeping this as-is for now, thanks for the explanation!

enum Localization {
static let photoUploaded = NSLocalizedString(
"productCreationAIStartingInfoView.packagePhotoView.viewPhoto",
value: "Photo uploaded",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should we use "Photo selected" instead? "uploaded" sounds like the photo has been uploaded somewhere - it's misleading to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done in a995988

static let photoUploaded = NSLocalizedString(
"productCreationAIStartingInfoView.packagePhotoView.viewPhoto",
value: "Photo uploaded",
comment: "Button title in starting info screen."
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we should explain clearly what the text is about to make it easier for translators. Same comment for the below strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in aba6505

@selanthiraiyan selanthiraiyan enabled auto-merge July 2, 2024 03:15
@selanthiraiyan selanthiraiyan merged commit 1dcc8f0 into trunk Jul 2, 2024
22 checks passed
@selanthiraiyan selanthiraiyan deleted the feat/13104-select-image branch July 2, 2024 03:36
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants