Skip to content

Commit eaaf30f

Browse files
authored
Merge pull request #9789 from woocommerce/feat/9788-share-product-cta
Show the share CTA in product form navigation bar
2 parents 6ef5832 + 77ed9a3 commit eaaf30f

File tree

7 files changed

+53
-6
lines changed

7 files changed

+53
-6
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
13.8
44
-----
5-
5+
- [*] 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]
66

77
13.7
88
-----
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extension WooAnalyticsEvent {
2+
enum ProductForm {
3+
/// Event property keys.
4+
private enum Key {
5+
static let source = "source"
6+
}
7+
8+
/// Tracked when the user taps on the button to share a product.
9+
static func productDetailShareButtonTapped(source: ShareProductSource) -> WooAnalyticsEvent {
10+
WooAnalyticsEvent(statName: .productDetailShareButtonTapped,
11+
properties: [Key.source: source.rawValue])
12+
}
13+
}
14+
}
15+
16+
extension WooAnalyticsEvent.ProductForm {
17+
/// Source of the share product action. The raw value is the event property value.
18+
enum ShareProductSource: String {
19+
/// From product form in the navigation bar.
20+
case productForm = "product_form"
21+
/// From product form > more menu in the navigation bar.
22+
case moreMenu = "more_menu"
23+
}
24+
}

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
281281

282282
if viewModel.canShareProduct() {
283283
actionSheet.addDefaultActionWithTitle(ActionSheetStrings.share) { [weak self] _ in
284-
ServiceLocator.analytics.track(.productDetailShareButtonTapped)
285-
self?.displayShareProduct()
284+
self?.displayShareProduct(source: .moreMenu)
286285
}
287286
}
288287

@@ -470,6 +469,10 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
470469
}
471470
}
472471

472+
@objc private func shareProduct() {
473+
displayShareProduct(source: .productForm)
474+
}
475+
473476
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
474477
let section = tableViewModel.sections[section]
475478
switch section {
@@ -858,7 +861,9 @@ private extension ProductFormViewController {
858861
WebviewHelper.launch(url, with: self)
859862
}
860863

861-
func displayShareProduct() {
864+
func displayShareProduct(source: WooAnalyticsEvent.ProductForm.ShareProductSource) {
865+
ServiceLocator.analytics.track(event: .ProductForm.productDetailShareButtonTapped(source: source))
866+
862867
guard let url = URL(string: product.permalink) else {
863868
return
864869
}
@@ -1003,6 +1008,8 @@ private extension ProductFormViewController {
10031008
return createSaveBarButtonItem()
10041009
case .more:
10051010
return createMoreOptionsBarButtonItem()
1011+
case .share:
1012+
return createShareBarButtonItem()
10061013
}
10071014
}
10081015

@@ -1048,6 +1055,12 @@ private extension ProductFormViewController {
10481055
moreButton.accessibilityIdentifier = "edit-product-more-options-button"
10491056
return moreButton
10501057
}
1058+
1059+
func createShareBarButtonItem() -> UIBarButtonItem {
1060+
UIBarButtonItem(barButtonSystemItem: .action,
1061+
target: self,
1062+
action: #selector(shareProduct))
1063+
}
10511064
}
10521065

10531066
// MARK: - Keyboard management

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ final class ProductFormViewModel: ProductFormViewModelProtocol {
168168
buttons.append(.more)
169169
}
170170

171+
// Share button if up to one button is visible.
172+
if canShareProduct() && buttons.count <= 1 {
173+
buttons.insert(.share, at: 0)
174+
}
175+
171176
return buttons
172177
}
173178

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewModelProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum ActionButtonType {
1414
case publish
1515
case save
1616
case more
17+
case share
1718
}
1819

1920
/// The type of save message when saving a product.

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
02490D1E284F3226002096EF /* ProductImagesSaverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02490D1D284F3226002096EF /* ProductImagesSaverTests.swift */; };
192192
024A543422BA6F8F00F4F38E /* DeveloperEmailChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A543322BA6F8F00F4F38E /* DeveloperEmailChecker.swift */; };
193193
024A543622BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A543522BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift */; };
194+
024D4E842A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */; };
194195
024DF3052372ADCD006658FE /* KeyboardScrollable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3042372ADCD006658FE /* KeyboardScrollable.swift */; };
195196
024DF3072372C18D006658FE /* AztecUIConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3062372C18D006658FE /* AztecUIConfigurator.swift */; };
196197
024DF3092372CA00006658FE /* EditorViewProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024DF3082372CA00006658FE /* EditorViewProperties.swift */; };
@@ -2481,6 +2482,7 @@
24812482
02490D1D284F3226002096EF /* ProductImagesSaverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductImagesSaverTests.swift; sourceTree = "<group>"; };
24822483
024A543322BA6F8F00F4F38E /* DeveloperEmailChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperEmailChecker.swift; sourceTree = "<group>"; };
24832484
024A543522BA84DB00F4F38E /* DeveloperEmailCheckerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperEmailCheckerTests.swift; sourceTree = "<group>"; };
2485+
024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+ProductForm.swift"; sourceTree = "<group>"; };
24842486
024DF3042372ADCD006658FE /* KeyboardScrollable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardScrollable.swift; sourceTree = "<group>"; };
24852487
024DF3062372C18D006658FE /* AztecUIConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AztecUIConfigurator.swift; sourceTree = "<group>"; };
24862488
024DF3082372CA00006658FE /* EditorViewProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorViewProperties.swift; sourceTree = "<group>"; };
@@ -7451,6 +7453,7 @@
74517453
02B21C5629C9EEF900C5623B /* WooAnalyticsEvent+StoreOnboarding.swift */,
74527454
DE621F6929D67E1B000DE3BD /* WooAnalyticsEvent+JetpackSetup.swift */,
74537455
02E222C729FBA60F004579A1 /* WooAnalyticsEvent+ProductFormAI.swift */,
7456+
024D4E832A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift */,
74547457
);
74557458
path = Analytics;
74567459
sourceTree = "<group>";
@@ -11178,6 +11181,7 @@
1117811181
03BB9EA5292E2D0C00251E9E /* CardReaderConnectionController.swift in Sources */,
1117911182
B95112DA28BF79CA00D9578D /* PaymentsRoute.swift in Sources */,
1118011183
7E6A019F2725CD76001668D5 /* FilterProductCategoryListViewModel.swift in Sources */,
11184+
024D4E842A1B4B630090E0E6 /* WooAnalyticsEvent+ProductForm.swift in Sources */,
1118111185
CC53FB3C2757EC7200C4CA4F /* ProductSelectorViewModel.swift in Sources */,
1118211186
CCA1D5FE293F537400B40560 /* DeltaPercentage.swift in Sources */,
1118311187
4569D3C325DC008700CDC3E2 /* SiteAddress.swift in Sources */,

WooCommerce/WooCommerceTests/ViewRelated/Products/Edit Product/ProductFormViewModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ final class ProductFormViewModelTests: XCTestCase {
357357
let actionButtons = viewModel.actionButtons
358358

359359
// Then
360-
XCTAssertEqual(actionButtons, [.more])
360+
XCTAssertEqual(actionButtons, [.share, .more])
361361
}
362362

363363
func test_action_buttons_for_existing_draft_product_and_pending_changes() {
@@ -425,7 +425,7 @@ final class ProductFormViewModelTests: XCTestCase {
425425
let actionButtons = viewModel.actionButtons
426426

427427
// Then
428-
XCTAssertEqual(actionButtons, [.more])
428+
XCTAssertEqual(actionButtons, [.share, .more])
429429
}
430430

431431
func test_no_preview_button_for_existing_draft_product_on_site_with_no_frame_nonce() {

0 commit comments

Comments
 (0)