From c101c4e42fbab48ee779ace31541ed9d814f4936 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Mon, 5 Aug 2024 13:51:59 +0500 Subject: [PATCH] 12698 - fix 'go back to products' stateful navigation --- app/controllers/admin/products_v3_controller.rb | 2 ++ app/controllers/spree/admin/products_controller.rb | 1 + app/helpers/admin/products_helper.rb | 4 ++++ app/views/spree/admin/products/edit.html.haml | 4 ++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 327a4a4be9..24ed032dcf 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -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 diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 3ae92a38bd..4580a751f0 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -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] diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb index d0d5611d80..334743a62b 100644 --- a/app/helpers/admin/products_helper.rb +++ b/app/helpers/admin/products_helper.rb @@ -27,5 +27,9 @@ module Admin [precised_unit_value, variant.unit_description].compact_blank.join(" ") end + + def products_return_to_url + session[:products_return_to_url] || admin_products_url + end end end diff --git a/app/views/spree/admin/products/edit.html.haml b/app/views/spree/admin/products/edit.html.haml index 6a5ccb4c21..f30115860c 100644 --- a/app/views/spree/admin/products/edit.html.haml +++ b/app/views/spree/admin/products/edit.html.haml @@ -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, :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, icon: 'icon-remove'