Skip to content

Commit

Permalink
Refactor sidebar component and combine secondary portions
Browse files Browse the repository at this point in the history
This refactors the sidebar component to make it easier to determine
what is being rendered in each of the two sections and to render
it without accidentally duplicating the divider elements.

It also ensures that items that should be grouped together in the
second section are displayed in a single box, as noted in #1437.

Fixes #1437
  • Loading branch information
thatbudakguy committed Nov 1, 2024
1 parent 42e61f7 commit 5fb83a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
14 changes: 6 additions & 8 deletions app/components/also_available_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div class="mt-3 bg-fog-light component-container rounded">
<h2 class="h4">Also available at</h2>
<ul class="list-unstyled">
<% also_available_links.each do |label, url| %>
<li><%= link_to label, url %></li>
<% end %>
</ul>
</div>
<h2 class="h4">Also available at</h2>
<ul class="list-unstyled">
<% also_available_links.each do |label, url| %>
<li><%= link_to label, url %></li>
<% end %>
</ul>
22 changes: 9 additions & 13 deletions app/components/document/sidebar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<% filtered_components = components.map{|component | render component }.uniq.compact_blank %>
<% tools = render_show_tools %>
<% if filtered_components.any? || tools.present? %>
<% filtered_components = filter_components(components) %>
<% if filtered_components.any? %>
<div class="bg-fog-light component-container rounded">
<%= filtered_components.join('<hr style="border-top: dotted 1px;" />').html_safe if filtered_components.any? %>
<% if filtered_components.any? && tools.present? %>
<hr style="border-top: dotted 1px;" />
<% end %>
<%= tools %>
<%= safe_join filtered_components, separator %>
</div>
<% end %>

<%= render AlsoAvailableComponent.new(document:) %>

<div class="mt-4">
<%= render Blacklight::Document::MoreLikeThisComponent.new(document:) %>
</div>
<% filtered_components = filter_components(secondary_components) %>
<% if filtered_components.any? %>
<div class="bg-fog-light component-container rounded mt-4">
<%= safe_join filtered_components, separator %>
</div>
<% end %>
23 changes: 22 additions & 1 deletion app/components/document/sidebar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
# Render the sidebar on the show view
module Document
class SidebarComponent < Geoblacklight::Document::SidebarComponent
# Primary section of the sidebar that displays at the top
def components
[
Geoblacklight::LoginLinkComponent.new(document:),
Geoblacklight::StaticMapComponent.new(document:),
DownloadLinksComponent.new(document:)
DownloadLinksComponent.new(document:),
Blacklight::Document::ShowToolsComponent.new(document:)
]
end

# Second section of the sidebar that displays below the main one
def secondary_components
[
AlsoAvailableComponent.new(document:),
'relations_container',
Blacklight::Document::MoreLikeThisComponent.new(document:)
]
end

# Determine if there's actually anything to show by rendering everything
def filter_components(components)
components.map { |component| render component, document: }.compact_blank
end

# Rendered in between each component
def separator
content_tag :hr, nil, style: 'border-top: dotted 1px;'
end
end
end

0 comments on commit 5fb83a5

Please sign in to comment.