Use a switch to enable/disable homepage features

So it's consistent with the way we enable/disable other features.
This commit is contained in:
Javi Martín
2021-08-28 03:05:44 +02:00
parent fabe97e506
commit 7b8e892f9c
9 changed files with 26 additions and 30 deletions

View File

@@ -1,10 +1,12 @@
class Admin::Settings::FeaturedSettingsFormComponent < ApplicationComponent class Admin::Settings::FeaturedSettingsFormComponent < ApplicationComponent
attr_reader :feature, :tab attr_reader :feature, :tab, :describedby
alias_method :describedby?, :describedby
delegate :enabled?, to: :feature delegate :enabled?, to: :feature
def initialize(feature, tab: nil) def initialize(feature, tab: nil, describedby: true)
@feature = feature @feature = feature
@tab = tab @tab = tab
@describedby = describedby
end end
private private
@@ -20,7 +22,7 @@ class Admin::Settings::FeaturedSettingsFormComponent < ApplicationComponent
def options def options
{ {
"aria-labelledby": dom_id(feature, :title), "aria-labelledby": dom_id(feature, :title),
"aria-describedby": dom_id(feature, :description), "aria-describedby": (dom_id(feature, :description) if describedby?),
"aria-pressed": enabled? "aria-pressed": enabled?
} }
end end

View File

@@ -1,6 +1,6 @@
<div id="<%= dom_id(feed) %>" class="small-12 medium-6 large-4 column end"> <div id="<%= dom_id(feed) %>" class="small-12 medium-6 large-4 column end">
<div class="callout"> <div class="callout">
<h3><%= t("admin.homepage.feeds.#{feed.kind}") %></h3> <h3 id="<%= dom_id(feed.setting, :title) %>"><%= t("admin.homepage.feeds.#{feed.kind}") %></h3>
<%= render "setting", setting: feed.setting %> <%= render "setting", setting: feed.setting %>

View File

@@ -1,10 +1 @@
<div id="<%= dom_id(setting) %>"> <%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, describedby: false) %>
<%= form_for(setting, url: admin_setting_path(setting), method: :put) do |f| %>
<%= f.hidden_field :value,
value: (setting.enabled? ? "" : "active") %>
<%= f.submit(t("admin.settings.index.features.#{setting.enabled? ? "disable" : "enable"}"),
class: "button #{setting.enabled? ? "hollow alert" : "success"}") %>
<% end %>
</div>

View File

@@ -38,7 +38,7 @@
<div class="small-12 medium-6 large-4 column end"> <div class="small-12 medium-6 large-4 column end">
<div class="callout"> <div class="callout">
<h3 class="inline-block"><%= t("settings.#{@recommendations.key}") %></h3> <h3 id="<%= dom_id(@recommendations, :title) %>" class="inline-block"><%= t("settings.#{@recommendations.key}") %></h3>
<%= render "setting", setting: @recommendations %> <%= render "setting", setting: @recommendations %>
</div> </div>
</div> </div>

View File

@@ -160,7 +160,6 @@ ignore_unused:
- "admin.legislation.draft_versions.*.submit_button" - "admin.legislation.draft_versions.*.submit_button"
- "admin.legislation.questions.*.submit_button" - "admin.legislation.questions.*.submit_button"
- "admin.hidden_comments.index.hidden_*" - "admin.hidden_comments.index.hidden_*"
- "admin.settings.index.features.*"
- "admin.polls.*.submit_button" - "admin.polls.*.submit_button"
- "admin.booths.*.submit_button" - "admin.booths.*.submit_button"
- "admin.admin_notifications.*.submit_button" - "admin.admin_notifications.*.submit_button"

View File

@@ -1299,8 +1299,6 @@ en:
feature_flags: Features feature_flags: Features
features: features:
enabled: "Enabled" enabled: "Enabled"
enable: "Enable"
disable: "Disable"
map: map:
title: Map configuration title: Map configuration
help: Here you can customize the way the map is displayed to users. Drag map marker or click anywhere over the map, set desired zoom and click button "Update". help: Here you can customize the way the map is displayed to users. Drag map marker or click anywhere over the map, set desired zoom and click button "Update".

View File

@@ -1298,8 +1298,6 @@ es:
feature_flags: Funcionalidades feature_flags: Funcionalidades
features: features:
enabled: "Activada" enabled: "Activada"
enable: "Activar"
disable: "Desactivar"
map: map:
title: Configuración del mapa title: Configuración del mapa
help: Aquí puedes personalizar la manera en la que se muestra el mapa a los usuarios. Arrastra el marcador o pulsa sobre cualquier parte del mapa, ajusta el zoom y pulsa el botón 'Actualizar'. help: Aquí puedes personalizar la manera en la que se muestra el mapa a los usuarios. Arrastra el marcador o pulsa sobre cualquier parte del mapa, ajusta el zoom y pulsa el botón 'Actualizar'.

View File

@@ -11,12 +11,20 @@ describe Admin::Settings::FeaturedSettingsFormComponent do
expect(page).to have_css "button[aria-labelledby='title_setting_#{setting.id}']" expect(page).to have_css "button[aria-labelledby='title_setting_#{setting.id}']"
end end
it "includes an aria-describedby attribute" do describe "aria-describedby attribute" do
it "is rendered by default" do
render_inline component render_inline component
expect(page).to have_css "button[aria-describedby='description_setting_#{setting.id}']" expect(page).to have_css "button[aria-describedby='description_setting_#{setting.id}']"
end end
it "is not rendered when the describedby option is false" do
render_inline Admin::Settings::FeaturedSettingsFormComponent.new(setting, describedby: false)
expect(page).not_to have_css "[aria-describedby]"
end
end
describe "aria-pressed attribute" do describe "aria-pressed attribute" do
it "is true when the setting is enabled" do it "is true when the setting is enabled" do
setting.update!(value: "active") setting.update!(value: "active")

View File

@@ -33,7 +33,7 @@ describe "Homepage", :admin do
within("#widget_feed_#{proposals_feed.id}") do within("#widget_feed_#{proposals_feed.id}") do
select "1", from: "widget_feed_limit" select "1", from: "widget_feed_limit"
click_button "Enable" click_button "No"
end end
visit root_path visit root_path
@@ -52,7 +52,7 @@ describe "Homepage", :admin do
visit admin_homepage_path visit admin_homepage_path
within("#widget_feed_#{debates_feed.id}") do within("#widget_feed_#{debates_feed.id}") do
select "2", from: "widget_feed_limit" select "2", from: "widget_feed_limit"
click_button "Enable" click_button "No"
end end
visit root_path visit root_path
@@ -73,12 +73,12 @@ describe "Homepage", :admin do
within("#widget_feed_#{proposals_feed.id}") do within("#widget_feed_#{proposals_feed.id}") do
select "3", from: "widget_feed_limit" select "3", from: "widget_feed_limit"
click_button "Enable" click_button "No"
end end
within("#widget_feed_#{debates_feed.id}") do within("#widget_feed_#{debates_feed.id}") do
select "3", from: "widget_feed_limit" select "3", from: "widget_feed_limit"
click_button "Enable" click_button "No"
end end
visit root_path visit root_path
@@ -100,7 +100,7 @@ describe "Homepage", :admin do
visit admin_homepage_path visit admin_homepage_path
within("#widget_feed_#{processes_feed.id}") do within("#widget_feed_#{processes_feed.id}") do
select "3", from: "widget_feed_limit" select "3", from: "widget_feed_limit"
click_button "Enable" click_button "No"
end end
visit root_path visit root_path
@@ -153,8 +153,8 @@ describe "Homepage", :admin do
create(:proposal, tag_list: "Sport") create(:proposal, tag_list: "Sport")
visit admin_homepage_path visit admin_homepage_path
within("#setting_#{user_recommendations.id}") do within("#edit_setting_#{user_recommendations.id}") do
click_button "Enable" click_button "No"
end end
expect(page).to have_content "Value updated" expect(page).to have_content "Value updated"