-
Notifications
You must be signed in to change notification settings - Fork 121
Analytics Hub: Products Card UI #8215
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ed9152
Adds Empty AnalyticsProductCard
Ecarrion d5e7d35
Extract DeltaTag to its own custom view
Ecarrion d9e5827
Adds content for AnalyticsProductCard
Ecarrion aa70ef7
Integrate Product card into main hub view
Ecarrion 78c667f
Adds AnalyticsProductCardViewModel
Ecarrion 5e5e527
Set product card vm from main hub vm
Ecarrion f052ed0
Add safe paddings to product card
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
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
62 changes: 62 additions & 0 deletions
62
WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsProductCard.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,62 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Products Card on the Analytics Hub | ||
| /// | ||
| struct AnalyticsProductCard: View { | ||
|
|
||
| /// Items sold quantity. Needs to be formatted. | ||
| /// | ||
| let itemsSold: String | ||
|
|
||
| /// Delta Tag Value. Needs to be formatted | ||
| let delta: String | ||
|
|
||
| /// Delta Tag background color. | ||
| let deltaBackgroundColor: UIColor | ||
|
|
||
| var body: some View { | ||
| VStack(alignment: .leading) { | ||
|
|
||
| Text(Localization.title) | ||
| .foregroundColor(Color(.text)) | ||
| .footnoteStyle() | ||
|
|
||
| Text(Localization.itemsSold) | ||
| .headlineStyle() | ||
| .padding(.top, Layout.titleSpacing) | ||
| .padding(.bottom, Layout.columnSpacing) | ||
|
|
||
| HStack { | ||
| Text(itemsSold) | ||
| .titleStyle() | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| DeltaTag(value: delta, backgroundColor: deltaBackgroundColor) | ||
| } | ||
| } | ||
| .padding(Layout.cardPadding) | ||
| } | ||
| } | ||
|
|
||
| // MARK: Constants | ||
| private extension AnalyticsProductCard { | ||
| enum Localization { | ||
| static let title = NSLocalizedString("Products", comment: "Title for the products card on the analytics hub screen.").localizedUppercase | ||
| static let itemsSold = NSLocalizedString("Items Sold", comment: "Title for the items sold column on the products card on the analytics hub screen.") | ||
| } | ||
|
|
||
| enum Layout { | ||
| static let titleSpacing: CGFloat = 24 | ||
| static let cardPadding: CGFloat = 16 | ||
| static let columnSpacing: CGFloat = 10 | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // MARK: Previews | ||
| struct AnalyticsProductCardPreviews: PreviewProvider { | ||
| static var previews: some View { | ||
| AnalyticsProductCard(itemsSold: "2,234", delta: "+23%", deltaBackgroundColor: .withColorStudio(.green, shade: .shade50)) | ||
| .previewLayout(.sizeThatFits) | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsProductCardViewModel.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,29 @@ | ||
| import Foundation | ||
| import class UIKit.UIColor | ||
|
|
||
| /// Analytics Hub Product Card ViewModel. | ||
| /// Used to transmit analytics products data. | ||
| /// | ||
| struct AnalyticsProductCardViewModel { | ||
| /// Items Sold Value | ||
| /// | ||
| let itemsSold: String | ||
|
|
||
| /// Items Sold Delta | ||
| /// | ||
| let delta: String | ||
|
|
||
| /// Delta background color. | ||
| /// | ||
| let deltaBackgroundColor: UIColor | ||
| } | ||
|
|
||
| /// Convenience extension to create an `AnalyticsReportCard` from a view model. | ||
| /// | ||
| extension AnalyticsProductCard { | ||
| init(viewModel: AnalyticsProductCardViewModel) { | ||
| self.itemsSold = viewModel.itemsSold | ||
| self.delta = viewModel.delta | ||
| self.deltaBackgroundColor = viewModel.deltaBackgroundColor | ||
| } | ||
| } |
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
44 changes: 44 additions & 0 deletions
44
WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/DeltaTag.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,44 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Reusable tag view. | ||
| /// Useful to indicate growth rates. | ||
| /// | ||
| struct DeltaTag: View { | ||
|
|
||
| /// Value to display. Needs to be already formatted | ||
| /// | ||
| let value: String | ||
|
|
||
| /// Tag color. | ||
| /// | ||
| let backgroundColor: UIColor | ||
|
|
||
| var body: some View { | ||
| Text(value) | ||
| .padding(Layout.backgroundPadding) | ||
| .foregroundColor(Color(.textInverted)) | ||
| .captionStyle() | ||
| .background(Color(backgroundColor)) | ||
| .cornerRadius(Layout.cornerRadius) | ||
| } | ||
| } | ||
|
|
||
| // MARK: Constants | ||
| private extension DeltaTag { | ||
| enum Layout { | ||
| static let backgroundPadding = EdgeInsets(top: 2, leading: 8, bottom: 2, trailing: 8) | ||
| static let cornerRadius: CGFloat = 4.0 | ||
| } | ||
| } | ||
|
|
||
| // MARK: Peviews | ||
| struct DeltaTagPreviews: PreviewProvider { | ||
| static var previews: some View { | ||
| VStack { | ||
| DeltaTag(value: "+3.23%", backgroundColor: .systemGreen) | ||
|
|
||
| DeltaTag(value: "-3.23%", backgroundColor: .systemRed) | ||
| } | ||
| .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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this matches the Figma designs, but I think it makes more sense to use
.calloutStyle()here to match the other cards. Otherwise this card has a strangely different style. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I Initially tried it with
calloutStyle()and it also looked off. I think once we have the product list will look better!