Skip to content

Commit ff70064

Browse files
authored
Merge pull request #5372 from woocommerce/issue/4385-empty-filter-view
Issue/4385 empty filter view
2 parents a746159 + 6a3f936 commit ff70064

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ public enum WooAnalyticsStat: String {
330330
case productListSearched = "product_list_searched"
331331
case productListMenuSearchTapped = "product_list_menu_search_tapped"
332332
case productListAddProductTapped = "product_list_add_product_button_tapped"
333+
case productListClearFiltersTapped = "product_list_clear_filters_button_tapped"
333334

334335
// MARK: Add Product Events
335336
//

WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ private extension ProductsViewController {
678678
present(filterProductListViewController, animated: true, completion: nil)
679679
}
680680

681+
func clearFilter(sourceBarButtonItem: UIBarButtonItem? = nil, sourceView: UIView? = nil) {
682+
ServiceLocator.analytics.track(.productListClearFiltersTapped)
683+
filters = FilterProductListViewModel.Filters()
684+
}
685+
681686
/// Presents products survey
682687
///
683688
func presentProductsFeedback() {
@@ -728,21 +733,51 @@ private extension ProductsViewController {
728733
///
729734
func displayNoResultsOverlay() {
730735
let emptyStateViewController = EmptyStateViewController(style: .list)
736+
let config = createFilterConfig()
737+
displayEmptyStateViewController(emptyStateViewController)
738+
emptyStateViewController.configure(config)
739+
}
740+
741+
func createFilterConfig() -> EmptyStateViewController.Config {
742+
if filters.numberOfActiveFilters == 0 {
743+
return createNoProductsConfig()
744+
} else {
745+
return createNoProductsMatchFilterConfig()
746+
}
747+
}
748+
749+
/// Creates EmptyStateViewController.Config for no products empty view
750+
///
751+
func createNoProductsConfig() -> EmptyStateViewController.Config {
731752
let message = NSLocalizedString("No products yet",
732753
comment: "The text on the placeholder overlay when there are no products on the Products tab")
733754
let details = NSLocalizedString("Start selling today by adding your first product to the store.",
734755
comment: "The details on the placeholder overlay when there are no products on the Products tab")
735756
let buttonTitle = NSLocalizedString("Add Product",
736757
comment: "Action to add product on the placeholder overlay when there are no products on the Products tab")
737-
let config = EmptyStateViewController.Config.withButton(
758+
return EmptyStateViewController.Config.withButton(
738759
message: .init(string: message),
739760
image: .emptyProductsTabImage,
740761
details: details,
741762
buttonTitle: buttonTitle) { [weak self] button in
742763
self?.addProduct(sourceView: button)
743764
}
744-
displayEmptyStateViewController(emptyStateViewController)
745-
emptyStateViewController.configure(config)
765+
}
766+
767+
/// Creates EmptyStateViewController.Config for no products match the filter empty view
768+
///
769+
func createNoProductsMatchFilterConfig() -> EmptyStateViewController.Config {
770+
let message = NSLocalizedString("No matching products found",
771+
comment: "The text on the placeholder overlay when no products match the filter on the Products tab")
772+
let buttonTitle = NSLocalizedString("Clear Filters",
773+
comment: "Action to add product on the placeholder overlay when no products match the filter on the Products tab")
774+
return EmptyStateViewController.Config.withButton(
775+
message: .init(string: message),
776+
image: .emptyProductsTabImage,
777+
details: "",
778+
buttonTitle: buttonTitle) { [weak self] button in
779+
self?.clearFilter(sourceView: button)
780+
}
746781
}
747782

748783
/// Shows the EmptyStateViewController as a child view controller.

0 commit comments

Comments
 (0)