Commit b54f3cb0 authored by Alper Akgun's avatar Alper Akgun

Merge branch '258209-filters-params-remain-when-switching-tabs' into 'master'

Reset the search filters upon a scope change

See merge request gitlab-org/gitlab!45808
parents 9f498701 b2de4a50
# frozen_string_literal: true # frozen_string_literal: true
module SearchHelper module SearchHelper
SEARCH_PERMITTED_PARAMS = [ SEARCH_GENERIC_PARAMS = [
:search, :search,
:scope, :scope,
:project_id, :project_id,
...@@ -9,8 +9,6 @@ module SearchHelper ...@@ -9,8 +9,6 @@ module SearchHelper
:repository_ref, :repository_ref,
:snippets, :snippets,
:sort, :sort,
:state,
:confidential,
:force_search_results :force_search_results
].freeze ].freeze
...@@ -255,7 +253,7 @@ module SearchHelper ...@@ -255,7 +253,7 @@ module SearchHelper
search_params = params search_params = params
.merge(search) .merge(search)
.merge({ scope: scope }) .merge({ scope: scope })
.permit(SEARCH_PERMITTED_PARAMS) .permit(SEARCH_GENERIC_PARAMS)
if @scope == scope if @scope == scope
li_class = 'active' li_class = 'active'
......
---
title: Reset search results filters whenever a user changes scope.
merge_request: 45808
author:
type: fixed
...@@ -373,6 +373,19 @@ RSpec.describe SearchHelper do ...@@ -373,6 +373,19 @@ RSpec.describe SearchHelper do
expect(link).to have_link('Projects', href: search_path(scope: 'projects', search: 'hello', project_id: 23)) expect(link).to have_link('Projects', href: search_path(scope: 'projects', search: 'hello', project_id: 23))
end end
it 'restricts the params' do
expect(self).to receive(:params).and_return(
ActionController::Parameters.new(
search: 'hello',
unknown: 42
)
)
link = search_filter_link('projects', 'Projects')
expect(link).to have_link('Projects', href: search_path(scope: 'projects', search: 'hello'))
end
it 'assigns given data attributes on the list container' do it 'assigns given data attributes on the list container' do
link = search_filter_link('projects', 'Projects', data: { foo: 'bar' }) link = search_filter_link('projects', 'Projects', data: { foo: 'bar' })
......
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