Extract methods in toggle selection component

This commit is contained in:
Javi Martín
2021-08-20 02:08:25 +02:00
parent 3cebce9a29
commit 3febe3f0cc
2 changed files with 27 additions and 15 deletions

View File

@@ -1 +1 @@
<%= link_to_toggle_proposal_selection %> <%= link_to text, path, options %>

View File

@@ -5,22 +5,34 @@ class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
@proposal = proposal @proposal = proposal
end end
def link_to_toggle_proposal_selection private
if proposal.selected?
button_text = t("admin.proposals.index.selected") def text
html_class = "button expanded" if proposal.selected?
else t("admin.proposals.index.selected")
button_text = t("admin.proposals.index.select") else
html_class = "button hollow expanded" t("admin.proposals.index.select")
end
end end
case proposal.class.to_s def path
when "Proposal" case proposal.class.to_s
path = toggle_selection_admin_proposal_path(proposal) when "Proposal"
when "Legislation::Proposal" toggle_selection_admin_proposal_path(proposal)
path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal) when "Legislation::Proposal"
toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal)
end
end end
link_to button_text, path, remote: true, method: :patch, class: html_class def options
end { remote: true, method: :patch, class: html_class }
end
def html_class
if proposal.selected?
"button expanded"
else
"button hollow expanded"
end
end
end end