-
Notifications
You must be signed in to change notification settings - Fork 121
Bookings: Update selector for service/event and customer name filters #16278
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b8dbe4
Add new view for selecting service/event
itsmeichigo d2fe760
Update customer filter
itsmeichigo ee6b4f6
Move Customer name row down
itsmeichigo fdd478f
Update layout for customer selector rows
itsmeichigo 9e59c70
Hide username for customers in booking filter
itsmeichigo 5d7ed17
Do not dismiss selector views after selection
itsmeichigo fb76687
Update sort descriptors for customers
itsmeichigo b6ed021
Update initial selection logic and remove full product model from Boo…
itsmeichigo 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
13 changes: 8 additions & 5 deletions
13
Modules/Sources/Yosemite/Model/Bookings/BookingProductFilter.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 |
|---|---|---|
| @@ -1,20 +1,23 @@ | ||
| // periphery:ignore:all - will be used for booking filters | ||
| import Foundation | ||
|
|
||
| /// Used to filter bookings by product | ||
| /// | ||
| public struct BookingProductFilter: Codable, Hashable { | ||
| /// The underlying product | ||
| public let product: Product | ||
|
|
||
| /// ID of the product | ||
| /// periphery:ignore - to be used later when applying filter | ||
| /// | ||
| public let id: Int64 | ||
|
|
||
| /// Name of the product | ||
| /// | ||
| public let name: String | ||
|
|
||
| public init(id: Int64, | ||
| name: String) { | ||
| self.id = id | ||
| self.name = name | ||
| public init(product: Product) { | ||
| self.id = product.productID | ||
| self.name = product.name | ||
| self.product = product | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
WooCommerce/Classes/Bookings/BookingFilters/BookableProductListSyncable.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,68 @@ | ||
| import Foundation | ||
| import Yosemite | ||
|
|
||
| /// Syncable implementation for booking services/events (bookable product) filtering | ||
| struct BookableProductListSyncable: ListSyncable { | ||
| typealias StorageType = StorageProduct | ||
| typealias ModelType = Product | ||
|
|
||
| let siteID: Int64 | ||
|
|
||
| var title: String { Localization.title } | ||
|
|
||
| var emptyStateMessage: String { Localization.noMembersFound } | ||
|
|
||
| // MARK: - ResultsController Configuration | ||
|
|
||
| func createPredicate() -> NSPredicate { | ||
| NSPredicate(format: "siteID == %lld AND productTypeKey == %@", siteID, ProductType.booking.rawValue) | ||
| } | ||
|
|
||
| func createSortDescriptors() -> [NSSortDescriptor] { | ||
| [NSSortDescriptor(key: "productID", ascending: false)] | ||
| } | ||
|
|
||
| // MARK: - Sync Configuration | ||
|
|
||
| func createSyncAction( | ||
| pageNumber: Int, | ||
| pageSize: Int, | ||
| completion: @escaping (Result<Bool, Error>) -> Void | ||
| ) -> Action { | ||
| ProductAction.synchronizeProducts( | ||
| siteID: siteID, | ||
| pageNumber: pageNumber, | ||
| pageSize: pageSize, | ||
| stockStatus: nil, | ||
| productStatus: nil, | ||
| productType: .booking, | ||
| productCategory: nil, | ||
| sortOrder: .dateDescending, | ||
| productIDs: [], | ||
| excludedProductIDs: [], | ||
| shouldDeleteStoredProductsOnFirstPage: true, | ||
| onCompletion: completion | ||
| ) | ||
| } | ||
|
|
||
| // MARK: - Display Configuration | ||
|
|
||
| func displayName(for item: Product) -> String { | ||
| item.name | ||
| } | ||
| } | ||
|
|
||
| private extension BookableProductListSyncable { | ||
| enum Localization { | ||
| static let title = NSLocalizedString( | ||
| "bookingServiceEventSelectorView.title", | ||
| value: "Service / Event", | ||
| comment: "Title of the booking service/event selector view" | ||
| ) | ||
| static let noMembersFound = NSLocalizedString( | ||
| "bookingServiceEventSelectorView.noMembersFound", | ||
| value: "No service or event found", | ||
| comment: "Text on the empty view of the booking service/event selector view" | ||
| ) | ||
| } | ||
| } |
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
27 changes: 27 additions & 0 deletions
27
WooCommerce/Classes/Bookings/BookingFilters/CustomerSelector+BookingFilter.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,27 @@ | ||
| import Foundation | ||
|
|
||
| extension CustomerSelectorViewController.Configuration { | ||
| static let configurationForBookingFilter = CustomerSelectorViewController.Configuration( | ||
| title: BookingFilterLocalization.customerSelectorTitle, | ||
| disallowSelectingGuest: true, | ||
| guestDisallowedMessage: BookingFilterLocalization.guestSelectionDisallowedError, | ||
| disallowCreatingCustomer: true, | ||
| showGuestLabel: true, | ||
| shouldTrackCustomerAdded: false, | ||
| isModal: false, | ||
| hideDetailText: true | ||
| ) | ||
|
|
||
| enum BookingFilterLocalization { | ||
| static let customerSelectorTitle = NSLocalizedString( | ||
| "configurationForBookingFilter.customerName", | ||
| value: "Customer name", | ||
| comment: "Title for the screen to select customer in booking filtering." | ||
| ) | ||
| static let guestSelectionDisallowedError = NSLocalizedString( | ||
| "configurationForBookingFilter.guestSelectionDisallowedError", | ||
| value: "This user is a guest, and guests can’t be used for filtering bookings.", | ||
| comment: "Error message when selecting guest customer in booking filtering" | ||
| ) | ||
| } | ||
| } |
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
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.
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.
One small concern — I wonder if we really need to store the entire Product here. Having both product, id, and name feels a bit redundant and might make it easier for other parts of the code to start depending on BookingProductFilter for full product data instead of just treating it as a lightweight filter value.
Would it make sense for this type to only keep the minimal info needed for filtering (e.g. id and name) and drop the product property? That would keep the model focused on its purpose and avoid any unintended coupling later on.
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.
This is a valid point! I added an update in b6ed021 with the following changes:
BookingProductFilter.SyncableListSelectorViewto accept a closure for checking initial selection rather than comparing full models.FilterListViewControllerfollowing the selection logic change.