Commit 21a2701e authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '262640-search-results-return-no-results-when-the-pagination-window-is-outside-the-filtered-results' into 'master'

Reset the pagination cursor upon search filter changes

See merge request gitlab-org/gitlab!45708
parents facb15c0 e0538e3e
......@@ -43,7 +43,15 @@ export default {
return this.filterData.filters.ANY.value;
},
set(filter) {
visitUrl(setUrlParams({ [this.filterData.filterParam]: filter }));
// we need to remove the pagination cursor to ensure the
// relevancy of the new results
visitUrl(
setUrlParams({
page: null,
[this.filterData.filterParam]: filter,
}),
);
},
},
selectedFilterText() {
......
......@@ -62,7 +62,9 @@ class SearchService
end
def search_objects(preload_method = nil)
@search_objects ||= redact_unauthorized_results(search_results.objects(scope, page: params[:page], per_page: per_page, preload_method: preload_method))
@search_objects ||= redact_unauthorized_results(
search_results.objects(scope, page: page, per_page: per_page, preload_method: preload_method)
)
end
def search_highlight
......@@ -71,6 +73,10 @@ class SearchService
private
def page
[1, params[:page].to_i].max
end
def per_page
per_page_param = params[:per_page].to_i
......
---
title: Reset the pagination cursor when a search result filter changes.
merge_request: 45708
author:
type: fixed
......@@ -106,6 +106,7 @@ describe('DropdownFilter', () => {
firstDropDownItem().vm.$emit('click');
expect(urlUtils.setUrlParams).toHaveBeenCalledWith({
page: null,
[stateFilterData.filterParam]: filter,
});
});
......@@ -183,6 +184,7 @@ describe('DropdownFilter', () => {
firstDropDownItem().vm.$emit('click');
expect(urlUtils.setUrlParams).toHaveBeenCalledWith({
page: null,
[confidentialFilterData.filterParam]: filter,
});
});
......
......@@ -18,9 +18,10 @@ RSpec.describe SearchService do
let(:group_project) { create(:project, group: accessible_group, name: 'group_project') }
let(:public_project) { create(:project, :public, name: 'public_project') }
let(:page) { 1 }
let(:per_page) { described_class::DEFAULT_PER_PAGE }
subject(:search_service) { described_class.new(user, search: search, scope: scope, page: 1, per_page: per_page) }
subject(:search_service) { described_class.new(user, search: search, scope: scope, page: page, per_page: per_page) }
before do
accessible_project.add_maintainer(user)
......@@ -242,10 +243,10 @@ RSpec.describe SearchService do
end
describe '#search_objects' do
context 'handling per_page param' do
let(:search) { '' }
let(:scope) { nil }
let(:search) { '' }
let(:scope) { nil }
describe 'per_page: parameter' do
context 'when nil' do
let(:per_page) { nil }
......@@ -312,6 +313,34 @@ RSpec.describe SearchService do
end
end
describe 'page: parameter' do
context 'when < 1' do
let(:page) { 0 }
it "defaults to 1" do
expect_any_instance_of(Gitlab::SearchResults)
.to receive(:objects)
.with(anything, hash_including(page: 1))
.and_call_original
subject.search_objects
end
end
context 'when nil' do
let(:page) { nil }
it "defaults to 1" do
expect_any_instance_of(Gitlab::SearchResults)
.to receive(:objects)
.with(anything, hash_including(page: 1))
.and_call_original
subject.search_objects
end
end
end
context 'with accessible project_id' do
it 'returns objects in the project' do
search_objects = described_class.new(
......
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