Add labels to the search form in the management area

The text for the unfeasible checkbox wasn't correctly defined as a
label, while the fields to search investments and select the heading
weren't intuitive since their purpose wasn't obvious.
This commit is contained in:
Javi Martín
2024-10-11 02:09:15 +02:00
parent b45f928703
commit 1cefc040a7
8 changed files with 55 additions and 7 deletions

View File

@@ -47,6 +47,7 @@
@import "documents/**/*"; @import "documents/**/*";
@import "layout/**/*"; @import "layout/**/*";
@import "machine_learning/**/*"; @import "machine_learning/**/*";
@import "management/**/*";
@import "moderation/**/*"; @import "moderation/**/*";
@import "polls/**/*"; @import "polls/**/*";
@import "proposals/**/*"; @import "proposals/**/*";

View File

@@ -0,0 +1,5 @@
.management-investments-search {
.checkbox-label {
font-weight: normal;
}
}

View File

@@ -1,9 +1,11 @@
<%= form_tag(url, method: :get) do |f| %> <%= form_tag(url, options) do |f| %>
<div class="row"> <div class="row">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<%= label_tag :search, search_label_text %>
<%= text_field_tag :search, "" %> <%= text_field_tag :search, "" %>
</div> </div>
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
<%= label_tag :heading_id, attribute_name(:heading_id) %>
<%= select_tag :heading_id, <%= select_tag :heading_id,
options_for_select(budget_heading_select_options(budget), options_for_select(budget_heading_select_options(budget),
params[:heading_id]), params[:heading_id]),
@@ -12,8 +14,10 @@
</div> </div>
<div class="row"> <div class="row">
<div class="small-12 column"> <div class="small-12 column">
<%= check_box_tag :unfeasible, "1", params[:unfeasible].present? %> <%= label_tag :unfeasible, class: "checkbox-label" do %>
<%= t("admin.budget_investments.search_unfeasible") %> <%= check_box_tag :unfeasible, "1", params[:unfeasible].present? %>
<%= t("admin.budget_investments.search_unfeasible") %>
<% end %>
</div> </div>
</div> </div>

View File

@@ -6,4 +6,21 @@ class Management::Budgets::Investments::SearchComponent < ApplicationComponent
@budget = budget @budget = budget
@url = url @url = url
end end
private
def options
{
method: :get,
class: "management-investments-search"
}
end
def search_label_text
t("management.budget_investments.search.label")
end
def attribute_name(attribute)
Budget::Investment.human_attribute_name(attribute)
end
end end

View File

@@ -95,6 +95,8 @@ en:
unfeasible: Unfeasible investment unfeasible: Unfeasible investment
print: print:
print_button: Print print_button: Print
search:
label: "Search investments"
search_results: search_results:
one: " containing the term '%{search_term}'" one: " containing the term '%{search_term}'"
other: " containing the term '%{search_term}'" other: " containing the term '%{search_term}'"

View File

@@ -95,6 +95,8 @@ es:
unfeasible: Proyectos no factibles unfeasible: Proyectos no factibles
print: print:
print_button: Imprimir print_button: Imprimir
search:
label: "Buscar proyectos"
search_results: search_results:
one: " que contiene '%{search_term}'" one: " que contiene '%{search_term}'"
other: " que contienen '%{search_term}'" other: " que contienen '%{search_term}'"

View File

@@ -0,0 +1,17 @@
require "rails_helper"
describe Management::Budgets::Investments::SearchComponent do
include Rails.application.routes.url_helpers
let(:budget) { create(:budget) }
let(:url) { management_budget_investments_path(budget) }
let(:component) { Management::Budgets::Investments::SearchComponent.new(budget, url: url) }
it "renders a label for each field" do
render_inline component
expect(page).to have_field "Search investments"
expect(page).to have_select "Heading"
expect(page).to have_field "Search unfeasible", type: :checkbox
end
end

View File

@@ -143,7 +143,7 @@ describe "Budget Investments" do
click_link "Support budget investments" click_link "Support budget investments"
end end
fill_in "search", with: "what you got" fill_in "Search investments", with: "what you got"
click_button "Search" click_button "Search"
within("#budget-investments") do within("#budget-investments") do
@@ -170,7 +170,7 @@ describe "Budget Investments" do
click_link "Support budget investments" click_link "Support budget investments"
end end
fill_in "search", with: "Area 52" fill_in "Search investments", with: "Area 52"
click_button "Search" click_button "Search"
within("#budget-investments") do within("#budget-investments") do
@@ -523,8 +523,8 @@ describe "Budget Investments" do
expect(page).to have_content(low_investment.title) expect(page).to have_content(low_investment.title)
end end
select "District Nine", from: "heading_id" select "District Nine", from: "Heading"
click_button("Search") click_button "Search"
within "#budget-investments" do within "#budget-investments" do
expect(page).not_to have_content(unvoted_investment.title) expect(page).not_to have_content(unvoted_investment.title)