Skip to content

Commit bd8b367

Browse files
committed
Remove ServiceLocator dependency in new features
1 parent cbce231 commit bd8b367

File tree

11 files changed

+21
-173
lines changed

11 files changed

+21
-173
lines changed

WooCommerce/Classes/POS/Adaptors/POSServiceLocatorAdaptor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ private struct POSExternalNavigationAdaptor: POSExternalNavigationProviding {
7777
}
7878

7979
private struct POSExternalViewAdaptor: POSExternalViewProviding {
80-
func createSupportFormView(isPresented: Binding<Bool>) -> AnyView {
80+
func createSupportFormView(isPresented: Binding<Bool>, sourceTag: String) -> AnyView {
8181
AnyView(
8282
SupportForm(isPresented: isPresented,
83-
viewModel: SupportFormViewModel(sourceTag: "pos",
83+
viewModel: SupportFormViewModel(sourceTag: sourceTag,
8484
defaultSite: ServiceLocator.stores.sessionManager.defaultSite))
8585
)
8686
}

WooCommerce/Classes/POS/Analytics/POSCollectOrderPaymentAnalytics.swift

Lines changed: 0 additions & 152 deletions
This file was deleted.

WooCommerce/Classes/POS/Models/PointOfSaleSettingsController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ protocol PointOfSaleSettingsControllerProtocol {
2323
settingsService: PointOfSaleSettingsServiceProtocol,
2424
cardPresentPaymentService: CardPresentPaymentFacade,
2525
pluginsService: PluginsServiceProtocol,
26-
defaultSiteName: String? = ServiceLocator.stores.sessionManager.defaultSite?.name,
27-
siteSettings: [SiteSetting] = ServiceLocator.selectedSiteSettings.siteSettings) {
26+
defaultSiteName: String?,
27+
siteSettings: [SiteSetting]) {
2828
self.storeViewModel = POSSettingsStoreViewModel(siteID: siteID,
2929
settingsService: settingsService,
3030
pluginsService: pluginsService,

WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import WooFoundation
44

55
struct PointOfSaleCollectCashView: View {
66
@Environment(\.dynamicTypeSize) var dynamicTypeSize
7+
@Environment(\.posAnalytics) var analytics
78
@Environment(\.floatingControlAreaSize) private var floatingControlAreaSize: CGSize
89
@Environment(PointOfSaleAggregateModel.self) private var posModel
910
@FocusState private var isTextFieldFocused: Bool
@@ -136,7 +137,7 @@ struct PointOfSaleCollectCashView: View {
136137

137138
private extension PointOfSaleCollectCashView {
138139
private func submitCashAmount() async {
139-
ServiceLocator.analytics.track(.pointOfSaleCashPaymentTapped)
140+
analytics.track(.pointOfSaleCashPaymentTapped)
140141
isLoading = true
141142
do {
142143
try await markComplete()

WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ struct PointOfSaleDashboardView: View {
191191
private extension PointOfSaleDashboardView {
192192
var supportForm: some View {
193193
NavigationView {
194-
externalViews.createSupportFormView(isPresented: $showSupport)
194+
externalViews.createSupportFormView(isPresented: $showSupport, sourceTag: Constants.supportTag)
195195
.toolbar {
196-
ToolbarItem(placement: .confirmationAction) {
196+
ToolbarItem(placement: .cancellationAction) {
197197
Button(Localization.supportCancel) {
198198
showSupport = false
199199
}
@@ -256,6 +256,7 @@ private extension PointOfSaleDashboardView {
256256
static let floatingControlHorizontalOffset: CGFloat = POSPadding.medium
257257
static let floatingControlVerticalOffset: CGFloat = 0
258258
static let exitPOSSheetMaxWidth: CGFloat = 900.0
259+
static let supportTag = "origin:point-of-sale"
259260
}
260261

261262
enum Localization {

WooCommerce/Classes/POS/Presentation/Settings/PointOfSaleSettingsHelpDetailView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct PointOfSaleSettingsHelpDetailView: View {
44
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
5+
@Environment(\.posExternalViews) private var externalViews
56

67
@State private var showProductRestrictions = false
78
@State private var showDocumentation = false
@@ -174,9 +175,7 @@ private extension PointOfSaleSettingsHelpDetailView {
174175

175176
var supportForm: some View {
176177
NavigationView {
177-
SupportForm(isPresented: $showSupport,
178-
viewModel: SupportFormViewModel(sourceTag: Constants.supportTag,
179-
defaultSite: ServiceLocator.stores.sessionManager.defaultSite))
178+
externalViews.createSupportFormView(isPresented: $showSupport, sourceTag: Constants.supportTag)
180179
.toolbar {
181180
ToolbarItem(placement: .cancellationAction) {
182181
Button(Localization.supportCancel) {

WooCommerce/Classes/POS/Presentation/Settings/PointOfSaleSettingsView.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22

33
struct PointOfSaleSettingsView: View {
44
@Environment(\.dismiss) private var dismiss
5+
@Environment(\.posAnalytics) private var analytics
56
@State private var selection: SidebarNavigation? = .store
67

78
let settingsController: PointOfSaleSettingsControllerProtocol
@@ -27,7 +28,7 @@ extension PointOfSaleSettingsView {
2728
title: Localization.navigationTitle,
2829
backButtonConfiguration: .init(state: .enabled,
2930
action: {
30-
ServiceLocator.analytics.track(.pointOfSaleSettingsCloseButtonTapped)
31+
analytics.track(.pointOfSaleSettingsCloseButtonTapped)
3132
dismiss()
3233
},
3334
buttonIcon: "xmark"))
@@ -39,7 +40,7 @@ extension PointOfSaleSettingsView {
3940
item: .store,
4041
isSelected: selection == .store,
4142
onTap: {
42-
ServiceLocator.analytics.track(.pointOfSaleSettingsStoreDetailsTapped)
43+
analytics.track(.pointOfSaleSettingsStoreDetailsTapped)
4344
selection = .store
4445
}
4546
)
@@ -48,7 +49,7 @@ extension PointOfSaleSettingsView {
4849
item: .hardware,
4950
isSelected: selection == .hardware,
5051
onTap: {
51-
ServiceLocator.analytics.track(.pointOfSaleSettingsHardwareTapped)
52+
analytics.track(.pointOfSaleSettingsHardwareTapped)
5253
selection = .hardware
5354
}
5455
)
@@ -59,7 +60,7 @@ extension PointOfSaleSettingsView {
5960
item: .help,
6061
isSelected: selection == .help,
6162
onTap: {
62-
ServiceLocator.analytics.track(.pointOfSaleSettingsHelpTapped)
63+
analytics.track(.pointOfSaleSettingsHelpTapped)
6364
selection = .help
6465
}
6566
)

WooCommerce/Classes/POS/Protocols/POSDependencyProviding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protocol POSExternalNavigationProviding {
3535

3636
/// Protocol that provides external view creation capabilities for POS
3737
protocol POSExternalViewProviding {
38-
func createSupportFormView(isPresented: Binding<Bool>) -> AnyView
38+
func createSupportFormView(isPresented: Binding<Bool>, sourceTag: String) -> AnyView
3939
}
4040

4141
/// Main protocol that combines all POS dependency providers

WooCommerce/Classes/POS/TabBar/POSTabCoordinator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ private extension POSTabCoordinator {
152152
settingsController: PointOfSaleSettingsController(siteID: siteID,
153153
settingsService: settingsService,
154154
cardPresentPaymentService: cardPresentPaymentService,
155-
pluginsService: pluginsService),
155+
pluginsService: pluginsService,
156+
defaultSiteName: storesManager.sessionManager.defaultSite?.name,
157+
siteSettings: ServiceLocator.selectedSiteSettings.siteSettings),
156158
collectOrderPaymentAnalyticsTracker: collectPaymentAnalyticsAdaptor,
157159
searchHistoryService: POSSearchHistoryService(siteID: siteID),
158160
popularPurchasableItemsController: PointOfSaleItemsController(

WooCommerce/Classes/POS/Utils/POSEnvironmentKeys.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ struct EmptyPOSAnalytics: POSAnalyticsProviding {
121121
}
122122

123123
struct EmptyPOSExternalView: POSExternalViewProviding {
124-
func createSupportFormView(isPresented: Binding<Bool>) -> AnyView { AnyView(EmptyView()) }
124+
func createSupportFormView(isPresented: Binding<Bool>, sourceTag: String) -> AnyView { AnyView(EmptyView()) }
125125
init() {}
126126
}

0 commit comments

Comments
 (0)