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

View File

@@ -19,7 +19,5 @@
.publish-link {
@include regular-button;
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.edit.delete"),
admin_budget_path(budget),
method: :delete,
class: "delete" %>
<%= action(:destroy,
text: t("admin.budgets.edit.delete"),
method: :delete,
class: "delete") %>
</div>

View File

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

View File

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

View File

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

View File

@@ -496,11 +496,11 @@ describe "Admin budget investments", :admin do
check "Winners"
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)
expect(page).to have_link "Calculate Winner Investments"
expect(page).to have_button "Calculate Winner Investments"
select "Accepting projects", from: "Active phase"
click_button "Update Budget"
@@ -513,14 +513,14 @@ describe "Admin budget investments", :admin do
check "Winners"
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", '\
'"Reviewing Ballots" or "Finished budget" in order '\
"to calculate winners projects"
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
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
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).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
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
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("There are no budgets.")
@@ -153,7 +153,7 @@ describe "Admin budgets", :admin do
budget.valuators << create(:valuator)
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 "There are no budgets."
@@ -163,7 +163,7 @@ describe "Admin budgets", :admin do
create(:budget_investment, heading: heading)
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("There is 1 budget")
@@ -173,7 +173,7 @@ describe "Admin budgets", :admin do
create(:poll, budget: 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("There is 1 budget")
@@ -335,7 +335,9 @@ describe "Admin budgets", :admin do
visit edit_admin_budget_path(budget)
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 winner.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_link "Preview"
expect(page).to have_link "Publish budget"
expect(page).to have_button "Publish budget"
end
end