-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Stats Traffic date picker #22400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Stats Traffic date picker #22400
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4719ef5
Add Stats Traffic date picker
9651867
Merge branch 'trunk' into task/22382-stats-traffic-create-date-picker
75908c9
Merge branch 'trunk' into task/22382-stats-traffic-create-date-picker
764294a
Replace Period with StatsPeriodUnit
ae91a77
Fix date period formatting
d6ab761
Integrate date picker
981f7ae
Adjust to designs
49aeae1
Merge branch 'trunk' into task/22382-stats-traffic-create-date-picker
75c15bd
Clean up code formatting
182300d
Add Traffic date picker tracking
a5ded9e
Use site date & existing helpers
b9a1321
Fixed date formatting
0ddf520
Fix date navigation
596d987
Refactor to simplify naming
6f64107
Updated tests
aa34722
Fix code alignment
16eabfb
Adjusted date picker navigation button spacing
18b7d4b
Clean up code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
WordPress/Classes/ViewRelated/Stats/Traffic/StatsTrafficDatePickerView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import SwiftUI | ||
| import DesignSystem | ||
|
|
||
| struct StatsTrafficDatePickerView: View { | ||
| @ObservedObject var viewModel: StatsTrafficDatePickerViewModel | ||
|
|
||
| var body: some View { | ||
| HStack { | ||
| Menu { | ||
| ForEach([StatsPeriodUnit.day, .week, .month, .year], id: \.self) { period in | ||
| Button(period.label, action: { | ||
| viewModel.period = period | ||
| }) | ||
| } | ||
| } label: { | ||
| Text(viewModel.period.label) | ||
| .style(TextStyle.bodySmall(.emphasized)) | ||
| .foregroundColor(Color.DS.Foreground.primary) | ||
| Image(systemName: "chevron.down") | ||
| .font(.system(size: 8)) | ||
| .foregroundColor(Color.DS.Foreground.secondary) | ||
|
|
||
| } | ||
| .menuStyle(.borderlessButton) | ||
| .padding(.vertical, Length.Padding.single) | ||
| .padding(.horizontal, Length.Padding.double) | ||
| .background(Color.DS.Background.secondary) | ||
| .clipShape(RoundedRectangle(cornerRadius: Length.Radius.max)) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: Length.Radius.max) | ||
| .strokeBorder(.clear, lineWidth: 0) | ||
| ) | ||
|
|
||
| Spacer() | ||
|
|
||
| Text(viewModel.formattedCurrentPeriod()) | ||
| .style(TextStyle.bodySmall(.emphasized)) | ||
| .foregroundColor(Color.DS.Foreground.primary) | ||
| .lineLimit(1) | ||
|
|
||
| Spacer().frame(width: Length.Padding.split) | ||
|
|
||
| Button(action: { | ||
| viewModel.goToPreviousPeriod() | ||
| }) { | ||
| Image(systemName: "chevron.left") | ||
| .imageScale(.small) | ||
| .foregroundColor(Color.DS.Foreground.secondary) | ||
| .flipsForRightToLeftLayoutDirection(true) | ||
guarani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| .padding(.trailing, Length.Padding.single) | ||
|
|
||
| let isNextDisabled = !viewModel.isNextPeriodAvailable | ||
| let enabledColor = Color.DS.Foreground.secondary | ||
| let disabledColor = enabledColor.opacity(0.5) | ||
|
|
||
| Button(action: { | ||
guarani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| viewModel.goToNextPeriod() | ||
| }) { | ||
| Image(systemName: "chevron.right") | ||
| .imageScale(.small) | ||
| .foregroundColor(isNextDisabled ? disabledColor : enabledColor) | ||
| .flipsForRightToLeftLayoutDirection(true) | ||
| } | ||
| .disabled(isNextDisabled) | ||
| }.padding(.vertical, Length.Padding.single) | ||
| .padding(.horizontal, Length.Padding.double) | ||
| .background(Color.DS.Background.primary) | ||
| .overlay( | ||
| Rectangle() | ||
| .frame(height: Length.Border.thin) | ||
| .foregroundColor(Color.DS.Foreground.tertiary), | ||
| alignment: .bottom | ||
| ) | ||
| .background(Color.DS.Background.secondary) | ||
| } | ||
| } | ||
|
|
||
| private extension StatsPeriodUnit { | ||
| var label: String { | ||
| switch self { | ||
| case .day: | ||
| return NSLocalizedString("stats.traffic.day", value: "By day", comment: "The label for the option to show Stats Traffic by day.") | ||
| case .week: | ||
| return NSLocalizedString("stats.traffic.week", value: "By week", comment: "The label for the option to show Stats Traffic by week.") | ||
| case .month: | ||
| return NSLocalizedString("stats.traffic.month", value: "By month", comment: "The label for the option to show Stats Traffic by month.") | ||
| case .year: | ||
| return NSLocalizedString("stats.traffic.year", value: "By year", comment: "The label for the option to show Stats Traffic by year.") | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.