From 8e96c5a4765ad9571771dc2781ed8f20251f2d4c Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 30 Nov 2023 10:26:19 +0100 Subject: [PATCH 1/4] Normalize translations across components --- .../solidus_admin/products/index/component.html.erb | 2 +- .../app/components/solidus_admin/products/index/component.rb | 2 +- .../app/components/solidus_admin/products/index/component.yml | 4 ++-- .../components/solidus_admin/promotions/index/component.yml | 2 +- admin/app/components/solidus_admin/users/index/component.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/admin/app/components/solidus_admin/products/index/component.html.erb b/admin/app/components/solidus_admin/products/index/component.html.erb index ab9cb3c6880..1d93b2abd53 100644 --- a/admin/app/components/solidus_admin/products/index/component.html.erb +++ b/admin/app/components/solidus_admin/products/index/component.html.erb @@ -4,7 +4,7 @@ <%= page_header_actions do %> <%= render component("ui/button").new( tag: :a, - text: t('.add_product'), + text: t('.add'), href: spree.new_admin_product_path, icon: "add-line", ) %> diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 61ed95110fd..b8a3648e17d 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -79,7 +79,7 @@ def columns def image_column { col: { class: "w-[72px]" }, - header: tag.span('aria-label': t('.product_image'), role: 'text'), + header: tag.span('aria-label': t('.image'), role: 'text'), data: ->(product) do image = product.gallery.images.first or return diff --git a/admin/app/components/solidus_admin/products/index/component.yml b/admin/app/components/solidus_admin/products/index/component.yml index 4de6e6f3e48..eec0674346d 100644 --- a/admin/app/components/solidus_admin/products/index/component.yml +++ b/admin/app/components/solidus_admin/products/index/component.yml @@ -1,6 +1,6 @@ en: - product_image: 'Image' - add_product: 'Add Product' + image: 'Image' + add: 'Add new' batch_actions: delete: 'Delete' discontinue: 'Discontinue' diff --git a/admin/app/components/solidus_admin/promotions/index/component.yml b/admin/app/components/solidus_admin/promotions/index/component.yml index 6f43121d76f..cdb40f9455b 100644 --- a/admin/app/components/solidus_admin/promotions/index/component.yml +++ b/admin/app/components/solidus_admin/promotions/index/component.yml @@ -1,6 +1,6 @@ en: promotion_image: 'Image' - add: 'Add Promotion' + add: 'Add new' batch_actions: delete: 'Delete' scopes: diff --git a/admin/app/components/solidus_admin/users/index/component.yml b/admin/app/components/solidus_admin/users/index/component.yml index 179e1336f95..6a7fa4eaab4 100644 --- a/admin/app/components/solidus_admin/users/index/component.yml +++ b/admin/app/components/solidus_admin/users/index/component.yml @@ -1,6 +1,6 @@ en: promotion_image: 'Image' - add: 'Add Promotion' + add: 'Add new' batch_actions: delete: 'Delete' discontinue: 'Discontinue' From 83f3e756a3ed1335e0de8ec830344a9b13f9cc64 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 30 Nov 2023 10:42:57 +0100 Subject: [PATCH 2/4] Add a product state for deleted products --- .../solidus_admin/products/status/component.rb | 14 ++++++++++++-- .../solidus_admin/products/status/component.yml | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/admin/app/components/solidus_admin/products/status/component.rb b/admin/app/components/solidus_admin/products/status/component.rb index 190e97779a4..2c7be1885f6 100644 --- a/admin/app/components/solidus_admin/products/status/component.rb +++ b/admin/app/components/solidus_admin/products/status/component.rb @@ -3,11 +3,21 @@ class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent STATUSES = { available: :green, - discontinued: :red + discontinued: :yellow, + deleted: :red, }.freeze def self.from_product(product) - new(status: product.available? ? :available : :discontinued) + status = + if product.deleted? + :deleted + elsif product.discontinued? + :discontinued + else + :available + end + + new(status: status) end def initialize(status:) diff --git a/admin/app/components/solidus_admin/products/status/component.yml b/admin/app/components/solidus_admin/products/status/component.yml index c0f10400804..51e56549a30 100644 --- a/admin/app/components/solidus_admin/products/status/component.yml +++ b/admin/app/components/solidus_admin/products/status/component.yml @@ -1,3 +1,4 @@ en: available: 'Available' discontinued: 'Discontinued' + deleted: 'Deleted' From ef7202797300cad62f96ee8f478c8953ab7cadfb Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 30 Nov 2023 10:43:12 +0100 Subject: [PATCH 3/4] Ensure the products controller can show deleted products --- admin/app/controllers/solidus_admin/products_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb index c82a5ebd1a8..68840063c4b 100644 --- a/admin/app/controllers/solidus_admin/products_controller.rb +++ b/admin/app/controllers/solidus_admin/products_controller.rb @@ -28,7 +28,7 @@ def edit end def show - @product = Spree::Product.friendly.find(params[:id]) + @product = Spree::Product.with_discarded.friendly.find(params[:id]) respond_to do |format| format.html { render component('products/show').new(product: @product) } From f8b6f4fd23159da650c241662b34205140f80048 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 30 Nov 2023 10:42:41 +0100 Subject: [PATCH 4/4] Add scopes to the products/index page --- .../solidus_admin/products/index/component.rb | 4 ++++ .../solidus_admin/products/index/component.yml | 4 ++++ .../controllers/solidus_admin/products_controller.rb | 4 ++++ .../solidus_admin/products/status/component_spec.rb | 2 +- admin/spec/features/products_spec.rb | 11 +++++++---- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index b8a3648e17d..df52184f00e 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -62,6 +62,10 @@ def filters def scopes [ { name: :all, label: t('.scopes.all'), default: true }, + { name: :in_stock, label: t('.scopes.in_stock') }, + { name: :out_of_stock, label: t('.scopes.out_of_stock') }, + { name: :available, label: t('.scopes.available') }, + { name: :discontinued, label: t('.scopes.discontinued') }, { name: :deleted, label: t('.scopes.deleted') }, ] end diff --git a/admin/app/components/solidus_admin/products/index/component.yml b/admin/app/components/solidus_admin/products/index/component.yml index eec0674346d..8ae8270bd25 100644 --- a/admin/app/components/solidus_admin/products/index/component.yml +++ b/admin/app/components/solidus_admin/products/index/component.yml @@ -9,4 +9,8 @@ en: with_deleted: Include deleted scopes: all: All + available: Available + discontinued: Discontinued + in_stock: In stock + out_of_stock: Out of stock deleted: Deleted diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb index 68840063c4b..5479bbe6519 100644 --- a/admin/app/controllers/solidus_admin/products_controller.rb +++ b/admin/app/controllers/solidus_admin/products_controller.rb @@ -6,6 +6,10 @@ class ProductsController < SolidusAdmin::BaseController search_scope(:all, default: true) search_scope(:deleted) { _1.with_discarded.discarded } + search_scope(:discontinued) { _1.where(discontinue_on: ...Time.current) } + search_scope(:available) { _1.available } + search_scope(:in_stock) { _1.where(id: Spree::Variant.in_stock.distinct.select(:product_id)) } + search_scope(:out_of_stock) { _1.where.not(id: Spree::Variant.in_stock.distinct.select(:product_id)) } def index products = apply_search_to( diff --git a/admin/spec/components/solidus_admin/products/status/component_spec.rb b/admin/spec/components/solidus_admin/products/status/component_spec.rb index 45f1d52ba75..7a705f01505 100644 --- a/admin/spec/components/solidus_admin/products/status/component_spec.rb +++ b/admin/spec/components/solidus_admin/products/status/component_spec.rb @@ -21,7 +21,7 @@ render_inline described_class.from_product(product) - expect(rendered_content).to have_text("Discontinued") + within('tbody') { expect(rendered_content).to have_text("Discontinued") } end end end diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index b390e4c24bb..f450020428f 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -59,10 +59,13 @@ click_button "Activate" expect(page).to have_content("Products were successfully activated.", wait: 5) - expect(page).to have_content("Just a product") - expect(page).to have_content("Another product") - expect(page).not_to have_content("Discontinued") - expect(page).to have_content("Available").twice + within('tbody') do + expect(page).to have_content("Just a product") + expect(page).to have_content("Another product") + expect(page).not_to have_content("Discontinued") + expect(page).to have_content("Available").twice + end + expect(page).to be_axe_clean end end