Skip to content

Conversation

@ealeksandrov
Copy link
Contributor

@ealeksandrov ealeksandrov commented Oct 27, 2022

Closes: #7944

Description

This PR adds button on product details to show a preview. Button should appear:

  • for new product flow (when it's possible to create a draft, but not for a completely blank product)
  • for existing drafts (unchanged and modified).

It triggers draft saving (if needed) before opening webview with preview URL (unauthenticated at this stage).
The whole new feature is hidden behind new feature flag.

Testing

  1. Open products tab.
  2. Open any existing published product.
    1. Confirm that there is no "Preview" button in navbar.
    2. Update any product property.
    3. Confirm that "Save" button appears, but there is still no "Preview" button.
  3. Start the flow to create new product ("+" button in navbar on product list)
    1. Edit the title (or anything else) to have non-blank product.
    2. Confirm that "Preview" button appears in navbar.
    3. Tap it and check that draft is saved before WebView opens (ignore web content).
  4. Open any existing draft product (you can continue with product from last step).
    1. Confirm that "Preview" button appears in navbar.
    2. Tap it and check that WebView immediately opens (ignore web content).
    3. Update any product property.
    4. Confirm that "Preview" button still available and tap it.
    5. Confirm that draft is saved before WebView opens.

Screenshots

before after
Simulator Screen Shot Simulator Screen Shot

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

@ealeksandrov ealeksandrov added feature: product details Related to adding or editing products, including Product Settings. status: feature-flagged Behind a feature flag. Milestone is not strongly held. labels Oct 27, 2022
@ealeksandrov ealeksandrov added this to the 11.0 milestone Oct 27, 2022
@ealeksandrov
Copy link
Contributor Author

Reverted unit tests on actionButtons because they are failing on CI due to disabled feature flag.
Will consider adding FeatureFlagService dependency injection later.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 27, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr7960-dad2691 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

Copy link
Contributor

@Ecarrion Ecarrion left a comment

Choose a reason for hiding this comment

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

The looks good, my main worry is one suggestion to make sure all cases are covered and tested!

Also I think we need to update some test cases.


I went through the test cases and have a couple of concerns/questions

  • If you change a published product status to draft (using the products settings screen) you get the preview button, should that be the case? or should we wait until the product is actually saved as a draft before showing the preview button?
change-product.mov
  • If you start creating a new product, you get immediately the preview button. Is that ok or should we wait for at least one change?

Comment on lines 50 to 51
case .productsPreview:
return buildConfig == .localDeveloper || buildConfig == .alpha
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could use the same .productsOnboarding feature flag right?
When the other deliverables are done, we can just take them out of the feature flag check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, updated in edf3702

updatedQueryItems.append(.init(name: "preview", value: "true"))
permalink?.queryItems = updatedQueryItems
guard let url = permalink?.url else {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this fail? if it can, should we show some kind of toast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The source string, product.permalink is non-optional property. But all URL manipulation tools in iOS SDK return optional URL result.
So I consider this one is safe and never reachable.

Comment on lines 155 to 158
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.productsPreview),
(canSaveAsDraft() || productModel.status == .draft) {
buttons.insert(.preview, at: 0)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we could move this logic to the switch above, or would things get more complicated? The switch is useful for us to not miss any case or combination.

Also, do you think this is worth unit testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic doesn't really fit in switch cases + it requires FeatureFlag check. If we add it to switch above, it'll explode into more cases and it'll be hard to understand when "preview" flow is applied.
I've updated it with comments in b6ea899, c1e812f.

Unit tests added in d69489c.

@ealeksandrov
Copy link
Contributor Author

Thanks @Ecarrion for useful feedback and suggestions!

Also I think we need to update some test cases.

Agree! I've added test initially, but rolled them back because of feature flag conflict.
Fixed it properly by:

  • adding feature flag DI (6281f5b)
  • forcing older tests to disabled flag state, so they behave in same way on CI and locally (9401ad1)
  • adding .productsOnboarding support to MockFeatureFlagService (ac52d2d)
  • adding set of tests covering preview logic under enabled feature flag (d69489c)

If you change a published product status to draft (using the products settings screen) you get the preview button, should that be the case? or should we wait until the product is actually saved as a draft before showing the preview button?

I agree that we shouldn't allow preview here. Because it will trigger "unpublishing" of a product before user actually tap "save" to confirm a change.
Changed in 9867928.

If you start creating a new product, you get immediately the preview button. Is that ok or should we wait for at least one change?

I don't see much issue in that, but also there is no value :)
Changed in b6ea899.

# Conflicts:
#	Experiments/Experiments/FeatureFlag.swift
#	WooCommerce/WooCommerceTests/Mocks/MockFeatureFlagService.swift
@ealeksandrov ealeksandrov modified the milestones: 11.0, 11.1 Oct 28, 2022
@ealeksandrov ealeksandrov requested a review from Ecarrion October 28, 2022 15:27
@Ecarrion Ecarrion self-assigned this Oct 31, 2022
Copy link
Contributor

@Ecarrion Ecarrion left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for the changes! 🚀

@ealeksandrov ealeksandrov merged commit a7e296c into trunk Oct 31, 2022
@ealeksandrov ealeksandrov deleted the issue/7944-product-preview-flow branch October 31, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: product details Related to adding or editing products, including Product Settings. status: feature-flagged Behind a feature flag. Milestone is not strongly held.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Product Preview: Feature flag and CTA button

4 participants