Skip to content

Commit a0c8e18

Browse files
committed
Show the selected period on snapshot stats detail screens
The Referrer, External Link, and Archive detail screens display a range-scoped views total, but nothing on screen states which period the number covers; the date range is frozen at push time and these screens have no fetch path, so they cannot host the interactive date range control. Add an optional dateInterval to StandaloneMetricView (used only by these three screens) that renders the formatted period as a secondary line under the value. The ReferrerStatsView preview mock now uses .last7Days so the preview exercises a date-style period label instead of a bare year. Part of CMM-2319.
1 parent 654a54a commit a0c8e18

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

Modules/Sources/JetpackStats/Screens/ArchiveStatsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct ArchiveStatsView: View {
4545
Spacer()
4646

4747
if let totalViews = archiveSection.metrics.views {
48-
StandaloneMetricView(metric: .views, value: totalViews)
48+
StandaloneMetricView(metric: .views, value: totalViews, dateInterval: dateRange.dateInterval)
4949
}
5050
}
5151
}

Modules/Sources/JetpackStats/Screens/ExternalLinkStatsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct ExternalLinkStatsView: View {
101101
@ViewBuilder
102102
var viewsCount: some View {
103103
if let views = externalLink.metrics.views {
104-
StandaloneMetricView(metric: .views, value: views)
104+
StandaloneMetricView(metric: .views, value: views, dateInterval: dateRange.dateInterval)
105105
}
106106
}
107107

Modules/Sources/JetpackStats/Screens/ReferrerStatsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct ReferrerStatsView: View {
122122
@ViewBuilder
123123
var viewsCount: some View {
124124
if let views = referrer.metrics.views {
125-
StandaloneMetricView(metric: .views, value: views)
125+
StandaloneMetricView(metric: .views, value: views, dateInterval: dateRange.dateInterval)
126126
}
127127
}
128128

@@ -203,7 +203,7 @@ struct ReferrerStatsView: View {
203203
NavigationView {
204204
ReferrerStatsView(
205205
referrer: .mock,
206-
dateRange: Calendar.demo.makeDateRange(for: .thisYear)
206+
dateRange: Calendar.demo.makeDateRange(for: .last7Days)
207207
)
208208
}
209209
.navigationViewStyle(.stack)

Modules/Sources/JetpackStats/Views/StandaloneMetricView.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import DesignSystem
44
struct StandaloneMetricView: View {
55
let metric: SiteMetric
66
let value: Int
7+
var dateInterval: DateInterval?
8+
9+
@Environment(\.context) private var context
710

811
var body: some View {
912
VStack(alignment: .trailing, spacing: 0) {
@@ -15,11 +18,23 @@ struct StandaloneMetricView: View {
1518
.font(Constants.Typography.smallDisplayFont)
1619
.foregroundColor(.primary)
1720
.contentTransition(.numericText())
21+
if let dateInterval {
22+
Text(context.formatters.dateRange.string(from: dateInterval))
23+
.font(.footnote)
24+
.foregroundColor(.secondary)
25+
}
1826
}
1927
}
2028
}
2129

2230
#Preview {
23-
StandaloneMetricView(metric: .views, value: 12345)
24-
.padding()
31+
VStack(spacing: 32) {
32+
StandaloneMetricView(metric: .views, value: 12345)
33+
StandaloneMetricView(
34+
metric: .views,
35+
value: 12345,
36+
dateInterval: Calendar.demo.makeDateRange(for: .last7Days).dateInterval
37+
)
38+
}
39+
.padding()
2540
}

0 commit comments

Comments
 (0)