Skip to content

Commit 25a6085

Browse files
committed
POS Modularization: Complete remaining file updates
- Move WooAnalyticsEventPropertyType to WooFoundationCore - Update DefaultConnectivityObserver and tests in WooFoundation - Update authentication and POS utility files with proper imports - Complete final import updates across remaining files
1 parent db81fe3 commit 25a6085

File tree

8 files changed

+40
-51
lines changed

8 files changed

+40
-51
lines changed

Modules/Sources/WooFoundation/Protocols/Analytics/WooAnalyticsEventPropertyType.swift

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

Modules/Sources/WooFoundation/Utilities/Connectivity/DefaultConnectivityObserver.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import Combine
22
import Network
33

4-
final class DefaultConnectivityObserver: ConnectivityObserver {
4+
public final class DefaultConnectivityObserver: ConnectivityObserver {
55

66
/// Network monitor to evaluate connection.
77
///
88
private let networkMonitor: NetworkMonitoring
99
private let observingQueue: DispatchQueue = .global(qos: .background)
1010

11-
@Published private(set) var currentStatus: ConnectivityStatus = .unknown
11+
@Published private(set) public var currentStatus: ConnectivityStatus = .unknown
1212

13-
var statusPublisher: AnyPublisher<ConnectivityStatus, Never> {
13+
public var statusPublisher: AnyPublisher<ConnectivityStatus, Never> {
1414
$currentStatus.eraseToAnyPublisher()
1515
}
1616

17+
public convenience init() {
18+
self.init(networkMonitor: NWPathMonitor())
19+
}
20+
1721
init(networkMonitor: NetworkMonitoring = NWPathMonitor()) {
1822
self.networkMonitor = networkMonitor
1923
startObserving()
@@ -25,11 +29,11 @@ final class DefaultConnectivityObserver: ConnectivityObserver {
2529
}
2630
}
2731

28-
func startObserving() {
32+
public func startObserving() {
2933
networkMonitor.start(queue: observingQueue)
3034
}
3135

32-
func stopObserving() {
36+
public func stopObserving() {
3337
networkMonitor.cancel()
3438
}
3539

Modules/Tests/WooFoundationTests/Utilities/DefaultConnectivityObserverTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Combine
22
import Network
33
import XCTest
4-
@testable import WooCommerce
4+
@testable import WooFoundation
55

66
final class DefaultConnectivityObserverTests: XCTestCase {
77
private var subscriptions: Set<AnyCancellable> = []

Modules/Tests/WooFoundationTests/Utilities/VersionHelpersTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Testing
22
import WooFoundationCore
3-
@testable import WooCommerce
3+
@testable import WooFoundation
44

55
/// VersionHelpers Unit Tests
66
///

WooCommerce/Classes/Authentication/Jetpack Setup/Native Jetpack Setup/JetpackSetupInterruptedView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SwiftUI
2+
import struct WooFoundation.ScrollableVStack
23

34
/// View to be displayed when the Jetpack connection flow is dismissed.
45
/// This screen is used only in the Jetpack setup flow for non-JCP sites.

WooCommerce/Classes/POS/TabBar/POSIneligibleView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct POSIneligibleView: View {
77
let onRefresh: () async throws -> Void
88
@Environment(\.dismiss) private var dismiss
99
@Environment(\.sizeCategory) private var sizeCategory
10+
@Environment(\.posAnalytics) private var analytics
1011
@State private var isLoading: Bool = false
1112
@State private var scrollViewHeight: CGFloat = 0
1213
@State private var contentHeight: CGFloat = 0
@@ -59,7 +60,7 @@ struct POSIneligibleView: View {
5960
Task { @MainActor in
6061
do {
6162
isLoading = true
62-
ServiceLocator.analytics.track(
63+
analytics.track(
6364
event: .PointOfSaleIneligibleUI.ineligibleUIRetryTapped(reason: reason)
6465
)
6566
try await onRefresh()
@@ -95,10 +96,10 @@ struct POSIneligibleView: View {
9596
contentHeight = height
9697
}
9798
.onAppear {
98-
ServiceLocator.analytics.track(event: .PointOfSaleIneligibleUI.ineligibleUIShown(reason: reason))
99+
analytics.track(event: .PointOfSaleIneligibleUI.ineligibleUIShown(reason: reason))
99100
}
100101
.onChange(of: reason) { _, newReason in
101-
ServiceLocator.analytics.track(event: .PointOfSaleIneligibleUI.ineligibleUIShown(reason: newReason))
102+
analytics.track(event: .PointOfSaleIneligibleUI.ineligibleUIShown(reason: newReason))
102103
}
103104
}
104105
.scrollDisabled(shouldDisableScrolling)

WooCommerce/Classes/POS/Utils/POSReceiptSender.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import struct Yosemite.Order
88
import enum Yosemite.Plugin
99
import protocol WooFoundation.Analytics
1010
import class Yosemite.PluginsService
11+
import WooFoundationCore
1112

1213
protocol POSReceiptSending {
1314
func sendReceipt(orderID: Int64, recipientEmail: String) async throws
@@ -17,9 +18,10 @@ final class POSReceiptSender: POSReceiptSending {
1718
init(siteID: Int64,
1819
orderService: POSOrderServiceProtocol,
1920
receiptService: POSReceiptServiceProtocol,
20-
analytics: Analytics = ServiceLocator.analytics,
21-
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService,
22-
pluginsService: PluginsServiceProtocol = PluginsService(storageManager: ServiceLocator.storageManager)) {
21+
analytics: POSAnalyticsProviding,
22+
featureFlagService: POSFeatureFlagProviding,
23+
pluginsService: PluginsServiceProtocol
24+
) {
2325
self.siteID = siteID
2426
self.orderService = orderService
2527
self.receiptService = receiptService
@@ -31,8 +33,8 @@ final class POSReceiptSender: POSReceiptSending {
3133
private let siteID: Int64
3234
private let orderService: POSOrderServiceProtocol
3335
private let receiptService: POSReceiptServiceProtocol
34-
private let analytics: Analytics
35-
private let featureFlagService: FeatureFlagService
36+
private let analytics: POSAnalyticsProviding
37+
private let featureFlagService: POSFeatureFlagProviding
3638
private let pluginsService: PluginsServiceProtocol
3739

3840
@MainActor
@@ -59,12 +61,12 @@ final class POSReceiptSender: POSReceiptSending {
5961

6062
try await receiptService.sendReceipt(orderID: orderID, recipientEmail: recipientEmail, isEligibleForPOSReceipt: posReceiptEligibility)
6163

62-
analytics.track(.receiptEmailSuccess, withProperties: ["eligible_for_pos_receipt": posReceiptEligibility])
64+
analytics.track(.receiptEmailSuccess, parameters: ["eligible_for_pos_receipt": posReceiptEligibility])
6365
} catch {
6466
let properties = [
6567
"eligible_for_pos_receipt": isEligibleForPOSReceipt
6668
].compactMapValues( { $0 })
67-
analytics.track(.receiptEmailFailed, properties: properties, error: error)
69+
analytics.track(.receiptEmailFailed, parameters: properties, error: error)
6870
throw error
6971
}
7072
}

WooCommerce/Classes/POS/Utils/PreviewHelpers.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,21 @@ struct POSPreviewHelpers {
219219
collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking = POSCollectOrderPaymentPreviewAnalytics(),
220220
searchHistoryService: POSSearchHistoryProviding = PointOfSalePreviewHistoryService(),
221221
popularItemsController: PointOfSaleItemsControllerProtocol = PointOfSalePreviewItemsController(),
222-
barcodeScanService: PointOfSaleBarcodeScanServiceProtocol = PointOfSalePreviewBarcodeScanService()
222+
barcodeScanService: PointOfSaleBarcodeScanServiceProtocol = PointOfSalePreviewBarcodeScanService(),
223+
analytics: POSAnalyticsProviding = EmptyPOSAnalytics(),
224+
featureFlags: POSFeatureFlagProviding = EmptyPOSFeatureFlags()
223225
) -> PointOfSaleAggregateModel {
224226
return PointOfSaleAggregateModel(
225-
entryPointController: POSEntryPointController(eligibilityChecker: LegacyPOSTabEligibilityChecker(siteID: 0)),
227+
entryPointController: POSEntryPointController(eligibilityChecker: LegacyPOSTabEligibilityChecker(siteID: 0),
228+
featureFlagService: featureFlags),
226229
itemsController: itemsController,
227230
purchasableItemsSearchController: purchasableItemsSearchController,
228231
couponsController: couponsController,
229232
couponsSearchController: couponsSearchController,
230233
cardPresentPaymentService: cardPresentPaymentService,
231234
orderController: orderController,
232235
settingsController: settingsController,
236+
analytics: analytics,
233237
collectOrderPaymentAnalyticsTracker: collectOrderPaymentAnalyticsTracker,
234238
searchHistoryService: searchHistoryService,
235239
popularPurchasableItemsController: popularItemsController,
@@ -435,4 +439,13 @@ final class POSCollectOrderPaymentPreviewAnalytics: POSCollectOrderPaymentAnalyt
435439
func trackReceiptPrintFailed(error: any Error) {}
436440
}
437441

442+
final class POSPreviewServices: POSDependencyProviding {
443+
var analytics: POSAnalyticsProviding = EmptyPOSAnalytics()
444+
var currency: POSCurrencySettingsProviding = EmptyPOSCurrencySettings()
445+
var featureFlags: POSFeatureFlagProviding = EmptyPOSFeatureFlags()
446+
var connectivity: POSConnectivityProviding = EmptyPOSConnectivityProvider()
447+
var externalNavigation: POSExternalNavigationProviding = EmptyPOSExternalNavigation()
448+
var externalViews: POSExternalViewProviding = EmptyPOSExternalView()
449+
}
450+
438451
#endif

0 commit comments

Comments
 (0)