diff --git a/app/components/admin/budget_investments/toggle_selection_component.html.erb b/app/components/admin/budget_investments/toggle_selection_component.html.erb index 97d671e67..9d5d3c87e 100644 --- a/app/components/admin/budget_investments/toggle_selection_component.html.erb +++ b/app/components/admin/budget_investments/toggle_selection_component.html.erb @@ -1,16 +1,5 @@ -<% if investment.selected? %> - <%= link_to_if can?(:toggle_selection, investment), - t("admin.budget_investments.index.selected"), - path, - method: :patch, - remote: true, - class: "button small expanded" %> -<% elsif investment.feasible? && investment.valuation_finished? %> - <% if can?(:toggle_selection, investment) %> - <%= link_to t("admin.budget_investments.index.select"), - path, - method: :patch, - remote: true, - class: "button small hollow expanded" %> - <% end %> +<% if can?(:toggle_selection, investment) && investment.feasible? && investment.valuation_finished? %> + <%= link_to text, path, method: :patch, remote: true, class: html_class %> +<% elsif selected? %> + <%= selected_text %> <% end %> diff --git a/app/components/admin/budget_investments/toggle_selection_component.rb b/app/components/admin/budget_investments/toggle_selection_component.rb index 9dd870d86..64d662fd5 100644 --- a/app/components/admin/budget_investments/toggle_selection_component.rb +++ b/app/components/admin/budget_investments/toggle_selection_component.rb @@ -1,6 +1,7 @@ class Admin::BudgetInvestments::ToggleSelectionComponent < ApplicationComponent attr_reader :investment use_helpers :can? + delegate :selected?, to: :investment def initialize(investment) @investment = investment @@ -8,6 +9,18 @@ class Admin::BudgetInvestments::ToggleSelectionComponent < ApplicationComponent private + def text + if selected? + selected_text + else + t("admin.budget_investments.index.select") + end + end + + def selected_text + t("admin.budget_investments.index.selected") + end + def path toggle_selection_admin_budget_budget_investment_path( investment.budget, @@ -20,4 +33,12 @@ class Admin::BudgetInvestments::ToggleSelectionComponent < ApplicationComponent page: params[:page] ) end + + def html_class + if selected? + "button small expanded" + else + "button small hollow expanded" + end + end end