From c378ad1d88ec243cc9050bc5c76568195e2805e2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 5 Jul 2023 11:50:13 +0200 Subject: [PATCH] Add "no results found" container --- app/views/admin/products_v3/_content.html.haml | 7 +------ app/views/admin/products_v3/_no_products.html.haml | 11 +++++++++++ config/locales/en.yml | 2 ++ spec/system/admin/products_v3/products_spec.rb | 8 ++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/products_v3/_no_products.html.haml diff --git a/app/views/admin/products_v3/_content.html.haml b/app/views/admin/products_v3/_content.html.haml index beb3942621..b598120c14 100644 --- a/app/views/admin/products_v3/_content.html.haml +++ b/app/views/admin/products_v3/_content.html.haml @@ -14,9 +14,4 @@ = render partial: 'admin/shared/v3/pagy', locals: { pagy: pagy, reflex: "click->Products#fetch" } - else #no-products - = t('.no_products_found') - #no-products-actions - %a{ href: "/admin/products/new", class: "button icon-plus", icon: "icon-plus" } - = t(:new_product) - %a{ href: "/admin/products/import", class: "button icon-upload secondary", icon: "icon-upload" } - = t(".import_products") + = render partial: "no_products", locals: { search_term: search_term, producer_id: producer_id, category_id: category_id } diff --git a/app/views/admin/products_v3/_no_products.html.haml b/app/views/admin/products_v3/_no_products.html.haml new file mode 100644 index 0000000000..7b0bbb328c --- /dev/null +++ b/app/views/admin/products_v3/_no_products.html.haml @@ -0,0 +1,11 @@ +- if search_term.present? || producer_id.present? || category_id.present? + = t('.no_products_found_for_search') + %a{ href: "#", class: "button disruptive", data: { reflex: "click->products#clear_search" } } + = t("admin.products_v3.sort.pagination.clear_search") +- else + = t('.no_products_found') + #no-products-actions + %a{ href: "/admin/products/new", class: "button icon-plus", icon: "icon-plus" } + = t(:new_product) + %a{ href: "/admin/products/import", class: "button icon-upload secondary", icon: "icon-upload" } + = t(".import_products") diff --git a/config/locales/en.yml b/config/locales/en.yml index 7c27aea2c6..682e090f86 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -784,8 +784,10 @@ en: label: Categories search: Search content: + no_products: no_products_found: No products found import_products: Import multiple products + no_products_found_for_search: No products found for your search criteria product_import: title: Product Import file_not_found: File not found or could not be opened diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 6b8dbfb592..f7b521ec27 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -131,6 +131,14 @@ describe 'As an admin, I can see the new product page' do expect_products_count_to_be 15 end end + + context "no results" do + it "shows a message when there are no results" do + search_for "no results" + expect(page).to have_content "No products found for your search criteria" + expect(page).to have_link "Clear search" + end + end end def expect_page_to_be(page)