Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

13.8
-----

- [*] Product form: a share action is shown in the navigation bar if the product can be shared and no more than one action is displayed, in addition to the more menu > Share. [https://github.com/woocommerce/woocommerce-ios/pull/9789]

13.7
-----
Expand Down
24 changes: 24 additions & 0 deletions WooCommerce/Classes/Analytics/WooAnalyticsEvent+ProductForm.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extension WooAnalyticsEvent {
enum ProductForm {
/// Event property keys.
private enum Key {
static let source = "source"
}

/// Tracked when the user taps on the button to share a product.
static func productDetailShareButtonTapped(source: ShareProductSource) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .productDetailShareButtonTapped,
properties: [Key.source: source.rawValue])
}
}
}

extension WooAnalyticsEvent.ProductForm {
/// Source of the share product action. The raw value is the event property value.
enum ShareProductSource: String {
/// From product form in the navigation bar.
case productForm = "product_form"
/// From product form > more menu in the navigation bar.
case moreMenu = "more_menu"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:

if viewModel.canShareProduct() {
actionSheet.addDefaultActionWithTitle(ActionSheetStrings.share) { [weak self] _ in
ServiceLocator.analytics.track(.productDetailShareButtonTapped)
self?.displayShareProduct()
self?.displayShareProduct(source: .moreMenu)
}
}

Expand Down Expand Up @@ -470,6 +469,10 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
}
}

@objc private func shareProduct() {
displayShareProduct(source: .productForm)
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
let section = tableViewModel.sections[section]
switch section {
Expand Down Expand Up @@ -858,7 +861,9 @@ private extension ProductFormViewController {
WebviewHelper.launch(url, with: self)
}

func displayShareProduct() {
func displayShareProduct(source: WooAnalyticsEvent.ProductForm.ShareProductSource) {
ServiceLocator.analytics.track(event: .ProductForm.productDetailShareButtonTapped(source: source))

guard let url = URL(string: product.permalink) else {
return
}
Expand Down Expand Up @@ -1003,6 +1008,8 @@ private extension ProductFormViewController {
return createSaveBarButtonItem()
case .more:
return createMoreOptionsBarButtonItem()
case .share:
return createShareBarButtonItem()
}
}

Expand Down Expand Up @@ -1048,6 +1055,12 @@ private extension ProductFormViewController {
moreButton.accessibilityIdentifier = "edit-product-more-options-button"
return moreButton
}

func createShareBarButtonItem() -> UIBarButtonItem {
UIBarButtonItem(barButtonSystemItem: .action,
target: self,
action: #selector(shareProduct))
}
}

// MARK: - Keyboard management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ final class ProductFormViewModel: ProductFormViewModelProtocol {
buttons.append(.more)
}

// Share button if up to one button is visible.
if canShareProduct() && buttons.count <= 1 {
buttons.insert(.share, at: 0)
}

return buttons
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum ActionButtonType {
case publish
case save
case more
case share
}

/// The type of save message when saving a product.
Expand Down
4 changes: 4 additions & 0 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
02490D1E284F3226002096EF /* ProductImagesSaverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02490D1D284F3226002096EF /* ProductImagesSaverTests.swift */; };
024A543422BA6F8F00F4F38E /* DeveloperEmailChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A543322BA6F8F00F4F38E /* DeveloperEmailChecker.swift */; };
024A543622BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A543522BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift */; };
024D4E842A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */; };
024DF3052372ADCD006658FE /* KeyboardScrollable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3042372ADCD006658FE /* KeyboardScrollable.swift */; };
024DF3072372C18D006658FE /* AztecUIConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3062372C18D006658FE /* AztecUIConfigurator.swift */; };
024DF3092372CA00006658FE /* EditorViewProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3082372CA00006658FE /* EditorViewProperties.swift */; };
Expand Down Expand Up @@ -2481,6 +2482,7 @@
02490D1D284F3226002096EF /* ProductImagesSaverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductImagesSaverTests.swift; sourceTree = "<group>"; };
024A543322BA6F8F00F4F38E /* DeveloperEmailChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperEmailChecker.swift; sourceTree = "<group>"; };
024A543522BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperEmailCheckerTests.swift; sourceTree = "<group>"; };
024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+ProductForm.swift"; sourceTree = "<group>"; };
024DF3042372ADCD006658FE /* KeyboardScrollable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardScrollable.swift; sourceTree = "<group>"; };
024DF3062372C18D006658FE /* AztecUIConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AztecUIConfigurator.swift; sourceTree = "<group>"; };
024DF3082372CA00006658FE /* EditorViewProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorViewProperties.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7451,6 +7453,7 @@
02B21C5629C9EEF900C5623B /* WooAnalyticsEvent+StoreOnboarding.swift */,
DE621F6929D67E1B000DE3BD /* WooAnalyticsEvent+JetpackSetup.swift */,
02E222C729FBA60F004579A1 /* WooAnalyticsEvent+ProductFormAI.swift */,
024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */,
);
path = Analytics;
sourceTree = "<group>";
Expand Down Expand Up @@ -11178,6 +11181,7 @@
03BB9EA5292E2D0C00251E9E /* CardReaderConnectionController.swift in Sources */,
B95112DA28BF79CA00D9578D /* PaymentsRoute.swift in Sources */,
7E6A019F2725CD76001668D5 /* FilterProductCategoryListViewModel.swift in Sources */,
024D4E842A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift in Sources */,
CC53FB3C2757EC7200C4CA4F /* ProductSelectorViewModel.swift in Sources */,
CCA1D5FE293F537400B40560 /* DeltaPercentage.swift in Sources */,
4569D3C325DC008700CDC3E2 /* SiteAddress.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ final class ProductFormViewModelTests: XCTestCase {
let actionButtons = viewModel.actionButtons

// Then
XCTAssertEqual(actionButtons, [.more])
XCTAssertEqual(actionButtons, [.share, .more])
}

func test_action_buttons_for_existing_draft_product_and_pending_changes() {
Expand Down Expand Up @@ -425,7 +425,7 @@ final class ProductFormViewModelTests: XCTestCase {
let actionButtons = viewModel.actionButtons

// Then
XCTAssertEqual(actionButtons, [.more])
XCTAssertEqual(actionButtons, [.share, .more])
}

func test_no_preview_button_for_existing_draft_product_on_site_with_no_frame_nonce() {
Expand Down