Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract BulkActionsComponent #3347

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/components/spotlight/bulk_action_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="dropdown bulk-actions-dropdown">
<%= button %>
<div class="dropdown-menu" aria-labelledby="bulk-actions-button">
<% bulk_actions.each do |key, _config| %>
<%= link_to t("spotlight.bulk_actions.#{key}.heading"), '#', class: 'dropdown-item', data: { toggle: "modal", "bs-toggle": "modal", target: "##{key.to_s.dasherize}-modal", "bs-target": "##{key.to_s.dasherize}-modal" } %>
<% end %>
</div>
</div>
20 changes: 20 additions & 0 deletions app/components/spotlight/bulk_action_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Spotlight
# Displays the "Bulk actions" button and dropdown
class BulkActionComponent < ViewComponent::Base
def initialize(bulk_actions:, button_classes: 'btn btn-secondary dropdown-toggle')
@bulk_actions = bulk_actions
@button_classes = button_classes
super
end

attr_reader :button_classes, :bulk_actions

def button
button_tag t(:'spotlight.bulk_actions.label'), id: 'bulk-actions-button', class: button_classes,
data: { toggle: 'dropdown', 'bs-toggle': 'dropdown' },
aria: { haspopup: true, expanded: false }
end
end
end
11 changes: 1 addition & 10 deletions app/views/catalog/_bulk_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
<div class="dropdown bulk-actions-dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="bulk-actions-button" data-toggle="dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<%= t(:'spotlight.bulk_actions.label') %>
</button>
<div class="dropdown-menu" aria-labelledby="bulk-actions-button">
<% blacklight_config.bulk_actions.each do |key, _config| %>
<%= link_to t("spotlight.bulk_actions.#{key}.heading"), '#', class: 'dropdown-item', data: { toggle: "modal", "bs-toggle": "modal", target: "##{key.to_s.dasherize}-modal", "bs-target": "##{key.to_s.dasherize}-modal" } %>
<% end %>
</div>
</div>
<%= render Spotlight::BulkActionComponent.new(bulk_actions: blacklight_config.bulk_actions) %>

<%= render_filtered_partials(blacklight_config.bulk_actions) %>
2 changes: 1 addition & 1 deletion spec/features/bulk_actions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe 'Bulk actions', type: :feature do
RSpec.describe 'Bulk actions', type: :feature do
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:curator) { FactoryBot.create(:exhibit_curator, exhibit:) }

Expand Down
Loading