From 9fceb4f55581d7b2b644e44c85b5986b34eaf06c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?=
<15726+Senen@users.noreply.github.com>
Date: Mon, 27 Nov 2023 14:22:15 +0100
Subject: [PATCH] Fix map settings redirection
---
.../admin/settings/map_form_component.html.erb | 1 +
app/components/admin/settings/map_form_component.rb | 5 +++++
app/controllers/admin/settings_controller.rb | 2 +-
.../admin/settings/_map_configuration_tab.html.erb | 2 +-
spec/system/admin/settings_spec.rb | 11 +++++++++++
5 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/app/components/admin/settings/map_form_component.html.erb b/app/components/admin/settings/map_form_component.html.erb
index c71b412a09c..df701e6c555 100644
--- a/app/components/admin/settings/map_form_component.html.erb
+++ b/app/components/admin/settings/map_form_component.html.erb
@@ -20,6 +20,7 @@
<%= hidden_field_tag :latitude, Setting["map.latitude"] %>
<%= hidden_field_tag :longitude, Setting["map.longitude"] %>
<%= hidden_field_tag :zoom, Setting["map.zoom"] %>
+ <%= hidden_field_tag :tab, tab if defined?(tab) %>
<%= submit_tag t("admin.settings.index.map.form.submit"),
diff --git a/app/components/admin/settings/map_form_component.rb b/app/components/admin/settings/map_form_component.rb
index 29e5f537283..81209a7eeea 100644
--- a/app/components/admin/settings/map_form_component.rb
+++ b/app/components/admin/settings/map_form_component.rb
@@ -1,2 +1,7 @@
class Admin::Settings::MapFormComponent < ApplicationComponent
+ attr_reader :tab
+
+ def initialize(tab: nil)
+ @tab = tab
+ end
end
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index c6284dafd63..7b98cb7736b 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -26,7 +26,7 @@ def update_map
Setting["map.latitude"] = params[:latitude].to_f
Setting["map.longitude"] = params[:longitude].to_f
Setting["map.zoom"] = params[:zoom].to_i
- redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update")
+ redirect_to request_referer, notice: t("admin.settings.index.map.flash.update")
end
def update_content_types
diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb
index 9f0d4ab71c8..77130f0a26a 100644
--- a/app/views/admin/settings/_map_configuration_tab.html.erb
+++ b/app/views/admin/settings/_map_configuration_tab.html.erb
@@ -5,7 +5,7 @@
<%= t("admin.settings.index.map.help") %>
- <%= render Admin::Settings::MapFormComponent.new %>
+ <%= render Admin::Settings::MapFormComponent.new(tab: "#tab-map-configuration") %>
<% else %>
<%= t("admin.settings.index.map.how_to_enable") %>
diff --git a/spec/system/admin/settings_spec.rb b/spec/system/admin/settings_spec.rb
index f57f737148d..e8ac59aba62 100644
--- a/spec/system/admin/settings_spec.rb
+++ b/spec/system/admin/settings_spec.rb
@@ -210,6 +210,17 @@
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-map-configuration.is-active")
end
+
+ scenario "On #tab-map-configuration when using the interactive map" do
+ visit admin_settings_path(anchor: "tab-map-configuration")
+ within "#map-form" do
+ click_button "Update"
+ end
+
+ expect(page).to have_content("Map configuration updated successfully.")
+ expect(page).to have_current_path(admin_settings_path)
+ expect(page).to have_css("div#tab-map-configuration.is-active")
+ end
end
scenario "On #tab-proposals" do