From bd01b5f113ce19fdd3de2415f92c6e0682cc0007 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 9 Feb 2026 15:30:33 +1100 Subject: [PATCH] Add 'create sourced variant' option in variant actions menu For now, we will only be able to create sourced variant from variants that are visible to us (variants that we manage) In a later commit I will hide the option if you can't use it --- .../admin/products_v3/_variant_row.html.haml | 2 + config/locales/en.yml | 1 + spec/system/admin/products_v3/actions_spec.rb | 54 ++++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index 54bf2ca861..79340b0f3e 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -88,6 +88,8 @@ = render(VerticalEllipsisMenuComponent.new) do - if variant.persisted? = link_to t('admin.products_page.actions.edit'), edit_admin_product_variant_path(variant.product, variant) + / TODO: only show if have permission. need to load permissions efficiently please. maybe the PErmissions object can cache result for each enterprise. maybe we preload it with the product query. + = link_to t('admin.products_page.actions.create_sourced_variant'), "TODO" # see next commit - if variant.product.variants.size > 1 %a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open", "data-modal-link-target-value": "variant-delete-modal", "class": "delete", diff --git a/config/locales/en.yml b/config/locales/en.yml index fffe128a73..f2f0e77c7c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -717,6 +717,7 @@ en: delete: Delete remove: Remove preview: Preview + create_sourced_variant: Create sourced variant image: edit: Edit product_preview: diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index 53079771df..006bce3132 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -272,6 +272,58 @@ RSpec.describe 'As an enterprise user, I can perform actions on the products scr end end + describe "Create sourced variant" do + let!(:variant) { + create(:variant, display_name: "My box", supplier: producer) + } + let!(:other_producer) { create(:supplier_enterprise) } + let!(:other_variant) { + create(:variant, display_name: "My friends box", supplier: other_producer) + } + let!(:enterprise_relationship) { + # Other producer grants me access to manage their variant + create(:enterprise_relationship, parent: other_producer, child: producer, + permissions_list: [:manage_products]) + } + + before do + visit admin_products_url + end + + context "with create_sourced_variants permission for my, and other's variants" do + it "shows an option to create sourced variant" do + create(:enterprise_relationship, parent: producer, child: producer, + permissions_list: [:create_sourced_variants]) + enterprise_relationship.permissions.create! name: :create_sourced_variants + + within row_containing_name("My box") do + page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Create sourced variant" # , href: admin_clone_product_path(product_a) + end + + within row_containing_name("My friends box") do + page.find(".vertical-ellipsis-menu").click + expect(page).to have_link "Create sourced variant" # , href: admin_clone_product_path(product_a) + end + end + end + + context "without create_sourced_variants permission" do + it "does not show the option in the menu" do + pending "TODO: hide option if you can't use it." + within row_containing_name("My box") do + page.find(".vertical-ellipsis-menu").click + expect(page).not_to have_link "Create sourced variant" + end + + within row_containing_name("My friends box") do + page.find(".vertical-ellipsis-menu").click + expect(page).not_to have_link "Create sourced variant" + end + end + end + end + describe "delete" do let!(:product_a) { create(:simple_product, name: "Apples", sku: "APL-00") } let(:delete_option_selector) { "a[data-controller='modal-link'].delete" } @@ -508,4 +560,4 @@ RSpec.describe 'As an enterprise user, I can perform actions on the products scr def close_action_menu page.find("div#content").click end -end \ No newline at end of file +end