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

Sidebar display fixes #1442

Merged
merged 1 commit into from
Nov 4, 2024
Merged

Sidebar display fixes #1442

merged 1 commit into from
Nov 4, 2024

Conversation

thatbudakguy
Copy link
Member

@thatbudakguy thatbudakguy commented Oct 31, 2024

  • Refactor sidebar component and combine secondary portions

Before:

Screenshot 2024-10-31 at 13 15 12

After:

Screenshot 2024-10-31 at 13 15 16

Part of #1437

@thatbudakguy thatbudakguy marked this pull request as ready for review October 31, 2024 20:30
@@ -0,0 +1,23 @@
<div class="card relations relationship-<%= relationship_type.downcase %>">
<div class="card-header">
<h2 class="h4"><%= t("#{rel_type_info.label}") %></h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<h2 class="h4"><%= t("#{rel_type_info.label}") %></h2>
<h2 class="h4"><%= t(rel_type_info.label) %></h2>

]
end

# Second section of the sidebar that displays below the main one
def secondary_components
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to secondary_components_or_partials, or perhaps we can make RelationsContainerComponent? so that these are all components.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I do that in Geoblacklight as part of a refactor to RelationsComponent? It seems like that's most of what you would like to see anyway. I can change the name of the method for now, if you like.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we do uniq here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure – I just extracted this from the template into a method. Doesn't seem like we could conceivably duplicate a component, so I'll remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

</div>

<ul class="list-group list-group-flush">
<% relationship_type_results['docs'][0..2].map { |hash| SolrDocument.new(hash) }.each do |doc| %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this code out of the template and into a method in the class?

<% end %>
</li>
<% end %>
<% unless (relationship_type_results['numFound'].to_i <= 3) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move relationship_type_results['numFound'] to a method on the class? It can be used on line 18 too.

<% end %>
<% unless (relationship_type_results['numFound'].to_i <= 3) %>
<li class="list-group-item border-bottom-0">
<%= link_to search_catalog_path({f: {"#{Settings.RELATIONSHIPS_SHOWN.public_send(relationship_type).field}" => [relations.link_id]}}) do %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this line to a method too?

@@ -0,0 +1,3 @@
<%- Settings.RELATIONSHIPS_SHOWN.each do |relationship_type, rel_type_info| %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this partial called from?

@thatbudakguy
Copy link
Member Author

@jcoyne just so you're aware – RelationsComponent is a near-exact copy of Geoblacklight's RelationsComponent; all I wanted was to change a single CSS class in the template. If you want me to refactor it, I can, but that seems orthogonal to this PR.

@thatbudakguy
Copy link
Member Author

I went ahead and removed the commit in this PR dealing with RelationsComponent; hopefully that makes it easier to review.

<% if filtered_components.any? %>
<div class="bg-fog-light component-container rounded mt-4">
<%= filtered_components.join(separator).html_safe %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use safe_join here?

Suggested change
<%= filtered_components.join(separator).html_safe %>
<%= safe_join(filtered_components, separator) %>

<hr style="border-top: dotted 1px;" />
<% end %>
<%= tools %>
<%= filtered_components.join(separator).html_safe %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<%= filtered_components.join(separator).html_safe %>
<%= safe_join filtered_components, separator %>

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
@thatbudakguy
Copy link
Member Author

Thanks for the tip re: safe_join; updated

@jcoyne jcoyne merged commit 6bde5d7 into main Nov 4, 2024
2 checks passed
@jcoyne jcoyne deleted the sidebar-display branch November 4, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants