Skip to content

Commit

Permalink
Merge pull request #3360 from projectblacklight/backport-3347
Browse files Browse the repository at this point in the history
Backport: Extract BulkActionsComponent
  • Loading branch information
taylor-steve authored Dec 13, 2024
2 parents 64afc7a + 87a29c5 commit abaaed1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
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

0 comments on commit abaaed1

Please sign in to comment.