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

Fix: Render flat list for groups when filtering #827

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions app/controllers/dashboard/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Dashboard
# Dashboard groups controller
class GroupsController < ApplicationController
before_action :current_page
before_action :render_flat_list, only: %i[index]

def index
@q = build_ransack_query
Expand All @@ -14,8 +15,8 @@ def index

private

def flat_list_requested?
params.dig(:q, :name_or_puid_cont).present?
def render_flat_list
@render_flat_list = params.dig(:q, :name_or_puid_cont).present?
end

def build_ransack_query
Expand Down Expand Up @@ -53,7 +54,7 @@ def toggle_group
end

def authorized_groups
if flat_list_requested?
if @render_flat_list
authorized_scope(Group, type: :relation)
else
authorized_scope(Group, type: :relation).without_descendants
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class GroupsController < Groups::ApplicationController # rubocop:disable Metrics/ClassLength
layout :resolve_layout
before_action :parent_group, only: %i[new]
before_action :tab, only: %i[show]
before_action :tab, :render_flat_list, only: %i[show]
before_action :group, only: %i[activity edit show destroy update transfer]
before_action :authorized_namespaces, except: %i[index show destroy]
before_action :current_page
Expand All @@ -16,7 +16,7 @@ def index
def show
authorize! @group, to: :read?

@q = if flat_list_requested?
@q = if @render_flat_list
namespace_descendants.ransack(params[:q])
else
namespace_children.ransack(params[:q])
Expand Down Expand Up @@ -117,8 +117,8 @@ def set_default_sort
@q.sorts = 'created_at desc' if @q.sorts.empty?
end

def flat_list_requested?
params.dig(:q, :name_or_puid_cont).present?
def render_flat_list
@render_flat_list = params.dig(:q, :name_or_puid_cont).present?
end

def parent_group
Expand Down
1 change: 1 addition & 0 deletions app/views/groups/subgroups/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
group_id: @group.full_path,
},
type: [Group.sti_name, Namespaces::ProjectNamespace.sti_name],
render_flat_list: @render_flat_list,
) %>
<%= render Viral::Pagy::FullComponent.new(@pagy, item: "Subgroups and projects") %>
<% else %>
Expand Down
28 changes: 28 additions & 0 deletions test/system/dashboard/groups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,33 @@ def setup
find('input.t-search-component').native.send_keys(:return)
assert_text I18n.t(:'dashboard.groups.index.no_groups_description')
end

test 'filtering renders flat list' do
group1 = groups(:group_one)
group3 = groups(:group_three)
login_as users(:john_doe)
visit dashboard_groups_url

within('#groups_tree') do
within("#group_#{group1.id}") do
assert_text group1.name
assert_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end

within("#group_#{group3.id}") do
assert_text group3.name
assert_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end
end

fill_in I18n.t(:'dashboard.groups.index.search.placeholder'), with: 'group'
find('input.t-search-component').native.send_keys(:return)

within('#groups_tree') do
assert_text group1.name
assert_text group3.name
assert_no_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end
end
end
end
35 changes: 35 additions & 0 deletions test/system/groups_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,39 @@ def setup

assert_selector 'li.namespace-entry', count: 5
end

test 'filtering renders flat list for subgroups and projects' do
group12 = groups(:group_twelve)
subgroup12a = groups(:subgroup_twelve_a)
subgroup12b = groups(:subgroup_twelve_b)
subgroup12aa = groups(:subgroup_twelve_a_a)

visit group_url(group12)

within('div.namespace-tree-container') do
assert_selector 'li', count: 2
within("#group_#{subgroup12a.id}") do
assert_text subgroup12a.name
assert_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end

within("#group_#{subgroup12b.id}") do
assert_text subgroup12b.name
assert_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end

assert_no_text subgroup12aa.name
end

fill_in I18n.t(:'general.search.name_puid'), with: 'subgroup'
find('input.t-search-component').native.send_keys(:return)

within('div.namespace-tree-container') do
assert_selector 'li', count: 3
assert_text subgroup12a.name
assert_text subgroup12b.name
assert_text subgroup12aa.name
assert_no_selector 'svg[class="Viral-Icon__Svg icon-chevron_right"]'
end
end
end
Loading