Extract component for restore and hide actions
By doing so, we remove a lot of duplication.
This commit is contained in:
12
app/components/admin/hidden_table_actions_component.html.erb
Normal file
12
app/components/admin/hidden_table_actions_component.html.erb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<%= render Admin::TableActionsComponent.new(actions: []) do %>
|
||||||
|
<%= link_to restore_text, restore_path,
|
||||||
|
method: :put,
|
||||||
|
data: { confirm: t("admin.actions.confirm") },
|
||||||
|
class: "button hollow warning" %>
|
||||||
|
|
||||||
|
<% unless record.confirmed_hide? %>
|
||||||
|
<%= link_to confirm_hide_text, confirm_hide_path,
|
||||||
|
method: :put,
|
||||||
|
class: "button" %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
34
app/components/admin/hidden_table_actions_component.rb
Normal file
34
app/components/admin/hidden_table_actions_component.rb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
class Admin::HiddenTableActionsComponent < ApplicationComponent
|
||||||
|
attr_reader :record
|
||||||
|
|
||||||
|
def initialize(record)
|
||||||
|
@record = record
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def restore_text
|
||||||
|
t("admin.actions.restore")
|
||||||
|
end
|
||||||
|
|
||||||
|
def restore_path
|
||||||
|
action_path(:restore)
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_hide_text
|
||||||
|
t("admin.actions.confirm_hide")
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_hide_path
|
||||||
|
action_path(:confirm_hide)
|
||||||
|
end
|
||||||
|
|
||||||
|
def action_path(action)
|
||||||
|
url_for({
|
||||||
|
controller: "admin/hidden_#{record.model_name.plural}",
|
||||||
|
action: action,
|
||||||
|
id: record,
|
||||||
|
only_path: true
|
||||||
|
}.merge(request.query_parameters))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -24,17 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-top">
|
<td class="align-top">
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(investment) %>
|
||||||
restore_admin_hidden_budget_investment_path(investment, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless investment.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_budget_investment_path(investment, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -23,17 +23,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(comment) %>
|
||||||
restore_admin_hidden_comment_path(comment, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless comment.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_comment_path(comment, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -24,17 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-top">
|
<td class="align-top">
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(debate) %>
|
||||||
restore_admin_hidden_debate_path(debate, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless debate.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_debate_path(debate, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -24,17 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-top">
|
<td class="align-top">
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(proposal_notification) %>
|
||||||
restore_admin_hidden_proposal_notification_path(proposal_notification, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless proposal_notification.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_proposal_notification_path(proposal_notification, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -28,17 +28,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-top">
|
<td class="align-top">
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(proposal) %>
|
||||||
restore_admin_hidden_proposal_path(proposal, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless proposal.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_proposal_path(proposal, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -19,17 +19,7 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("admin.actions.restore"),
|
<%= render Admin::HiddenTableActionsComponent.new(user) %>
|
||||||
restore_admin_hidden_user_path(user, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
data: { confirm: t("admin.actions.confirm") },
|
|
||||||
class: "button hollow warning" %>
|
|
||||||
<% unless user.confirmed_hide? %>
|
|
||||||
<%= link_to t("admin.actions.confirm_hide"),
|
|
||||||
confirm_hide_admin_hidden_user_path(user, request.query_parameters),
|
|
||||||
method: :put,
|
|
||||||
class: "button" %>
|
|
||||||
<% end %>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
14
spec/components/admin/hidden_table_actions_component_spec.rb
Normal file
14
spec/components/admin/hidden_table_actions_component_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Admin::HiddenTableActionsComponent, type: :component do
|
||||||
|
let(:record) { create(:user) }
|
||||||
|
let(:component) { Admin::HiddenTableActionsComponent.new(record) }
|
||||||
|
|
||||||
|
it "renders links to restore and confirm hide" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_css "a", count: 2
|
||||||
|
expect(page).to have_css "a[href*='restore'][data-method='put']", text: "Restore"
|
||||||
|
expect(page).to have_css "a[href*='confirm_hide'][data-method='put']", text: "Confirm moderation"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user