Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ struct BookableProductListSyncable: ListSyncable {

let title = Localization.title

let emptyStateMessage = Localization.noMembersFound
let emptyStateMessage = Localization.noServiceFound
let emptyItemTitlePlaceholder: String? = nil

let searchConfiguration: ListSearchConfiguration? = nil
let searchConfiguration: ListSearchConfiguration? = ListSearchConfiguration(
searchPrompt: Localization.searchPrompt,
emptySearchTitle: Localization.noServiceFound,
emptySearchDescription: Localization.emptySearchDescription
)

let selectionDisabledMessage: String? = nil

Expand Down Expand Up @@ -53,7 +57,19 @@ struct BookableProductListSyncable: ListSyncable {

/// Creates the action to search items with keyword
func createSearchAction(keyword: String, pageNumber: Int, pageSize: Int, completion: @escaping (Result<Bool, Error>) -> Void) -> Action {
fatalError("Searching is not supported")
ProductAction.searchProducts(
siteID: siteID,
keyword: keyword,
pageNumber: pageNumber,
pageSize: pageSize,
productType: .booking,
onCompletion: completion
)
}

/// Creates the predicate for filtering search results
func createSearchPredicate(keyword: String) -> NSPredicate? {
NSPredicate(format: "SUBQUERY(searchResults, $result, $result.keyword = %@).@count > 0", keyword)
}

// MARK: - Display Configuration
Expand All @@ -79,10 +95,20 @@ private extension BookableProductListSyncable {
value: "Service / Event",
comment: "Title of the booking service/event selector view"
)
static let noMembersFound = NSLocalizedString(
static let noServiceFound = NSLocalizedString(
"bookingServiceEventSelectorView.noMembersFound",
value: "No service or event found",
comment: "Text on the empty view of the booking service/event selector view"
)
static let searchPrompt = NSLocalizedString(
"bookingServiceEventSelectorView.searchPrompt",
value: "Search service / event",
comment: "Prompt in the search bar of the booking service/event selector view"
)
static let emptySearchDescription = NSLocalizedString(
"bookingServiceEventSelectorView.emptySearchDescription",
value: "Try adjusting your search term to see more results",
comment: "Message on the empty search result view of the booking service/event selector view"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ struct CustomerListSyncable: ListSyncable {
)
}

/// Creates the predicate for filtering search results
/// - Returns: nil because customer search handles filtering directly
func createSearchPredicate(keyword: String) -> NSPredicate? {
nil
}

// MARK: - Display Configuration

func displayName(for item: Customer) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ protocol ListSyncable {
/// Creates the action to search items with keyword
func createSearchAction(keyword: String, pageNumber: Int, pageSize: Int, completion: @escaping (Result<Bool, Error>) -> Void) -> Action

/// Creates the predicate for filtering search results
/// - Parameter keyword: The search keyword
/// - Returns: A predicate to filter storage objects by search results, or nil if search predicate is not needed
func createSearchPredicate(keyword: String) -> NSPredicate?

// MARK: - Display Configuration

/// Returns the display name for an item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ private extension SyncableListSelectorView {
}
)
.renderedIf(viewModel.searchQuery.isEmpty)
.listRowSeparator(.hidden, edges: .top)

ForEach(items, id: \.self) { item in
ForEach(Array(items.enumerated()), id: \.element) { (index, item) in
optionRow(text: syncable.displayName(for: item),
description: syncable.description(for: item),
isSelected: selectedItems.contains(where: { $0 == syncable.filterItem(for: item) }),
onSelection: { toggleSelectionIfPossible(for: item) })
.if(index == 0 && viewModel.searchQuery.isNotEmpty) {
$0.listRowSeparator(.hidden, edges: .top)
}
}

InfiniteScrollIndicator(showContent: viewModel.shouldShowBottomActivityIndicator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ final class SyncableListSelectorViewModel<Syncable: ListSyncable>: ObservableObj

/// Handles search query changes by resetting pagination and triggering new search
private func handleSearchQueryChange(_ query: String) {
syncState = .syncingFirstPage
currentSearchKeyword = query

// Update the predicate to filter by search results if needed
var predicates = [syncable.createPredicate()]
if !query.isEmpty, let searchPredicate = syncable.createSearchPredicate(keyword: query) {
predicates.append(searchPredicate)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good and readable. How about making it shorter?

var predicates = [syncable.createPredicate()]
if !query.isEmpty, let searchPredicate = syncable.createSearchPredicate(keyword: query) {
    predicates.append(searchPredicate)
}
resultsController.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better - done in ebae5bf.

resultsController.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)

paginationTracker.syncFirstPage()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ struct TeamMemberListSyncable: ListSyncable {
fatalError("Searching is not supported")
}

/// Creates the predicate for filtering search results
/// - Returns: nil because searching is not supported for team members
func createSearchPredicate(keyword: String) -> NSPredicate? {
nil
}

// MARK: - Display Configuration

func displayName(for item: BookingResource) -> String {
Expand Down
4 changes: 4 additions & 0 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,7 @@
DE8AA0B32BBE55E40084D2CC /* DashboardViewHostingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8AA0B22BBE55E40084D2CC /* DashboardViewHostingController.swift */; };
DE8AA0B52BBEBE590084D2CC /* ViewControllerContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8AA0B42BBEBE590084D2CC /* ViewControllerContainer.swift */; };
DE8C22732EB0AE8500C69F35 /* MultiSelectListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C22722EB0AE8500C69F35 /* MultiSelectListView.swift */; };
DE8C3A002EB3527300C69F35 /* SyncableListSelectorViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C39FF2EB3527300C69F35 /* SyncableListSelectorViewModelTests.swift */; };
DE8C63AE2E1E2D2D00DA48AC /* OrderDetailsShipmentDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C63AD2E1E2D1400DA48AC /* OrderDetailsShipmentDetailsView.swift */; };
DE8C946E264699B600C94823 /* PluginListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C946D264699B600C94823 /* PluginListViewModel.swift */; };
DE96844B2A331AD2000FBF4E /* WooAnalyticsEvent+ProductSharingAI.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE96844A2A331AD2000FBF4E /* WooAnalyticsEvent+ProductSharingAI.swift */; };
Expand Down Expand Up @@ -5403,6 +5404,7 @@
DE8AA0B22BBE55E40084D2CC /* DashboardViewHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardViewHostingController.swift; sourceTree = "<group>"; };
DE8AA0B42BBEBE590084D2CC /* ViewControllerContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewControllerContainer.swift; sourceTree = "<group>"; };
DE8C22722EB0AE8500C69F35 /* MultiSelectListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiSelectListView.swift; sourceTree = "<group>"; };
DE8C39FF2EB3527300C69F35 /* SyncableListSelectorViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncableListSelectorViewModelTests.swift; sourceTree = "<group>"; };
DE8C63AD2E1E2D1400DA48AC /* OrderDetailsShipmentDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderDetailsShipmentDetailsView.swift; sourceTree = "<group>"; };
DE8C946D264699B600C94823 /* PluginListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginListViewModel.swift; sourceTree = "<group>"; };
DE96844A2A331AD2000FBF4E /* WooAnalyticsEvent+ProductSharingAI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+ProductSharingAI.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12530,6 +12532,7 @@
DED1E3162E8556270089909C /* Bookings */ = {
isa = PBXGroup;
children = (
DE8C39FF2EB3527300C69F35 /* SyncableListSelectorViewModelTests.swift */,
DE49CD212E966814006DCB07 /* BookingSearchViewModelTests.swift */,
DED1E3152E8556270089909C /* BookingListViewModelTests.swift */,
2D054A292E953E3C004111FD /* BookingDetailsViewModelTests.swift */,
Expand Down Expand Up @@ -16037,6 +16040,7 @@
746FC23D2200A62B00C3096C /* DateWooTests.swift in Sources */,
DEF8CF1129A8933E00800A60 /* JetpackBenefitsViewModelTests.swift in Sources */,
31F21B5A263CB41A0035B50A /* MockCardPresentPaymentsStoresManager.swift in Sources */,
DE8C3A002EB3527300C69F35 /* SyncableListSelectorViewModelTests.swift in Sources */,
86F0896F2B307D7E00D668A1 /* ThemesPreviewViewModelTests.swift in Sources */,
CC3B35DF28E5BE6F0036B097 /* ReviewReplyViewModelTests.swift in Sources */,
DEE215322D116FBB004A11F3 /* EditStoreListViewModelTests.swift in Sources */,
Expand Down
Loading