diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 1da88b08a..b2badb487 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -56,6 +56,7 @@ @import "sdg_management/**/*"; @import "shared/**/*"; @import "subscriptions"; +@import "users/**/*"; @import "widgets/**/*"; @import "custom"; diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index a9755e38e..60bfe0fb0 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -442,6 +442,14 @@ .button { font-weight: bold; } + + button { + cursor: pointer; + + &:hover { + text-decoration: underline; + } + } } .community-poll { diff --git a/app/assets/stylesheets/debates/mark_featured_action.scss b/app/assets/stylesheets/debates/mark_featured_action.scss new file mode 100644 index 000000000..3684c90b8 --- /dev/null +++ b/app/assets/stylesheets/debates/mark_featured_action.scss @@ -0,0 +1,15 @@ +.debate-show .mark-featured-action { + display: inline; + + &::before { + @include vertical-separator; + } + + form { + display: inline; + } + + button { + @include link; + } +} diff --git a/app/assets/stylesheets/documents/document.scss b/app/assets/stylesheets/documents/document.scss index 54ecd651c..2b217757d 100644 --- a/app/assets/stylesheets/documents/document.scss +++ b/app/assets/stylesheets/documents/document.scss @@ -3,7 +3,7 @@ margin-top: calc(#{$line-height} / 3); } - a:first-of-type { + a { word-wrap: break-word; .document-metadata { @@ -18,4 +18,8 @@ } } } + + button { + cursor: pointer; + } } diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 87a2f08ec..192baa5c2 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1245,7 +1245,7 @@ table { } .button { - margin: 0; + margin-bottom: 0; } } @@ -1543,8 +1543,13 @@ table { } } + .delete-comment-form { + display: inline; + } + .delete-comment { @include has-fa-icon(trash-alt, regular); + cursor: pointer; &:not(:hover):not(:active) { color: $delete; @@ -1943,10 +1948,18 @@ table { .hide-recommendations { color: $text-light; + cursor: pointer; + font-size: $small-font-size; + line-height: inherit; position: absolute; right: 12px; top: -18px; z-index: 2; + + &:focus, + &:hover { + @include anchor-color-hover; + } } // 20. Documents diff --git a/app/assets/stylesheets/users/budget_investment_table_actions.scss b/app/assets/stylesheets/users/budget_investment_table_actions.scss new file mode 100644 index 000000000..37e128101 --- /dev/null +++ b/app/assets/stylesheets/users/budget_investment_table_actions.scss @@ -0,0 +1,3 @@ +.user-budget-investment-table-actions { + @include flex-with-gap($line-height * 0.25); +} diff --git a/app/components/debates/mark_featured_action_component.html.erb b/app/components/debates/mark_featured_action_component.html.erb new file mode 100644 index 000000000..5d7fe6565 --- /dev/null +++ b/app/components/debates/mark_featured_action_component.html.erb @@ -0,0 +1,17 @@ + diff --git a/app/components/debates/mark_featured_action_component.rb b/app/components/debates/mark_featured_action_component.rb new file mode 100644 index 000000000..38e5e59da --- /dev/null +++ b/app/components/debates/mark_featured_action_component.rb @@ -0,0 +1,12 @@ +class Debates::MarkFeaturedActionComponent < ApplicationComponent + attr_reader :debate + use_helpers :can? + + def initialize(debate) + @debate = debate + end + + def render + can? :mark_featured, debate + end +end diff --git a/app/components/documents/document_component.html.erb b/app/components/documents/document_component.html.erb index 1de910081..f31ba2a12 100644 --- a/app/components/documents/document_component.html.erb +++ b/app/components/documents/document_component.html.erb @@ -8,10 +8,10 @@ <% end %> <% if show_destroy_link? && can?(:destroy, document) %> - <%= link_to t("documents.buttons.destroy_document"), - document, - method: :delete, - data: { confirm: t("documents.actions.destroy.confirm") }, - class: "delete" %> + <%= button_to t("documents.buttons.destroy_document"), + document, + method: :delete, + data: { confirm: t("documents.actions.destroy.confirm") }, + class: "delete" %> <% end %> diff --git a/app/components/users/budget_investment_table_actions_component.html.erb b/app/components/users/budget_investment_table_actions_component.html.erb new file mode 100644 index 000000000..a29abf847 --- /dev/null +++ b/app/components/users/budget_investment_table_actions_component.html.erb @@ -0,0 +1,9 @@ +
+ <% if can? :update, investment %> + <%= edit_link %> + <% end %> + + <% if can? :destroy, investment %> + <%= destroy_button %> + <% end %> +
diff --git a/app/components/users/budget_investment_table_actions_component.rb b/app/components/users/budget_investment_table_actions_component.rb new file mode 100644 index 000000000..e3dfb12db --- /dev/null +++ b/app/components/users/budget_investment_table_actions_component.rb @@ -0,0 +1,30 @@ +class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent + attr_reader :investment + use_helpers :can? + + def initialize(investment) + @investment = investment + end + + private + + def edit_link + link_to t("shared.edit"), + edit_budget_investment_path(investment.budget, investment), + "aria-label": action_label(t("shared.edit")), + class: "button hollow" + end + + def destroy_button + button_to t("shared.delete"), + budget_investment_path(investment.budget, investment), + method: :delete, + "aria-label": action_label(t("shared.delete")), + class: "button hollow alert", + data: { confirm: t("users.show.delete_alert") } + end + + def action_label(action_text) + t("shared.actions.label", action: action_text, name: investment.title) + end +end diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 7780d9167..17f5ee0c7 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -5,10 +5,10 @@ <% if can?(:hide, comment) || can?(:hide, comment.user) %> <% if comment.author == current_user %>  •  - <%= link_to t("comments.actions.delete"), - hide_comment_path(comment), - method: :put, remote: true, class: "delete-comment", - data: { confirm: t("comments.actions.confirm_delete") } %> + <%= button_to t("comments.actions.delete"), + hide_comment_path(comment), + method: :put, remote: true, class: "delete-comment", form_class: "delete-comment-form", + data: { confirm: t("comments.actions.confirm_delete") } %> <% else %> <%= render Shared::ModerationActionsComponent.new(comment) %> <% end %> diff --git a/app/views/dashboard/polls/_poll.html.erb b/app/views/dashboard/polls/_poll.html.erb index 26fe74c28..4c3eca69d 100644 --- a/app/views/dashboard/polls/_poll.html.erb +++ b/app/views/dashboard/polls/_poll.html.erb @@ -27,10 +27,10 @@ <% end %>

<%= t("dashboard.polls.poll.show_results_help") %>

- <%= link_to t("dashboard.polls.poll.delete"), - proposal_dashboard_poll_path(proposal, poll), - method: :delete, - "data-confirm": t("dashboard.polls.poll.alert_notice"), - class: "delete" %> + <%= button_to t("dashboard.polls.poll.delete"), + proposal_dashboard_poll_path(proposal, poll), + method: :delete, + "data-confirm": t("dashboard.polls.poll.alert_notice"), + class: "delete" %> diff --git a/app/views/debates/_actions.html.erb b/app/views/debates/_actions.html.erb index d3e64148b..99a4f7931 100644 --- a/app/views/debates/_actions.html.erb +++ b/app/views/debates/_actions.html.erb @@ -1,18 +1,2 @@ <%= render Shared::ModerationActionsComponent.new(debate) %> - -<% if can? :mark_featured, debate %> -  |  - <% if debate.featured? %> - <%= link_to t("admin.actions.unmark_featured").capitalize, unmark_featured_debate_path(debate), - method: :put, - data: { confirm: t("admin.actions.confirm_action", - action: t("admin.actions.unmark_featured"), - name: debate.title) } %> - <% else %> - <%= link_to t("admin.actions.mark_featured").capitalize, mark_featured_debate_path(debate), - method: :put, - data: { confirm: t("admin.actions.confirm_action", - action: t("admin.actions.mark_featured"), - name: debate.title) } %> - <% end %> -<% end %> +<%= render Debates::MarkFeaturedActionComponent.new(debate) %> diff --git a/app/views/management/users/_erase_user_account.html.erb b/app/views/management/users/_erase_user_account.html.erb index 5746e103a..f7089203a 100644 --- a/app/views/management/users/_erase_user_account.html.erb +++ b/app/views/management/users/_erase_user_account.html.erb @@ -5,5 +5,5 @@ <%= t("management.users.erase_warning") %> - <%= link_to t("management.users.erase_submit"), erase_management_users_path, method: :delete, class: "button hollow alert", data: { confirm: t("management.users.erase_account_confirm") } %> + <%= button_to t("management.users.erase_submit"), erase_management_users_path, method: :delete, class: "button hollow alert", data: { confirm: t("management.users.erase_account_confirm") } %> diff --git a/app/views/shared/_recommended_index.html.erb b/app/views/shared/_recommended_index.html.erb index 4447a9ae4..eb3783d58 100644 --- a/app/views/shared/_recommended_index.html.erb +++ b/app/views/shared/_recommended_index.html.erb @@ -5,13 +5,13 @@
- <%= link_to disable_recommendations_path, title: t("shared.recommended_index.hide"), - class: "float-right-medium small hide-recommendations", - data: { - toggle: "recommendations", - confirm: t("#{namespace}.index.recommendations.disable") - }, - method: :put do %> + <%= button_to disable_recommendations_path, title: t("shared.recommended_index.hide"), + class: "hide-recommendations", + data: { + toggle: "recommendations", + confirm: t("#{namespace}.index.recommendations.disable") + }, + method: :put do %> <%= t("shared.recommended_index.hide") %> <% end %> diff --git a/app/views/users/_budget_investment.html.erb b/app/views/users/_budget_investment.html.erb index 7c9dc0fec..81377519c 100644 --- a/app/views/users/_budget_investment.html.erb +++ b/app/views/users/_budget_investment.html.erb @@ -3,14 +3,6 @@ <%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %> - <% if can? :update, budget_investment %> - <%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment), - class: "button hollow" %> - <% end %> - <% if can? :destroy, budget_investment %> - <%= link_to t("shared.delete"), budget_investment_path(budget_investment.budget, budget_investment), - method: :delete, class: "button hollow alert", - data: { confirm: t("users.show.delete_alert") } %> - <% end %> + <%= render Users::BudgetInvestmentTableActionsComponent.new(budget_investment) %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 5168cbd9d..95a9db662 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -644,6 +644,8 @@ en: show: back: "Go back to my content" shared: + actions: + label: "%{action} %{name}" edit: "Edit" filter: "Filter" save: "Save" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index e8bf22da2..05071f11f 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -644,6 +644,8 @@ es: show: back: "Volver a mi contenido" shared: + actions: + label: "%{action} %{name}" edit: "Editar" filter: "Filtrar" save: "Guardar" diff --git a/spec/components/users/budget_investment_table_actions_component_spec.rb b/spec/components/users/budget_investment_table_actions_component_spec.rb new file mode 100644 index 000000000..400721f8a --- /dev/null +++ b/spec/components/users/budget_investment_table_actions_component_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +describe Users::BudgetInvestmentTableActionsComponent do + let(:user) { create(:user, :level_two) } + let(:budget) { create(:budget, :accepting) } + let(:investment) { create(:budget_investment, budget: budget, author: user, title: "User investment") } + + describe "#edit_link" do + it "generates an aria-label attribute" do + sign_in(user) + + render_inline Users::BudgetInvestmentTableActionsComponent.new(investment) + + expect(page).to have_link count: 1 + expect(page).to have_link "Edit" + expect(page).to have_css "a[aria-label='Edit User investment']" + end + end + + describe "#destroy_button" do + it "generates an aria-label attribute" do + sign_in(user) + + render_inline Users::BudgetInvestmentTableActionsComponent.new(investment) + + expect(page).to have_button count: 1 + expect(page).to have_button "Delete" + expect(page).to have_css "button[aria-label='Delete User investment']" + end + end +end diff --git a/spec/shared/system/documentable.rb b/spec/shared/system/documentable.rb index ad6727671..3f7177573 100644 --- a/spec/shared/system/documentable.rb +++ b/spec/shared/system/documentable.rb @@ -25,27 +25,27 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, scenario "Should not be able when no user logged in" do visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end scenario "Should be able when documentable author is logged in" do login_as documentable.author visit send(documentable_path, arguments) - expect(page).to have_link("Delete document") + expect(page).to have_button "Delete document" end scenario "Administrators cannot destroy documentables they have not authored", :admin do visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end scenario "Users cannot destroy documentables they have not authored" do login_as(create(:user)) visit send(documentable_path, arguments) - expect(page).not_to have_link("Delete document") + expect(page).not_to have_button "Delete document" end end @@ -93,7 +93,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end expect(page).to have_content "Document was deleted successfully." @@ -105,7 +105,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end expect(page).not_to have_content "Documents (0)" @@ -117,7 +117,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, visit send(documentable_path, arguments) within "#document_#{document.id}" do - accept_confirm { click_link "Delete document" } + accept_confirm { click_button "Delete document" } end within "##{ActionView::RecordIdentifier.dom_id(documentable)}" do diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 31ac65b28..f9a08fdda 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -1170,7 +1170,7 @@ describe "Budget Investments" do within("#budget_investment_#{investment1.id}") do expect(page).to have_content(investment1.title) - accept_confirm { click_link("Delete") } + accept_confirm { click_button "Delete" } end expect(page).to have_content "Investment project deleted successfully" diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index c8a33de68..0702c1b2c 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -336,16 +336,16 @@ describe "Comments" do visit polymorphic_path(resource) accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do - within(".comment-body", text: "This was a mistake") { click_link "Delete comment" } + within(".comment-body", text: "This was a mistake") { click_button "Delete comment" } end expect(page).not_to have_content "This was a mistake" - expect(page).not_to have_link "Delete comment" + expect(page).not_to have_button "Delete comment" refresh expect(page).not_to have_content "This was a mistake" - expect(page).not_to have_link "Delete comment" + expect(page).not_to have_button "Delete comment" logout login_as(admin) @@ -363,7 +363,7 @@ describe "Comments" do visit polymorphic_path(resource) accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do - within(".comment-body", text: "Wrong comment") { click_link "Delete comment" } + within(".comment-body", text: "Wrong comment") { click_button "Delete comment" } end within "#comments > .comment-list > li", text: "Right reply" do diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb index 0f7d3d61b..0620cdcf3 100644 --- a/spec/system/dashboard/polls_spec.rb +++ b/spec/system/dashboard/polls_spec.rb @@ -199,7 +199,7 @@ describe "Polls" do visit proposal_dashboard_polls_path(proposal) within("#poll_#{poll.id}") do - accept_confirm { click_link "Delete survey" } + accept_confirm { click_button "Delete survey" } end expect(page).to have_content("Survey deleted successfully") @@ -214,7 +214,7 @@ describe "Polls" do visit proposal_dashboard_polls_path(proposal) within("#poll_#{poll.id}") do - accept_confirm { click_link "Delete survey" } + accept_confirm { click_button "Delete survey" } end expect(page).to have_content("You cannot destroy a survey that has responses") diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index 68d5de88c..7496e10af 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -521,7 +521,7 @@ describe "Debates" do expect(page).to have_content("Medium") expect(page).to have_css(".recommendation", count: 3) - accept_confirm { click_link "Hide recommendations" } + accept_confirm { click_button "Hide recommendations" } end expect(page).not_to have_link("recommendations") @@ -748,7 +748,7 @@ describe "Debates" do end click_link debate.title - accept_confirm("Are you sure? Featured") { click_link "Featured" } + accept_confirm("Are you sure? Featured") { click_button "Featured" } within("#debates") do expect(page).to have_content "FEATURED" @@ -760,7 +760,7 @@ describe "Debates" do click_link debate.title end - accept_confirm("Are you sure? Unmark featured") { click_link "Unmark featured" } + accept_confirm("Are you sure? Unmark featured") { click_button "Unmark featured" } within("#debates") do expect(page).not_to have_content "FEATURED" diff --git a/spec/system/management/users_spec.rb b/spec/system/management/users_spec.rb index 2291e9f56..fccf14b29 100644 --- a/spec/system/management/users_spec.rb +++ b/spec/system/management/users_spec.rb @@ -82,7 +82,7 @@ describe "Users" do expect(page).to have_content "This user can participate in the website with the following permissions" click_link "Delete user" - accept_confirm { click_link "Delete account" } + accept_confirm { click_button "Delete account" } expect(page).to have_content "User account deleted." diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 459f7c619..4ea70abe0 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -937,7 +937,7 @@ describe "Proposals" do expect(page).to have_content("Medium") expect(page).to have_css(".recommendation", count: 3) - accept_confirm { click_link "Hide recommendations" } + accept_confirm { click_button "Hide recommendations" } end expect(page).not_to have_link("recommendations") diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index 34e3c19c4..c6ddd1d4e 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -131,12 +131,12 @@ describe "Users" do expect(page).to have_link budget_investment.title within("#budget_investment_#{budget_investment.id}") do - dismiss_confirm { click_link "Delete" } + dismiss_confirm { click_button "Delete" } end expect(page).to have_link budget_investment.title within("#budget_investment_#{budget_investment.id}") do - accept_confirm { click_link "Delete" } + accept_confirm { click_button "Delete" } end expect(page).not_to have_link budget_investment.title end diff --git a/spec/system/valuation/budget_investments_spec.rb b/spec/system/valuation/budget_investments_spec.rb index 3d542abb1..7b0727730 100644 --- a/spec/system/valuation/budget_investments_spec.rb +++ b/spec/system/valuation/budget_investments_spec.rb @@ -410,7 +410,7 @@ describe "Valuation budget investments" do visit valuation_budget_budget_investment_path(budget, investment) click_link "Edit dossier" - accept_confirm { find_field("budget_investment[valuation_finished]").click } + accept_confirm { check "Valuation finished" } click_button "Save changes" expect(page).to have_content "Dossier updated"