Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ea7ee60a
Commit
ea7ee60a
authored
Mar 23, 2021
by
Changzheng Liu
Committed by
Enrique Alcántara
Mar 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the scope in search context from group issue and MR pages
parent
1d49a777
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
2 deletions
+107
-2
app/views/layouts/_search.html.haml
app/views/layouts/_search.html.haml
+1
-1
changelogs/unreleased/287921-default-global-search-tab-inconsistent.yml
...eleased/287921-default-global-search-tab-inconsistent.yml
+5
-0
lib/gitlab/search_context.rb
lib/gitlab/search_context.rb
+4
-1
spec/lib/gitlab/search_context/builder_spec.rb
spec/lib/gitlab/search_context/builder_spec.rb
+29
-0
spec/views/layouts/_search.html.haml_spec.rb
spec/views/layouts/_search.html.haml_spec.rb
+68
-0
No files found.
app/views/layouts/_search.html.haml
View file @
ea7ee60a
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
=
hidden_field_tag
:group_id
,
search_context
.
for_group?
?
search_context
.
group
.
id
:
''
,
class:
'js-search-group-options'
,
data:
search_context
.
group_metadata
=
hidden_field_tag
:group_id
,
search_context
.
for_group?
?
search_context
.
group
.
id
:
''
,
class:
'js-search-group-options'
,
data:
search_context
.
group_metadata
=
hidden_field_tag
:project_id
,
search_context
.
for_project?
?
search_context
.
project
.
id
:
''
,
id:
'search_project_id'
,
class:
'js-search-project-options'
,
data:
search_context
.
project_metadata
=
hidden_field_tag
:project_id
,
search_context
.
for_project?
?
search_context
.
project
.
id
:
''
,
id:
'search_project_id'
,
class:
'js-search-project-options'
,
data:
search_context
.
project_metadata
-
if
search_context
.
for_project?
-
if
search_context
.
for_project?
||
search_context
.
for_group?
=
hidden_field_tag
:scope
,
search_context
.
scope
=
hidden_field_tag
:scope
,
search_context
.
scope
=
hidden_field_tag
:search_code
,
search_context
.
code_search?
=
hidden_field_tag
:search_code
,
search_context
.
code_search?
...
...
changelogs/unreleased/287921-default-global-search-tab-inconsistent.yml
0 → 100644
View file @
ea7ee60a
---
title
:
Set the scope in search context from group issue and MR pages
merge_request
:
56383
author
:
type
:
other
lib/gitlab/search_context.rb
View file @
ea7ee60a
...
@@ -129,7 +129,10 @@ module Gitlab
...
@@ -129,7 +129,10 @@ module Gitlab
'wiki_blobs'
'wiki_blobs'
elsif
view_context
.
current_controller?
(
:commits
)
elsif
view_context
.
current_controller?
(
:commits
)
'commits'
'commits'
else
nil
elsif
view_context
.
current_controller?
(
:groups
)
if
%w(issues merge_requests)
.
include?
(
view_context
.
controller
.
action_name
)
view_context
.
controller
.
action_name
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/search_context/builder_spec.rb
View file @
ea7ee60a
...
@@ -127,6 +127,35 @@ RSpec.describe Gitlab::SearchContext::Builder, type: :controller do
...
@@ -127,6 +127,35 @@ RSpec.describe Gitlab::SearchContext::Builder, type: :controller do
it
{
is_expected
.
to
be_for_group
}
it
{
is_expected
.
to
be_for_group
}
it
{
is_expected
.
to
be_search_context
(
group:
group
)
}
it
{
is_expected
.
to
be_search_context
(
group:
group
)
}
context
'with group scope'
do
let
(
:action_name
)
{
''
}
before
do
allow
(
controller
).
to
receive
(
:controller_name
).
and_return
(
'groups'
)
allow
(
controller
).
to
receive
(
:action_name
).
and_return
(
action_name
)
end
it
'returns nil without groups controller action'
do
expect
(
subject
.
scope
).
to
be
(
nil
)
end
context
'when on issues scope'
do
let
(
:action_name
)
{
'issues'
}
it
'search context returns issues scope'
do
expect
(
subject
.
scope
).
to
be
(
'issues'
)
end
end
context
'when on merge requests scope'
do
let
(
:action_name
)
{
'merge_requests'
}
it
'search context returns issues scope'
do
expect
(
subject
.
scope
).
to
be
(
'merge_requests'
)
end
end
end
end
end
end
end
...
...
spec/views/layouts/_search.html.haml_spec.rb
0 → 100644
View file @
ea7ee60a
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'layouts/_search'
do
let
(
:group
)
{
nil
}
let
(
:project
)
{
nil
}
let
(
:scope
)
{
'issues'
}
let
(
:search_context
)
do
instance_double
(
Gitlab
::
SearchContext
,
project:
project
,
group:
group
,
scope:
scope
,
ref:
nil
,
snippets:
[],
search_url:
'/search'
,
project_metadata:
{},
group_metadata:
{})
end
before
do
allow
(
view
).
to
receive
(
:search_context
).
and_return
(
search_context
)
allow
(
search_context
).
to
receive
(
:code_search?
).
and_return
(
false
)
allow
(
search_context
).
to
receive
(
:for_snippets?
).
and_return
(
false
)
end
shared_examples
'search context scope is set'
do
context
'when on issues'
do
it
'sets scope to issues'
do
render
expect
(
rendered
).
to
have_css
(
"input[name='scope'][value='issues']"
,
count:
1
,
visible:
false
)
end
end
context
'when on merge requests'
do
let
(
:scope
)
{
'merge_requests'
}
it
'sets scope to merge_requests'
do
render
expect
(
rendered
).
to
have_css
(
"input[name='scope'][value='merge_requests']"
,
count:
1
,
visible:
false
)
end
end
end
context
'when doing project level search'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
allow
(
search_context
).
to
receive
(
:for_project?
).
and_return
(
true
)
allow
(
search_context
).
to
receive
(
:for_group?
).
and_return
(
false
)
end
it_behaves_like
'search context scope is set'
end
context
'when doing group level search'
do
let
(
:group
)
{
create
(
:group
)
}
before
do
allow
(
search_context
).
to
receive
(
:for_project?
).
and_return
(
false
)
allow
(
search_context
).
to
receive
(
:for_group?
).
and_return
(
true
)
end
it_behaves_like
'search context scope is set'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment