Skip to content

Commit 29d268a

Browse files
authored
Merge pull request #1250 from projectblacklight/extract-collection-sidebar
Extract CollectionSidebarComponent
2 parents 5a4fa00 + c83c8f7 commit 29d268a

File tree

11 files changed

+113
-50
lines changed

11 files changed

+113
-50
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Metrics/BlockLength:
3333
- 'spec/**/*'
3434
- 'tasks/**/*'
3535

36+
Naming/PredicateName:
37+
ForbiddenPrefixes:
38+
- _is
39+
3640
Layout/LineLength:
3741
Max: 160
3842

app/assets/stylesheets/arclight/modules/layout.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,6 @@
9191
}
9292
}
9393

94-
// Show page metadata.
95-
// Indent to match terminal show page breadcrumb.
96-
@for $i from 1 to 20 {
97-
.al-metadata-section.breadcrumb-item-#{$i} {
98-
padding-left: 0;
99-
100-
@media (min-width: 768px) {
101-
padding-left: ($i * 10) + 10px;
102-
}
103-
}
104-
}
105-
10694
.bookmark-toggle .toggle-bookmark {
10795
display: inline;
10896
margin-bottom: 0;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<nav id="about-collection-nav" class="al-sidebar-navigation-context sidebar-section">
2+
<h2><%= t('arclight.views.show.context_nav.title') %></h2>
3+
<ul class='nav flex-column'>
4+
<% partials.each do |section| %>
5+
<% next unless has_section?(section) %>
6+
<li class='nav-item'>
7+
<%= link_to section_label(section),
8+
document_section_path(section),
9+
class: 'nav-link pl-0',
10+
data: { turbolinks: 'false' }
11+
%>
12+
</li>
13+
<% end %>
14+
</ul>
15+
</nav>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
module Arclight
4+
# Draw the links to the collection info in the sidebar
5+
class CollectionSidebarComponent < ViewComponent::Base
6+
def initialize(document:, partials:, collection_presenter:)
7+
super
8+
9+
@document = document
10+
@partials = Array(partials)
11+
@collection_presenter = collection_presenter
12+
end
13+
14+
attr_reader :document, :partials, :collection_presenter
15+
16+
def has_section?(section)
17+
# Access field data comes from repositories.yml not from solr, so handle it in a different way.
18+
return true if section == :access_field
19+
20+
collection_presenter.with_field_group(section).fields_to_render.any?
21+
end
22+
23+
def document_section_path(section)
24+
[document_path, section_anchor(section)].join
25+
end
26+
27+
def section_label(section)
28+
t("arclight.views.show.sections.#{section}")
29+
end
30+
31+
def document_path
32+
@document_path ||= solr_document_path(normalized_eadid)
33+
end
34+
35+
def section_anchor(section)
36+
"##{t("arclight.views.show.sections.#{section}").parameterize}"
37+
end
38+
39+
delegate :normalized_eadid, to: :document
40+
end
41+
end

app/components/arclight/document_component.html.erb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
<% end %>
3131
</div>
3232

33-
<%= render Arclight::MetadataSectionComponent.with_collection(component_metadata_partials, metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent }, presenter: presenter, classes: ['al-metadata-section']) unless document.collection? %>
33+
<%= render Arclight::MetadataSectionComponent.with_collection(component_metadata_partials,
34+
metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent },
35+
presenter: presenter) unless document.collection? %>
3436

3537
<div class='row'>
3638
<div class='col-md-12'>
@@ -41,7 +43,9 @@
4143
<% if document.collection? %>
4244
<div id="metadata">
4345
<h2 class="sr-only visually-hidden"><%= t 'arclight.views.show.context' %></h2>
44-
<%= render Arclight::MetadataSectionComponent.with_collection(metadata_partials, presenter: presenter, heading: true) %>
46+
<%= render Arclight::MetadataSectionComponent.with_collection(metadata_partials,
47+
metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent },
48+
presenter: presenter, heading: true) %>
4549
</div>
4650
<% elsif document.children? %>
4751
<div id="contents">
@@ -52,15 +56,19 @@
5256

5357
<% access_content = capture do %>
5458
<% if @document.collection? %>
55-
<%= render Arclight::MetadataSectionComponent.with_collection(context_access_tab_items, presenter: presenter) %>
59+
<%= render Arclight::MetadataSectionComponent.with_collection(context_access_tab_items,
60+
metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent },
61+
presenter: presenter) %>
5662
<% else %>
57-
<%= render Arclight::MetadataSectionComponent.with_collection(component_access_tab_items, presenter: presenter) %>
63+
<%= render Arclight::MetadataSectionComponent.with_collection(component_access_tab_items,
64+
metadata_attr: { layout: Arclight::UpperMetadataLayoutComponent },
65+
presenter: presenter) %>
5866
<% end %>
5967
<% end %>
6068

6169
<% if access_content.present? %>
62-
<div id="access">
63-
<h2 class="al-show-sub-heading"><%= t 'arclight.views.show.access' %></h2>
70+
<div id="<%= t('arclight.views.show.sections.access_field').parameterize %>">
71+
<h2 class="al-show-sub-heading"><%= t 'arclight.views.show.sections.access_field' %></h2>
6472

6573
<%= access_content%>
6674
</div>

app/components/arclight/upper_metadata_layout_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
module Arclight
4-
# Override upstream to remove bootstrap column classes
4+
# Override upstream to add an offset bootstrap column class
55
class UpperMetadataLayoutComponent < Blacklight::MetadataFieldLayoutComponent
6-
def initialize(field:, label_class: nil, value_class: nil)
6+
def initialize(field:, label_class: 'col-md-3 offset-md-1', value_class: 'col-md-8')
77
super
88
end
99
end

app/views/catalog/_show_sidebar.html.erb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,9 @@
33
</div>
44

55
<%= render 'show_tools' %>
6-
<nav id="about-collection-nav" class="al-sidebar-navigation-context sidebar-section">
7-
<h2><%= t('arclight.views.show.context_nav.title') %></h2>
8-
<ul class='nav flex-column'>
9-
<% unless blacklight_config.show.metadata_partials.nil? %>
10-
<% blacklight_config.show.metadata_partials.each do |item| %>
11-
<% next unless document_presenter(document.collection).with_field_group(item).fields_to_render.any? %>
12-
<li class='nav-item'>
13-
<%= link_to t("arclight.views.show.sections.#{item}"),
14-
[
15-
solr_document_path(document.normalized_eadid),
16-
"##{t("arclight.views.show.sections.#{item}").parameterize}"
17-
].join, class: 'nav-link pl-0', data: { turbolinks: 'false' }
18-
%>
19-
</li>
20-
<% end %>
21-
<% end %>
22-
</ul>
23-
</nav>
6+
<%= render Arclight::CollectionSidebarComponent.new(document: @document,
7+
collection_presenter: document_presenter(@document.collection),
8+
partials: blacklight_config.show.metadata_partials) %>
249

2510
<div id="collection-context" class="sidebar-section">
2611
<h2><%= t('arclight.views.show.has_content') %></h2>

config/locales/arclight.en.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ en:
5252
view_all_collections: View all of our collections
5353
view_more: View more
5454
show:
55-
access: Access
5655
collection_id: 'Collection ID: %{id}'
5756
contents: Contents
5857
context: Collection context

lib/generators/arclight/templates/catalog_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ class CatalogController < ApplicationController
7878
config.show.document_presenter_class = Arclight::ShowPresenter
7979
config.show.metadata_partials = %i[
8080
summary_field
81-
access_field
8281
background_field
8382
related_field
8483
indexed_terms_field
84+
access_field
8585
]
8686

8787
config.show.context_access_tab_items = %i[
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Arclight::CollectionSidebarComponent, type: :component do
6+
subject(:component) do
7+
described_class.new(document: document,
8+
partials: CatalogController.blacklight_config.show.metadata_partials,
9+
collection_presenter: collection_presenter)
10+
end
11+
12+
before do
13+
render_inline(component)
14+
end
15+
16+
let(:document) { instance_double(SolrDocument, normalized_eadid: 'foo') }
17+
let(:collection_presenter) { instance_double(Arclight::ShowPresenter, with_field_group: group_presenter) }
18+
let(:group_presenter) { instance_double(Arclight::ShowPresenter, fields_to_render: [double]) }
19+
20+
it 'has navigation links' do
21+
expect(page).to have_link 'Summary'
22+
expect(page).to have_link 'Background'
23+
expect(page).to have_link 'Related'
24+
expect(page).to have_link 'Indexed Terms'
25+
expect(page).to have_link 'Access and Use'
26+
end
27+
end

0 commit comments

Comments
 (0)