Merge pull request #12735 from chahmedejaz/bugfix/12698-fix-products-stateful-navigataion

Fix 'Back to products list' stateful navigation
This commit is contained in:
Konrad
2024-08-15 10:43:13 +02:00
committed by GitHub
5 changed files with 50 additions and 57 deletions

View File

@@ -11,6 +11,8 @@ module Admin
def index
fetch_products
render "index", locals: { producers:, categories:, tax_category_options:, flash: }
session[:products_return_to_url] = request.url
end
def bulk_update

View File

@@ -10,6 +10,7 @@ module Spree
include OpenFoodNetwork::SpreeApiKeyLoader
include OrderCyclesHelper
include EnterprisesHelper
helper ::Admin::ProductsHelper
before_action :load_data
before_action :load_producers, only: [:index, :new]

View File

@@ -29,5 +29,13 @@ module Admin
[precised_unit_value, variant.unit_description].compact_blank.join(" ")
end
def products_return_to_url(url_filters)
if feature?(:admin_style_v3, spree_current_user)
return session[:products_return_to_url] || admin_products_url
end
"#{admin_products_path}#{url_filters.empty? ? '' : "#?#{url_filters.to_query}"}"
end
end
end

View File

@@ -1,7 +1,7 @@
= admin_inject_available_units
- content_for :page_actions do
%li= button_link_to t('admin.products.back_to_products_list'), "#{admin_products_path}#{(@url_filters.empty? ? "" : "#?#{@url_filters.to_query}")}", :icon => 'icon-arrow-left'
%li= button_link_to t('admin.products.back_to_products_list'), products_return_to_url(@url_filters), :icon => 'icon-arrow-left'
%li#new_product_link
= button_link_to t(:new_product), new_object_url, { :icon => 'icon-plus', :id => 'admin_new_product' }
@@ -16,4 +16,4 @@
.form-buttons.filter-actions.actions
= button t(:update), 'icon-refresh'
= button_link_to t(:cancel), "#{collection_url}#{(@url_filters.empty? ? "" : "#?#{@url_filters.to_query}")}", icon: 'icon-remove'
= button_link_to t(:cancel), products_return_to_url(@url_filters), icon: 'icon-remove'

View File

@@ -309,6 +309,43 @@ RSpec.describe '
describe "editing page" do
let!(:product) { create(:simple_product, name: 'a product', supplier_id: supplier2.id) }
describe "'Back to products list' and 'Cancel' buttons" do
context "navigates to edit from the bulk product update page with searched results" do
it "should navigate back to the same searched results page" do
# Navigating to a searched URL
visit admin_products_url({
page: 1,
per_page: 25,
search_term: 'product',
producer_id: supplier2.id
})
products_page_url = current_url
within row_containing_name('a product') do
page.find(".vertical-ellipsis-menu").click
click_link('Edit', href: spree.edit_admin_product_path(product))
end
expect(page).to have_link('Back to products list',
href: products_page_url)
expect(page).to have_link('Cancel',
href: products_page_url)
end
end
context "directly navigates to the edit page" do
it "should navigate back to all the products page" do
# Navigating to a searched URL
visit spree.edit_admin_product_path(product)
expect(page).to have_link('Back to products list',
href: admin_products_url)
expect(page).to have_link('Cancel',
href: admin_products_url)
end
end
end
it "editing a product" do
visit spree.edit_admin_product_path product
@@ -319,61 +356,6 @@ RSpec.describe '
expect(product.description).to eq("<div>A description...</div>")
end
it "editing a product comming from the bulk product update page with filter" do
visit spree.edit_admin_product_path(product, filter)
click_button 'Update'
expect(flash_message).to eq('Product "a product" has been successfully updated!')
# Check the url still includes the filters
uri = URI.parse(current_url)
expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(product, filter)
# Link back to the bulk product update page should include the filters
expected_admin_product_url =
Regexp.new(Regexp.escape("#{spree.admin_products_path}#?#{filter.to_query}"))
expect(page).to have_link('Back to products list',
href: expected_admin_product_url)
expect(page).to have_link('Cancel', href: expected_admin_product_url)
expected_product_url = Regexp.new(Regexp.escape(spree.edit_admin_product_path(
product.id, filter
)))
expect(page).to have_link('Product Details',
href: expected_product_url)
expected_product_image_url = Regexp.new(Regexp.escape(spree.admin_product_images_path(
product.id, filter
)))
expect(page).to have_link('Images',
href: expected_product_image_url)
expected_product_variant_url = Regexp.new(Regexp.escape(spree.admin_product_variants_path(
product.id, filter
)))
expect(page).to have_link('Variants',
href: expected_product_variant_url)
expected_product_properties_url =
Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
product.id, filter
)))
expect(page).to have_link('Product Properties',
href: expected_product_properties_url)
expected_product_group_buy_option_url =
Regexp.new(Regexp.escape(spree.group_buy_options_admin_product_path(
product.id, filter
)))
expect(page).to have_link('Group Buy Options',
href: expected_product_group_buy_option_url)
expected_product_seo_url = Regexp.new(Regexp.escape(spree.seo_admin_product_path(
product.id, filter
)))
expect(page).to have_link('Search', href: expected_product_seo_url)
end
it "editing product group buy options" do
visit spree.edit_admin_product_path product
within('#sidebar') { click_link 'Group Buy Options' }