Use a list of links for admin stats events

Using <h3> headings for the links had two disadvantages.

First, it was the wrong heading level to use, since there was no <h2>
tag before it.

Second, headings are supposed to be followed by content associated to
that heading; here, we had no content following the headings.

So we're using a list of links and giving it a heading. We're adding
styles so the page still looks like it used to, although these styles
are certainly asking for improvements.
This commit is contained in:
Javi Martín
2024-04-23 23:57:44 +02:00
parent 4e9ed4dfa6
commit b04ac817f6
6 changed files with 48 additions and 6 deletions

View File

@@ -0,0 +1,14 @@
.stats-event-links {
margin-top: $line-height;
ul {
@include header-font-size(h3);
font-weight: bold;
list-style-type: none;
margin-#{$global-left}: 0;
* + * {
margin-top: $line-height;
}
}
}

View File

@@ -1,6 +1,4 @@
<% event_names.each do |event| %> <div class="stats-event-links">
<h3> <h2><%= title %></h2>
<%= link_to link_text(event), <%= link_list(*links) %>
graph_admin_stats_path(event: event) %> </div>
</h3>
<% end %>

View File

@@ -1,5 +1,6 @@
class Admin::Stats::EventLinksComponent < ApplicationComponent class Admin::Stats::EventLinksComponent < ApplicationComponent
attr_reader :event_names attr_reader :event_names
use_helpers :link_list
def initialize(event_names) def initialize(event_names)
@event_names = event_names @event_names = event_names
@@ -14,4 +15,14 @@ class Admin::Stats::EventLinksComponent < ApplicationComponent
end end
text text
end end
def title
t("admin.stats.graph.title")
end
def links
event_names.map do |event|
[link_text(event), graph_admin_stats_path(event: event)]
end
end
end end

View File

@@ -1492,6 +1492,7 @@ en:
visit: Visits visit: Visits
level_2_user: Level 2 users level_2_user: Level 2 users
proposal_created: Citizen proposals proposal_created: Citizen proposals
title: Graphs
budgets: budgets:
no_data_before_balloting_phase: "There isn't any data to show before the balloting phase." no_data_before_balloting_phase: "There isn't any data to show before the balloting phase."
title: "Participatory Budgets - Participation stats" title: "Participatory Budgets - Participation stats"

View File

@@ -1492,6 +1492,7 @@ es:
visit: Visitas visit: Visitas
level_2_user: Usuarios nivel 2 level_2_user: Usuarios nivel 2
proposal_created: Propuestas Ciudadanas proposal_created: Propuestas Ciudadanas
title: Gráficos
budgets: budgets:
no_data_before_balloting_phase: "No hay datos que mostrar hasta que la fase de votación no esté abierta." no_data_before_balloting_phase: "No hay datos que mostrar hasta que la fase de votación no esté abierta."
title: "Presupuestos participativos - Estadisticas de participación" title: "Presupuestos participativos - Estadisticas de participación"

View File

@@ -0,0 +1,17 @@
require "rails_helper"
describe Admin::Stats::EventLinksComponent do
it "renders an <h2> heading followed by a list of links" do
render_inline Admin::Stats::EventLinksComponent.new(
%w[legislation_annotation_created legislation_answer_created]
)
expect(page).to have_css "h2", exact_text: "Graphs"
expect(page).to have_link count: 2
page.find("ul") do |list|
expect(list).to have_link "legislation_annotation_created"
expect(list).to have_link "legislation_answer_created"
end
end
end