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

Draft: Don't load all hierarchical items at once when expanding the tree #1492

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Display expand buttons one at a time
  • Loading branch information
lfarrell committed Dec 15, 2023
commit ce30f5935e6d659a893bb98b1dd16dac6c2b61fd
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ $hierarchy-view-collapse-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3
background: $mark-bg;
}

li.collapse .al-hierarchy-more {
display: none;
}

li.collapse.show .al-hierarchy-more {
display: block;
.al-hierarchy-more {
margin-bottom: 5px;
}


#collection-context {
ul {
list-style: none;

padding-left: 1.5rem;

ul {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,38 @@
<% elsif paginate? %>
<%# render the first N documents, and let the user expand the remaining if desired %>
<%= helpers.turbo_frame_tag "al-hierarchy-#{@document.id}-sidebar", loading: ('lazy' unless @target_index >= 0), src: hierarchy_path(limit: @maximum_left_gap, key: '-sidebar') %>
<div id="al-hierarchy-additional-pages">
<% num_pages.each do |page| %>
<%= tag.turbo_frame id: "al-hierarchy-#{@document.id}-right", class: "al-hierarchy-more" do %>
<ul>
<% hidden = 'd-none' unless page == 1 %>
<%= tag.turbo_frame class:"#{hidden}", id: "al-hierarchy-#{@document.id}-#{page}-right" do %>
<ul class="al-hierarchy-more" >
<li>
<%= link_to "\"#{@document.normalized_title.truncate(25, seperator: ' ')}\" Items #{more_text(page)}", hierarchy_path(offset: get_offset(page), limit: @maximum_left_gap, key: '-right'), class: 'btn btn-secondary btn-sm' %>
<%= link_to t('arclight.views.show.expand'), hierarchy_path(offset: get_offset(page), limit: @maximum_left_gap, key: "-#{page}-right"),
id: "al-hierarchy-#{@document.id}-#{page}-more", class: 'btn btn-secondary btn-sm' %>
</li>
</ul>
<% end %>
<% end %>
</div>
<% else %>
<%# there aren't enough to bother paginating, so load them all at once %>
<%= helpers.turbo_frame_tag "al-hierarchy-#{@document.id}-sidebar", loading: ('lazy' unless @target_index >= 0), src: hierarchy_path(key: '-sidebar') %>
<% end %>
<script>
(function() {
function showNextLink(e) {
if (e.target.id.startsWith('al-hierarchy') && e.target.id.endsWith('more')) {
const id_pieces = e.target.id.split('-');
const current_page = parseInt(id_pieces[id_pieces.length - 2]);
const next_page = current_page + 1;
const t = e.target.id.replace(`${current_page}-more`, `${next_page}-right`)
document.getElementById(`${t}`).classList.remove('d-none');
}
}

const more_links = document.getElementById('al-hierarchy-additional-pages');
if (more_links !== null) {
more_links.addEventListener('click', showNextLink);
}
})();
</script>
11 changes: 0 additions & 11 deletions app/components/arclight/document_components_hierarchy_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ def get_offset(page)
page * @maximum_left_gap
end

def more_text(page)
offset = get_offset(page)
last_item = offset + (@maximum_left_gap - 1)

if page == num_pages.last
last_item = @document.number_of_children
end

"#{offset + 1} to #{last_item}"
end

def hierarchy_path(**kwargs)
helpers.hierarchy_solr_document_path(id: @document.id, hierarchy: true, nest_path: params[:nest_path], **kwargs)
end
Expand Down
Loading