Skip to content

Commit c87c153

Browse files
Merge pull request #1601 from projectblacklight/1600-expand-component
Extract an expand hierarchy button component
2 parents 27a8a24 + 61e64ee commit c87c153

6 files changed

Lines changed: 56 additions & 15 deletions

File tree

app/components/arclight/document_components_hierarchy_component.html.erb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,17 @@
22
<%# render the hierarchy as: outer (left) window ... window ... because our current document hierarchy is so far down the list it'd be buried %>
33
<%= helpers.turbo_frame_tag "al-hierarchy-#{@document.id}-left", loading: 'lazy', src: hierarchy_path(limit: @left_outer_window, key: '-left') %>
44
<%= tag.turbo_frame id: "al-hierarchy-#{@document.id}-gap" do %>
5-
<ul>
6-
<li>
7-
<%= link_to t('arclight.views.show.expand'), hierarchy_path(offset: @left_outer_window, limit: @target_index - @left_outer_window - (@window / 2), key: '-gap'), class: 'btn btn-secondary btn-sm' %>
8-
</li>
9-
</ul>
5+
<%= render expand_hierarchy_component.new(path: hierarchy_path(offset: @left_outer_window, limit: @target_index - @left_outer_window - (@window / 2), key: '-gap')) %>
106
<% end %>
117
<%= helpers.turbo_frame_tag "al-hierarchy-#{@document.id}-window", src: hierarchy_path(offset: @target_index - (@window / 2), limit: @window, key: '-window') %>
128
<%= tag.turbo_frame id: "al-hierarchy-#{@document.id}-right" do %>
13-
<ul>
14-
<li>
15-
<%= link_to t('arclight.views.show.expand'), hierarchy_path(offset: @target_index + (@window / 2), key: '-right'), class: 'btn btn-secondary btn-sm' %>
16-
</li>
17-
</ul>
9+
<%= render expand_hierarchy_component.new(path: hierarchy_path(offset: @target_index + (@window / 2), key: '-right')) %>
1810
<% end %>
1911
<% elsif paginate? %>
2012
<%# render the first N documents, and let the user expand the remaining if desired %>
2113
<%= helpers.turbo_frame_tag "al-hierarchy-#{@document.id}-sidebar", loading: ('lazy' unless @target_index >= 0), src: hierarchy_path(limit: @maximum_left_gap, key: '-sidebar') %>
2214
<%= tag.turbo_frame id: "al-hierarchy-#{@document.id}-right" do %>
23-
<ul>
24-
<li>
25-
<%= link_to t('arclight.views.show.expand'), hierarchy_path(offset: @maximum_left_gap, key: '-right'), class: 'btn btn-secondary btn-sm' %>
26-
</li>
27-
</ul>
15+
<%= render expand_hierarchy_component.new(path: hierarchy_path(offset: @maximum_left_gap, key: '-right')) %>
2816
<% end %>
2917
<% else %>
3018
<%# there aren't enough to bother paginating, so load them all at once %>

app/components/arclight/document_components_hierarchy_component.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ def paginate?
2424
def hierarchy_path(**kwargs)
2525
helpers.hierarchy_solr_document_path(id: @document.id, hierarchy: true, nest_path: params[:nest_path], **kwargs)
2626
end
27+
28+
def expand_hierarchy_component
29+
blacklight_config.show.expand_hierarchy_component || Arclight::ExpandHierarchyButtonComponent
30+
end
31+
32+
delegate :blacklight_config, to: :helpers
2733
end
2834
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<li>
3+
<%= expand_link %>
4+
</li>
5+
</ul>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Arclight
4+
# Component for rendering an expand button in the hierarchy view
5+
class ExpandHierarchyButtonComponent < Blacklight::Component
6+
def initialize(path:, classes: 'btn btn-secondary btn-sm')
7+
super
8+
@path = path
9+
@classes = classes
10+
end
11+
12+
def expand_link
13+
link_to t('arclight.views.show.expand'), @path, class: @classes
14+
end
15+
end
16+
end

lib/generators/arclight/templates/catalog_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CatalogController < ApplicationController
7878
config.show.embed_component = Arclight::EmbedComponent
7979
config.show.access_component = Arclight::AccessComponent
8080
config.show.online_status_component = Arclight::OnlineStatusIndicatorComponent
81+
config.show.expand_hierarchy_component = Arclight::ExpandHierarchyButtonComponent
8182
config.show.display_type_field = 'level_ssm'
8283
# config.show.thumbnail_field = 'thumbnail_path_ss'
8384
config.show.document_presenter_class = Arclight::ShowPresenter
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Arclight::ExpandHierarchyButtonComponent, type: :component do
6+
subject(:component) { described_class.new(path: '/some/path') }
7+
8+
before do
9+
render_inline(component)
10+
end
11+
12+
it 'renders the button' do
13+
expect(page).to have_text('Expand')
14+
expect(page).to have_css('.btn.btn-secondary.btn-sm')
15+
end
16+
17+
context 'with a custom class' do
18+
subject(:component) { described_class.new(path: '/path/to_file', classes: 'btn btn-primary') }
19+
20+
it 'renders the button with the custom classes' do
21+
expect(page).to have_text('Expand')
22+
expect(page).to have_css('.btn.btn-primary')
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)