Skip to content

Conversation

@iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Oct 13, 2022

Part of: #7741

Description

This PR updates the Network's Customer and WCAnalyticsCustomer entities with a siteID parameter. Then adds support for upserting Customer and CustomerSearchResults to Storage.

Changes

  • Networking: Adds siteID to Customer and WCAnalyticsCustomer models.
  • Yosemite: Adds upsertCustomer and upsertSearchCustomerResult methods to CustomerStore + Unit Tests
  • Storage: Adds Customer+ReadOnlyConvertible
  • Storage: Adds necessary StorageType+Extensions + Unit Tests

Testing instructions

  1. Confirm that Unit Tests pass.
  2. The current implementation assumes that you have at least one customer in your store, and that customer name contains the word "hello", if that's not the case, you can change this to the keyword you prefer:

keyword: "hello") { result in
switch result {
case .success(let customers):
let storage = ServiceLocator.storageManager
guard let result = storage.viewStorage.loadCustomerSearchResult(siteID: self.siteID, keyword: "hello") else {

  1. Go to "Orders" > "+" > "Create new Order" > "+ "Add Customer" and tap in the "Magnifying glass" icon at the top of the screen:

  1. You should see your siteID, the keyword used, and the number of Customers inserted to Storage, as well as the CustomerSearchResults in the console. Similar to:
Site ID: 121710041, keyword: hello, Customers: Optional(2)
Customer: 4,
Name: Optional("hello") Optional("merch")
Customer: 5,
Name: Optional("Hello") Optional("maldon")

@iamgabrielma iamgabrielma mentioned this pull request Oct 13, 2022
15 tasks
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 13, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr7848-0a79129 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@iamgabrielma iamgabrielma added type: enhancement A request for an enhancement. category: parity Match what's supported by the other platform. feature: order creation All tasks related to creating an order labels Oct 13, 2022
@iamgabrielma iamgabrielma added this to the 10.8 milestone Oct 13, 2022
@spencertransier spencertransier modified the milestones: 10.8, 10.9 Oct 15, 2022
@iamgabrielma iamgabrielma marked this pull request as ready for review October 18, 2022 07:58
@iamgabrielma iamgabrielma requested a review from Ecarrion October 20, 2022 04:40
@rachelmcr rachelmcr self-assigned this Oct 20, 2022
Copy link
Contributor

@rachelmcr rachelmcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding a siteID property to WCAnalyticsCustomer? I followed how the changes to Customer support upserting everything to storage, but I don't see how the changes to WCAnalyticsCustomer fit into that. (I might be missing something here!)

Otherwise, my comments below are mostly just nits. These changes work as expected, and thanks for adding test coverage!

public struct WCAnalyticsCustomer: Codable {
public struct WCAnalyticsCustomer: Codable, GeneratedCopiable, GeneratedFakeable {
/// The siteID for the WCAnalyticsCustomer
public let siteID: Int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding a siteID property to WCAnalyticsCustomer? It's very possible I missed it, but I didn't see where we're using this. It looks like we may only need it for the Customer model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that we're not actively using it at the moment. That said I'd prefer to leave it for consistency with the rest of the models, and at some point we may need to save this to storage directly and siteID will be necessary ( I just haven't reached that point yet :D ). I can always circle back once the feature is completed and remove it if needed 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer to wait to make changes until they're definitely needed, but you have more context about the overall changes needed for this project so I'd say go with what makes most sense for your plans here!

@iamgabrielma
Copy link
Contributor Author

Thanks for review @rachelmcr 🙇 , feedback has been addressed and there was also a conflict with trunk that has been resolved. Ready for another look when you can!

Copy link
Contributor

@rachelmcr rachelmcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a comment about a point where a strong reference to self is being captured implicitly, but once that's resolved this should be good to go.

keyword: String,
readOnlyCustomers: [Networking.Customer],
onCompletion: @escaping () -> Void) {
sharedDerivedStorage.perform {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using self.sharedDerivedStorage in the closure here, it would be good to capture weak self, rather than implicitly capturing a strong reference to self. (Another option is to assign sharedDerivedStorage to a constant in the method before using it, so you don't need a reference to self in the closure.)

public struct WCAnalyticsCustomer: Codable {
public struct WCAnalyticsCustomer: Codable, GeneratedCopiable, GeneratedFakeable {
/// The siteID for the WCAnalyticsCustomer
public let siteID: Int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer to wait to make changes until they're definitely needed, but you have more context about the overall changes needed for this project so I'd say go with what makes most sense for your plans here!

@iamgabrielma iamgabrielma merged commit 8ee3cc5 into trunk Oct 21, 2022
@iamgabrielma iamgabrielma deleted the issue/7741-add-customer-upsert-logic branch October 21, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: parity Match what's supported by the other platform. feature: order creation All tasks related to creating an order type: enhancement A request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants