Commit ea4e17e2 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Search subgroups on dashboard and explore views

parent 3a4dc55f
module GroupTree
def render_group_tree(groups)
# Only show root groups if no parent-id is given
@groups = groups.where(parent_id: params[:parent_id])
@groups = @groups.search(params[:filter]) if params[:filter].present?
if params[:filter].present?
@groups = Gitlab::GroupHierarchy.new(groups).all_groups
@groups = @groups.search(params[:filter])
else
# Only show root groups if no parent-id is given
@groups = groups.where(parent_id: params[:parent_id])
end
@groups = @groups.includes(:route)
@groups = @groups.sort(@sort = params[:sort])
@groups = @groups.page(params[:page])
......@@ -12,6 +16,7 @@ module GroupTree
format.json do
serializer = GroupChildSerializer.new(current_user: current_user)
.with_pagination(request, response)
serializer.expand_hierarchy if params[:filter].present?
render json: serializer.represent(@groups)
end
end
......
......@@ -5,7 +5,8 @@ describe GroupTree do
let(:user) { create(:user) }
controller(ApplicationController) do
include GroupTree # rubocop:disable Rspec/DescribedClass
# `described_class` is not available in this context
include GroupTree # rubocop:disable RSpec/DescribedClass
def index
render_group_tree Group.all
......@@ -43,6 +44,14 @@ describe GroupTree do
expect(assigns(:groups)).to contain_exactly(subgroup)
end
it 'allows filtering for subgroups' do
subgroup = create(:group, :public, parent: group, name: 'filter')
get :index, filter: 'filt', format: :json
expect(assigns(:groups)).to contain_exactly(subgroup)
end
end
context 'json content' do
......@@ -51,6 +60,19 @@ describe GroupTree do
expect(json_response.first['id']).to eq(group.id)
end
context 'nested groups', :nested_groups do
it 'expands the tree when filtering' do
subgroup = create(:group, :public, parent: group, name: 'filter')
get :index, filter: 'filt', format: :json
children_response = json_response.first['children']
expect(json_response.first['id']).to eq(group.id)
expect(children_response.first['id']).to eq(subgroup.id)
end
end
end
end
end
......@@ -20,5 +20,4 @@ describe Explore::GroupsController do
expect(assigns(:groups)).to contain_exactly(member_of_group, public_group)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment