Skip to content

Commit

Permalink
Add kind filters to dependent_packages page #796
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 24, 2024
1 parent 8ae1df3 commit af9d7d6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/controllers/packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def dependent_packages
end
end

scope = @package.dependent_packages.includes(:registry)
if params[:latest].present?
scope = @package.latest_dependent_packages(kind: params[:kind]).includes(:registry)
else
scope = @package.dependent_packages(kind: params[:kind]).includes(:registry)
end

if params[:sort].present? || params[:order].present?
sort = params[:sort] || 'updated_at'
sort = "(repo_metadata ->> 'stargazers_count')::text::integer" if params[:sort] == 'stargazers_count'
Expand All @@ -78,6 +83,8 @@ def dependent_packages
scope = scope.order('latest_release_published_at DESC')
end

@kinds = @package.dependent_package_kinds

@pagy, @dependent_packages = pagy_countless(scope)
fresh_when(@dependent_packages, public: true)
end
Expand Down
26 changes: 24 additions & 2 deletions app/views/packages/dependent_packages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@
<%= render 'tabs' %>

<% if @dependent_packages.any? %>
<%= render @dependent_packages %>
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages && @pagy.pages > 1 %>
<div class='row'>
<div class='col-md-9'>
<%= render @dependent_packages %>
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages && @pagy.pages > 1 %>
</div>
<div class='col-md-3'>
<div class='card'>
<div class='card-header'>
Filter by kind
</div>
<div class='list-group list-group-flush'>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if params[:kind].blank? %>" href="<%= dependent_packages_registry_package_path(@registry, @package) %>">
All kinds
</a>
<% @kinds.each do |kind, count| %>
<a class="list-group-item list-group-item-action d-flex justify-content-between align-items-center <%= 'active' if params[:kind] == kind %>" href="<%= dependent_packages_registry_package_path(@registry, @package, kind: kind) %>">
<%= kind %>
<span class='badge bg-primary rounded-pill'><%= count %></span>
</a>
<% end %>
</div>
</div>
</div>
</div>
<% else %>
<div class="alert alert-info" role="alert">
No dependent packages found.
Expand Down

0 comments on commit af9d7d6

Please sign in to comment.