-
Notifications
You must be signed in to change notification settings - Fork 112
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
[Woo POS] Replace POS parent product with variable parent product #14818
[Woo POS] Replace POS parent product with variable parent product #14818
Conversation
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
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.
Looks good! One suggestion in the view inits, but what you have is fine too.
init(parentItem: POSItem, title: String) { | ||
self.parentItem = parentItem | ||
self.parentProduct = parentProduct | ||
self.title = title |
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 much prefer this simplification – when there's so little to pass through, the view's more flexible if we just declare the title compared to passing a whole model object.
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.
Agreed!
ParentProductCardView(name: parentProduct.name, | ||
imageSource: parentProduct.productImageSource, | ||
detailView: { | ||
Text(Localization.variationsAvailable) | ||
.foregroundStyle(Color.posSecondaryText) | ||
.font(.posBodyRegular) | ||
}) |
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.
It would also be fine to make this a VariableParentProductCardView
, and continue to pass through the whole parentProduct
here. Since we have to define the detail view as a closure, it's not quite as nice as the ChildItemList
view above, where we simply pass through title string.
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.
The image + title design seems pretty fixed for parent product types, I think it's nice sharing most of the view except the detail view. However, if the future design has more differences than the detail view, let's move to a separate view per parent product case for sure.
struct ParentProductCardView<DetailView: View>: View { | ||
private let name: String | ||
private let imageSource: String? | ||
private let detailView: DetailView |
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.
If you keep this – I think you can make this a ViewBuilder, so you only call it when it's used not at init time.
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.
Ignore this, the way you've done it is recommended
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.
Thanks for finding the best practice, TIL
Part of #14702
Description
This is a followup of #14807 (comment):
From my understanding, this suggestion is to replace
POSItem
enumparentProduct(POSParentProduct)
case that previously had atype
enum + associated type for each product type with a separate case per parent product type. This change also means that views that are meant to be general like the parent product cardParentProductCardView
and its child itemsChildItemList
cannot depend on one parent product enum case. I originally wanted to make a view model for each view, but as we don't generally use view models in POS anymore, I added the view properties in the view initializer.Key changes include:
Controller and Service Updates:
PointOfSaleItemsController
to handlePOSVariableParentProduct
instead ofPOSParentProduct
in theloadInitialChildItems
method andfetchVariationItems
method. [1] [2] [3]View Updates:
ChildItemList
andItemList
views to usePOSVariableParentProduct
and updated their initializers and property usage accordingly. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Card View Updates:
ParentProductCardView
to acceptname
,imageSource
, and adetailView
closure instead ofPOSParentProduct
. This change simplifies the card view and makes it more flexible. [1] [2] [3]Preview and Mock Updates:
POSVariableParentProduct
structure. [1] [2] [3] [4] [5]Steps to reproduce
Testing information
🗒️ As the variable products support requires WC version 9.6+ which is not publicly released at the time of writing, I'd recommend commenting out L214 in ProductsRemote to include all product types.
Screenshots
Same as in #14807:
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: