Skip to content

Commit 3c3e38c

Browse files
authored
Merge pull request #8422 from woocommerce/issue/8367-hide-session-card
[Analytics Hub] Hide Sessions card conditionally
2 parents fd26e26 + 20569e9 commit 3c3e38c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct AnalyticsHubView: View {
113113

114114
Divider()
115115
}
116-
.renderedIf(ServiceLocator.featureFlagService.isFeatureFlagEnabled(.analyticsHub))
116+
.renderedIf(ServiceLocator.featureFlagService.isFeatureFlagEnabled(.analyticsHub) && viewModel.showSessionsCard)
117117

118118
Spacer()
119119
}

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ final class AnalyticsHubViewModel: ObservableObject {
5353
///
5454
@Published var sessionsCard = AnalyticsHubViewModel.sessionsCard(currentPeriodStats: nil, siteStats: nil)
5555

56+
/// Sessions Card display state
57+
///
58+
var showSessionsCard: Bool {
59+
switch timeRangeSelectionType {
60+
case .custom:
61+
return false
62+
default:
63+
return true
64+
}
65+
}
66+
5667
/// Time Range Selection Type
5768
///
5869
@Published var timeRangeSelectionType: AnalyticsHubTimeRangeSelection.SelectionType

WooCommerce/WooCommerceTests/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModelTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,22 @@ final class AnalyticsHubViewModelTests: XCTestCase {
118118
XCTAssertEqual(loadingItemsSoldCard?.isRedacted, true)
119119
XCTAssertEqual(loadingSessionsCard?.isRedacted, true)
120120
}
121+
122+
func test_session_card_is_hidden_for_custom_range() async {
123+
// Given
124+
let vm = AnalyticsHubViewModel(siteID: 123, statsTimeRange: .today, usageTracksEventEmitter: eventEmitter, stores: stores)
125+
XCTAssertTrue(vm.showSessionsCard)
126+
127+
// When
128+
vm.timeRangeSelectionType = .custom(start: Date(), end: Date())
129+
130+
// Then
131+
XCTAssertFalse(vm.showSessionsCard)
132+
133+
// When
134+
vm.timeRangeSelectionType = .lastMonth
135+
136+
// Then
137+
XCTAssertTrue(vm.showSessionsCard)
138+
}
121139
}

0 commit comments

Comments
 (0)