From 2a98789571fde0b89e36cdf2e4566474ac25d878 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 19 Sep 2023 16:08:14 +0200 Subject: [PATCH] Add `vertical-ellipsis-menu` as product/variant actions menu in products table + add specs --- app/views/admin/products_v3/_table.html.haml | 4 +-- .../components/_product_actions.html.haml | 7 +++++ .../system/admin/products_v3/products_spec.rb | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/products_v3/components/_product_actions.html.haml diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index ba404e519d..21cf8f37ab 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -61,7 +61,7 @@ %td.align-left .line-clamp-1= product.inherits_properties ? 'YES' : 'NO' #TODO: consider using https://github.com/RST-J/human_attribute_values, else use I18n.t (also below) %td.align-right - = link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product) + = render partial: 'admin/products_v3/components/product_actions', locals: { product: product } - product.variants.each do |variant| - prefix = "[products][][variants_attributes][]" # Couldn't convince the formbuilder to generate this for me, so for now we manually add the prefix = form.fields_for(variant) do |variant_form| @@ -86,4 +86,4 @@ %td.align-left -# empty %td.align-right - = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(product, variant) + = render partial: 'admin/products_v3/components/product_actions', locals: { product: product, variant: variant } diff --git a/app/views/admin/products_v3/components/_product_actions.html.haml b/app/views/admin/products_v3/components/_product_actions.html.haml new file mode 100644 index 0000000000..a465498eac --- /dev/null +++ b/app/views/admin/products_v3/components/_product_actions.html.haml @@ -0,0 +1,7 @@ +.vertical-ellipsis-menu{ "data-controller": "vertical-ellipsis-menu" } + %i.fa.fa-ellipsis-v{ "data-action": "click->vertical-ellipsis-menu#toggle" } + .vertical-ellipsis-menu-content{ "data-vertical-ellipsis-menu-target": "content" } + - if defined?(variant) + = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(product, variant), class: "vertical-ellipsis-menu-content-item" + - else + = link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product), class: "vertical-ellipsis-menu-content-item" diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 0a0c83cbe4..53b5993cd6 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -157,6 +157,36 @@ describe 'As an admin, I can see the new product page' do end end + describe "Actions columns (edit)" do + let!(:variant_a1) { + create(:variant, + product: product_a, + display_name: "Medium box", + sku: "APL-01", + price: 5.25) + } + let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") } + + before do + visit admin_products_v3_index_url + end + + it "shows an actions memu with an edit link when clicking on icon for product" do + within row_containing_name("Apples") do + page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Edit", href: spree.edit_admin_product_path(product_a) + end + end + + it "shows an actions memu with an edit link when clicking on icon for variant" do + within row_containing_name("Medium box") do + page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Edit", + href: spree.edit_admin_product_variant_path(product_a, variant_a1) + end + end + end + describe "updating" do let!(:variant_a1) { create(:variant,