Skip to content

Commit 36762be

Browse files
committed
Populate variations option presenter
1 parent 58e4656 commit 36762be

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

WooCommerce/Classes/ViewRelated/Products/Variations/GenerateAllVariationsPresenter.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Foundation
2+
import UIKit
3+
import Yosemite
4+
5+
/// Type to encapsulate the options presented when generating variations.
6+
///
7+
final class GenerateVariationsOptionsPresenter {
8+
/// Options available when generating variations
9+
///
10+
enum Option {
11+
case single
12+
case all
13+
}
14+
15+
/// Base view controller where the loading indicators and notices will be presented.
16+
///
17+
private let baseViewController: UIViewController
18+
19+
init(baseViewController: UIViewController) {
20+
self.baseViewController = baseViewController
21+
}
22+
23+
/// Displays a bottom sheet allowing the merchant to choose whether to generate one variation or to generate all variations.
24+
///
25+
func presentGenerationOptions(sourceView: UIView, onCompletion: @escaping (_ selectedOption: Option) -> Void) {
26+
guard ServiceLocator.featureFlagService.isFeatureFlagEnabled(.generateAllVariations) else {
27+
return onCompletion(.single)
28+
}
29+
30+
let viewProperties = BottomSheetListSelectorViewProperties(title: Localization.addVariationAction)
31+
let command = GenerateVariationsSelectorCommand(selected: nil) { [weak self] option in
32+
guard let self else { return }
33+
self.baseViewController.dismiss(animated: true)
34+
switch option {
35+
case .single:
36+
onCompletion(.single)
37+
case .all:
38+
onCompletion(.all)
39+
}
40+
}
41+
let bottomSheetPresenter = BottomSheetListSelectorPresenter(viewProperties: viewProperties, command: command)
42+
bottomSheetPresenter.show(from: baseViewController, sourceView: sourceView)
43+
}
44+
}
45+
46+
// MARK: Localization
47+
//
48+
private extension GenerateVariationsOptionsPresenter {
49+
enum Localization {
50+
static let addVariationAction = NSLocalizedString("Add Variation",
51+
comment: "Title on empty state button when the product has attributes but no variations")
52+
}
53+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@
642642
26771A14256FFA8700EE030E /* IssueRefundCoordinatingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26771A13256FFA8700EE030E /* IssueRefundCoordinatingController.swift */; };
643643
2678897C270E6E8B00BD249E /* SimplePaymentsAmount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2678897B270E6E8B00BD249E /* SimplePaymentsAmount.swift */; };
644644
267D6882296485850072ED0C /* ProductVariationGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 267D6881296485850072ED0C /* ProductVariationGeneratorTests.swift */; };
645-
26838354296F460B00CCF60A /* GenerateAllVariationsPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26838353296F460B00CCF60A /* GenerateAllVariationsPresenter.swift */; };
645+
26838354296F460B00CCF60A /* GenerateVariationsOptionPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26838353296F460B00CCF60A /* GenerateVariationsOptionPresenter.swift */; };
646646
2687165524D21BC80042F6AE /* SurveySubmittedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2687165324D21BC80042F6AE /* SurveySubmittedViewController.swift */; };
647647
2687165624D21BC80042F6AE /* SurveySubmittedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2687165424D21BC80042F6AE /* SurveySubmittedViewController.xib */; };
648648
2687165A24D350C20042F6AE /* SurveyCoordinatingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2687165924D350C20042F6AE /* SurveyCoordinatingController.swift */; };
@@ -2704,7 +2704,7 @@
27042704
2678897B270E6E8B00BD249E /* SimplePaymentsAmount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplePaymentsAmount.swift; sourceTree = "<group>"; };
27052705
267CFE1824435A5500AF3A13 /* ProductCategoryViewModelBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCategoryViewModelBuilderTests.swift; sourceTree = "<group>"; };
27062706
267D6881296485850072ED0C /* ProductVariationGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVariationGeneratorTests.swift; sourceTree = "<group>"; };
2707-
26838353296F460B00CCF60A /* GenerateAllVariationsPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateAllVariationsPresenter.swift; sourceTree = "<group>"; };
2707+
26838353296F460B00CCF60A /* GenerateVariationsOptionPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateVariationsOptionPresenter.swift; sourceTree = "<group>"; };
27082708
2687165324D21BC80042F6AE /* SurveySubmittedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveySubmittedViewController.swift; sourceTree = "<group>"; };
27092709
2687165424D21BC80042F6AE /* SurveySubmittedViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SurveySubmittedViewController.xib; sourceTree = "<group>"; };
27102710
2687165924D350C20042F6AE /* SurveyCoordinatingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyCoordinatingController.swift; sourceTree = "<group>"; };
@@ -4799,7 +4799,7 @@
47994799
26F65C9725DEDAF0008FAE29 /* GenerateVariationUseCase.swift */,
48004800
269A2F46295CC683000828A8 /* GenerateVariationsSelectorCommand.swift */,
48014801
263C4CBF2963784900CA7E05 /* ProductVariationGenerator.swift */,
4802-
26838353296F460B00CCF60A /* GenerateAllVariationsPresenter.swift */,
4802+
26838353296F460B00CCF60A /* GenerateVariationsOptionPresenter.swift */,
48034803
4515262B2577D48D0076B03C /* Add Attributes */,
48044804
AEDDDA0825CA9C0A0077F9B2 /* Edit Attributes */,
48054805
);
@@ -10234,7 +10234,7 @@
1023410234
B541B220218A007C008FE7C1 /* NSMutableParagraphStyle+Helpers.swift in Sources */,
1023510235
45AE582C230D9D35001901E3 /* OrderNoteHeaderTableViewCell.swift in Sources */,
1023610236
6832C7CA26DA5C4500BA4088 /* LabeledTextViewTableViewCell.swift in Sources */,
10237-
26838354296F460B00CCF60A /* GenerateAllVariationsPresenter.swift in Sources */,
10237+
26838354296F460B00CCF60A /* GenerateVariationsOptionPresenter.swift in Sources */,
1023810238
31FC8CE727B47591004B9456 /* CardReaderSettingsDataSource.swift in Sources */,
1023910239
02B2829027C352DA004A332A /* RefreshableScrollView.swift in Sources */,
1024010240
DE7842F726F2E9340030C792 /* UIViewController+Connectivity.swift in Sources */,

0 commit comments

Comments
 (0)