-
Notifications
You must be signed in to change notification settings - Fork 121
Analytics Hub: Adds Report Card #8177
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
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
017077d
Adds empty report card class
Ecarrion e094d8a
Adds stats UI components
Ecarrion 0cd8c13
Add common modifiers
Ecarrion ff28904
Extract data into properties
Ecarrion 3b0e986
Move static content to constatns
Ecarrion 1a31d24
Extract growth class into their own type
Ecarrion acb3566
Add proper spacings
Ecarrion a56161f
Replace AnalyticsCard as a template
Ecarrion 8479ba8
Make sure card spawn over the full width
Ecarrion 5e7b991
make report card more configurable
Ecarrion 26604cf
Update template data
Ecarrion 7a49e68
Prefer delta over Growth
Ecarrion 6614415
Update naming
Ecarrion 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
99 changes: 99 additions & 0 deletions
99
WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/StatsCard.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,99 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Resuable report card made for the Analytics Hub. | ||
| /// | ||
| struct AnalyticsReportCard: View { | ||
|
|
||
| let title: String | ||
| let leadingTitle: String | ||
| let leadingValue: String | ||
| let leadingGrowth: String | ||
| let leadingGrowthColor: UIColor | ||
| let trailingTitle: String | ||
| let trailingValue: String | ||
| let trailingGrowth: String | ||
| let trailingGrowthColor: UIColor | ||
|
|
||
| var body: some View { | ||
| VStack(alignment: .leading, spacing: Layout.titleSpacing) { | ||
|
|
||
| Text(title) | ||
| .foregroundColor(Color(.text)) | ||
| .footnoteStyle() | ||
|
|
||
| HStack { | ||
|
|
||
| /// Leading Column | ||
| /// | ||
| VStack(alignment: .leading, spacing: Layout.salesColumnSpacing) { | ||
|
|
||
| Text(leadingTitle) | ||
| .calloutStyle() | ||
|
|
||
| Text(leadingValue) | ||
| .titleStyle() | ||
|
|
||
| GrowthTag(value: leadingGrowth, backgroundColor: leadingGrowthColor) | ||
|
|
||
| } | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| /// Net Sales | ||
Ecarrion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| VStack(alignment: .leading, spacing: Layout.salesColumnSpacing) { | ||
| Text(trailingTitle) | ||
| .calloutStyle() | ||
|
|
||
| Text(trailingValue) | ||
| .titleStyle() | ||
|
|
||
| GrowthTag(value: trailingGrowth, backgroundColor: trailingGrowthColor) | ||
| } | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| } | ||
| } | ||
| .padding(Layout.cardPadding) | ||
| } | ||
| } | ||
|
|
||
| private struct GrowthTag: View { | ||
Ecarrion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let value: String | ||
| let backgroundColor: UIColor | ||
|
|
||
| var body: some View { | ||
| Text(value) | ||
| .padding(AnalyticsReportCard.Layout.growthBackgroundPadding) | ||
| .foregroundColor(Color(.textInverted)) | ||
| .captionStyle() | ||
| .background(Color(backgroundColor)) | ||
| .cornerRadius(AnalyticsReportCard.Layout.growthCornerRadius) | ||
| } | ||
| } | ||
|
|
||
| // MARK: Constants | ||
| private extension AnalyticsReportCard { | ||
| enum Layout { | ||
| static let titleSpacing: CGFloat = 24 | ||
| static let cardPadding: CGFloat = 16 | ||
| static let salesColumnSpacing: CGFloat = 10 | ||
Ecarrion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static let growthBackgroundPadding = EdgeInsets(top: 2, leading: 8, bottom: 2, trailing: 8) | ||
| static let growthCornerRadius: CGFloat = 4.0 | ||
| } | ||
| } | ||
|
|
||
| // MARK: Previews | ||
| struct Previews: PreviewProvider { | ||
| static var previews: some View { | ||
| AnalyticsReportCard(title: "REVENUE", | ||
| leadingTitle: "Total Sales", | ||
| leadingValue: "$3.678", | ||
| leadingGrowth: "+23%", | ||
| leadingGrowthColor: .withColorStudio(.green, shade: .shade40), | ||
| trailingTitle: "Net Sales", | ||
| trailingValue: "$3.232", | ||
| trailingGrowth: "-3%", | ||
| trailingGrowthColor: .withColorStudio(.red, shade: .shade40)) | ||
| .previewLayout(.sizeThatFits) | ||
| } | ||
| } | ||
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
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.