mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Supports tag filters persistence during product updates
Adds functionality to retain tag filters applied in the admin product interface after bulk updates. Updates controller parameters to include tags_name_in, adds hidden fields for tag persistence in the view, and includes specs to verify filter state retention across update operations.
This commit is contained in:
@@ -28,7 +28,7 @@ module Admin
|
||||
flash[:success] = I18n.t('admin.products_v3.bulk_update.success')
|
||||
redirect_to [:index,
|
||||
{ page: @page, per_page: @per_page, search_term: @search_term,
|
||||
producer_id: @producer_id, category_id: @category_id }]
|
||||
producer_id: @producer_id, category_id: @category_id, tags_name_in: @tags }]
|
||||
elsif product_set.errors.present?
|
||||
@error_counts = { saved: product_set.saved_count, invalid: product_set.invalid.count }
|
||||
|
||||
@@ -120,7 +120,7 @@ module Admin
|
||||
@search_term = params[:search_term] || params[:_search_term]
|
||||
@producer_id = params[:producer_id] || params[:_producer_id]
|
||||
@category_id = params[:category_id] || params[:_category_id]
|
||||
@tags = params[:tags_name_in] || params[:_tags_name_in]
|
||||
@tags = params[:tags_name_in] || []
|
||||
end
|
||||
|
||||
def init_pagination_params
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
= hidden_field_tag :search_term, @search_term
|
||||
= hidden_field_tag :producer_id, @producer_id
|
||||
= hidden_field_tag :category_id, @category_id
|
||||
- @tags.each do |tag|
|
||||
= hidden_field_tag 'tags_name_in[]', tag
|
||||
|
||||
%table.products{ 'data-column-preferences-target': "table", class: (hide_producer_column?(producer_options) ? 'hide-producer' : '') }
|
||||
%colgroup
|
||||
|
||||
@@ -36,4 +36,21 @@ module TomSelectHelper
|
||||
|
||||
find('.ts-dropdown .ts-dropdown-content .option', text: /#{Regexp.quote(value)}/i).click
|
||||
end
|
||||
|
||||
def expect_tomselect_selected_options(from, *options)
|
||||
tomselect_control = page
|
||||
.find("[name='#{from}']")
|
||||
.sibling(".ts-wrapper")
|
||||
.find('.ts-control')
|
||||
|
||||
within(tomselect_control) do
|
||||
# options in case of we want to expect multiselect options
|
||||
options.each do |option|
|
||||
expect(page).to have_css(
|
||||
"div[data-ts-item]",
|
||||
text: option
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -731,6 +731,44 @@ RSpec.describe 'As an enterprise user, I can update my products' do
|
||||
expect(page).to have_css row_containing_name("zucchinis")
|
||||
end
|
||||
end
|
||||
|
||||
context "when filters are applied" do
|
||||
before do
|
||||
variant_b1 # invoke to create the variant
|
||||
variant_a1.tags.create!(name: 'organic')
|
||||
visit admin_products_url
|
||||
end
|
||||
it 'persists the filters after update' do
|
||||
# Ensure all products are shown
|
||||
expect_products_count_to_be 2
|
||||
|
||||
supplier_name = variant_a1.supplier.name
|
||||
category_name = variant_a1.primary_taxon.name
|
||||
tag_name = variant_a1.tags.first.name
|
||||
tomselect_select supplier_name, from: "producer_id"
|
||||
tomselect_select category_name, from: "category_id"
|
||||
tomselect_multiselect tag_name, from: "tags_name_in"
|
||||
click_button "Search"
|
||||
|
||||
# Ensure filters are selected and applied after search
|
||||
expect_tomselect_selected_options("producer_id", supplier_name)
|
||||
expect_tomselect_selected_options("category_id", category_name)
|
||||
expect_tomselect_selected_options("tags_name_in[]", tag_name)
|
||||
expect_products_count_to_be 1
|
||||
|
||||
within row_containing_name("Medium box") do
|
||||
fill_in "Price", with: "10.25"
|
||||
end
|
||||
click_button "Save changes"
|
||||
expect(page).to have_content "Changes saved"
|
||||
|
||||
# Ensure filters still selected and applied even after update
|
||||
expect_tomselect_selected_options("producer_id", supplier_name)
|
||||
expect_tomselect_selected_options("category_id", category_name)
|
||||
expect_tomselect_selected_options("tags_name_in[]", tag_name)
|
||||
expect_products_count_to_be 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit image" do
|
||||
|
||||
Reference in New Issue
Block a user