Use buttons for budgets actions

Using buttons for non-GET actions is better for accessibility, as
mentioned in commit 5311daadf.
This commit is contained in:
Javi Martín
2021-08-22 00:11:32 +02:00
parent b81bdc778b
commit 8aa6f29d6b
9 changed files with 43 additions and 27 deletions

View File

@@ -6,7 +6,6 @@
margin-top: -$gap; margin-top: -$gap;
> * { > * {
margin-bottom: 0;
margin-top: $gap; margin-top: $gap;
} }
@@ -14,6 +13,11 @@
margin-top: $line-height; margin-top: $line-height;
} }
a,
button {
margin-bottom: 0;
}
.preview-link { .preview-link {
@include has-fa-icon(eye, regular); @include has-fa-icon(eye, regular);
@include hollow-button; @include hollow-button;
@@ -24,4 +28,8 @@
margin-#{$global-right}: $font-icon-margin; margin-#{$global-right}: $font-icon-margin;
} }
} }
.delete {
cursor: pointer;
}
} }

View File

@@ -19,7 +19,5 @@
.publish-link { .publish-link {
@include regular-button; @include regular-button;
margin-bottom: 0; margin-bottom: 0;
margin-#{$global-left}: $line-height / 2;
margin-top: $vertical-gap;
} }
} }

View File

@@ -8,8 +8,8 @@
<%= link_to t("admin.budgets.actions.preview"), budget_path(budget), class: "preview-link", target: "_blank" %> <%= link_to t("admin.budgets.actions.preview"), budget_path(budget), class: "preview-link", target: "_blank" %>
<%= link_to t("admin.budgets.edit.delete"), <%= action(:destroy,
admin_budget_path(budget), text: t("admin.budgets.edit.delete"),
method: :delete, method: :delete,
class: "delete" %> class: "delete") %>
</div> </div>

View File

@@ -4,4 +4,10 @@ class Admin::Budgets::ActionsComponent < ApplicationComponent
def initialize(budget) def initialize(budget)
@budget = budget @budget = budget
end end
private
def action(action_name, **options)
render Admin::ActionComponent.new(action_name, budget, **options)
end
end end

View File

@@ -1,8 +1,9 @@
<% if display_button? %> <% if display_button? %>
<%= link_to text, <%= render Admin::ActionComponent.new(
calculate_winners_admin_budget_path(budget), :calculate_winners,
method: :put, budget,
class: html_class %> text: text, method: :put, class: html_class
) %>
<% elsif from_investments %> <% elsif from_investments %>
<span class="button hollow disabled float-right clear"> <span class="button hollow disabled float-right clear">
<%= t("admin.budgets.winners.calculate") %> <%= t("admin.budgets.winners.calculate") %>

View File

@@ -3,8 +3,9 @@
<strong><%= t("admin.budgets.edit.drafting") %></strong> <strong><%= t("admin.budgets.edit.drafting") %></strong>
</div> </div>
<%= link_to t("admin.budgets.edit.publish"), <%= render Admin::ActionComponent.new(
publish_admin_budget_path(budget), :publish,
method: :patch, class: "publish-link", budget,
data: { confirm: t("admin.actions.confirm") } %> text: t("admin.budgets.edit.publish"), method: :patch, confirm: true
) %>
</div> </div>

View File

@@ -496,11 +496,11 @@ describe "Admin budget investments", :admin do
check "Winners" check "Winners"
click_button "Filter" click_button "Filter"
expect(page).to have_link "Calculate Winner Investments" expect(page).to have_button "Calculate Winner Investments"
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
expect(page).to have_link "Calculate Winner Investments" expect(page).to have_button "Calculate Winner Investments"
select "Accepting projects", from: "Active phase" select "Accepting projects", from: "Active phase"
click_button "Update Budget" click_button "Update Budget"
@@ -513,14 +513,14 @@ describe "Admin budget investments", :admin do
check "Winners" check "Winners"
click_button "Filter" click_button "Filter"
expect(page).not_to have_link "Calculate Winner Investments" expect(page).not_to have_button "Calculate Winner Investments"
expect(page).to have_content 'The budget has to stay on phase "Balloting projects", '\ expect(page).to have_content 'The budget has to stay on phase "Balloting projects", '\
'"Reviewing Ballots" or "Finished budget" in order '\ '"Reviewing Ballots" or "Finished budget" in order '\
"to calculate winners projects" "to calculate winners projects"
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
expect(page).not_to have_link "Calculate Winner Investments" expect(page).not_to have_button "Calculate Winner Investments"
end end
scenario "Filtering by minimum number of votes" do scenario "Filtering by minimum number of votes" do

View File

@@ -124,11 +124,11 @@ describe "Admin budgets", :admin do
scenario "Can preview a budget after it is published" do scenario "Can preview a budget after it is published" do
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
accept_confirm { click_link "Publish budget" } accept_confirm { click_button "Publish budget" }
expect(page).to have_content "Participatory budget published successfully" expect(page).to have_content "Participatory budget published successfully"
expect(page).not_to have_content "This participatory budget is in draft mode" expect(page).not_to have_content "This participatory budget is in draft mode"
expect(page).not_to have_link "Publish budget" expect(page).not_to have_button "Publish budget"
within_window(window_opened_by { click_link "Preview" }) do within_window(window_opened_by { click_link "Preview" }) do
expect(page).to have_current_path budget_path(budget) expect(page).to have_current_path budget_path(budget)
@@ -142,7 +142,7 @@ describe "Admin budgets", :admin do
scenario "Destroy a budget without investments" do scenario "Destroy a budget without investments" do
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
click_link "Delete budget" click_button "Delete budget"
expect(page).to have_content("Budget deleted successfully") expect(page).to have_content("Budget deleted successfully")
expect(page).to have_content("There are no budgets.") expect(page).to have_content("There are no budgets.")
@@ -153,7 +153,7 @@ describe "Admin budgets", :admin do
budget.valuators << create(:valuator) budget.valuators << create(:valuator)
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
click_link "Delete budget" click_button "Delete budget"
expect(page).to have_content "Budget deleted successfully" expect(page).to have_content "Budget deleted successfully"
expect(page).to have_content "There are no budgets." expect(page).to have_content "There are no budgets."
@@ -163,7 +163,7 @@ describe "Admin budgets", :admin do
create(:budget_investment, heading: heading) create(:budget_investment, heading: heading)
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
click_link "Delete budget" click_button "Delete budget"
expect(page).to have_content("You cannot delete a budget that has associated investments") expect(page).to have_content("You cannot delete a budget that has associated investments")
expect(page).to have_content("There is 1 budget") expect(page).to have_content("There is 1 budget")
@@ -173,7 +173,7 @@ describe "Admin budgets", :admin do
create(:poll, budget: budget) create(:poll, budget: budget)
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
click_link "Delete budget" click_button "Delete budget"
expect(page).to have_content("You cannot delete a budget that has an associated poll") expect(page).to have_content("You cannot delete a budget that has an associated poll")
expect(page).to have_content("There is 1 budget") expect(page).to have_content("There is 1 budget")
@@ -335,7 +335,9 @@ describe "Admin budgets", :admin do
visit edit_admin_budget_path(budget) visit edit_admin_budget_path(budget)
expect(page).not_to have_content "See results" expect(page).not_to have_content "See results"
click_link "Calculate Winner Investments"
click_button "Calculate Winner Investments"
expect(page).to have_content "Winners being calculated, it may take a minute." expect(page).to have_content "Winners being calculated, it may take a minute."
expect(page).to have_content winner.title expect(page).to have_content winner.title
expect(page).not_to have_content unselected.title expect(page).not_to have_content unselected.title

View File

@@ -92,7 +92,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "This participatory budget is in draft mode" expect(page).to have_content "This participatory budget is in draft mode"
expect(page).to have_link "Preview" expect(page).to have_link "Preview"
expect(page).to have_link "Publish budget" expect(page).to have_button "Publish budget"
end end
end end