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
This commit is contained in:
David Cook
2026-02-09 15:30:33 +11:00
parent e565243ce4
commit bd01b5f113
3 changed files with 56 additions and 1 deletions

View File

@@ -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",

View File

@@ -717,6 +717,7 @@ en:
delete: Delete
remove: Remove
preview: Preview
create_sourced_variant: Create sourced variant
image:
edit: Edit
product_preview:

View File

@@ -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
end