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
e72a08a1
Commit
e72a08a1
authored
Dec 01, 2020
by
Dmitry Gruzd
Committed by
Denys Mishunov
Dec 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix empty results status
parent
5eab3096
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
127 additions
and
57 deletions
+127
-57
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+6
-28
app/presenters/search_service_presenter.rb
app/presenters/search_service_presenter.rb
+43
-0
app/views/search/_results.html.haml
app/views/search/_results.html.haml
+1
-20
app/views/search/_results_status.html.haml
app/views/search/_results_status.html.haml
+25
-0
app/views/search/_sort_dropdown.html.haml
app/views/search/_sort_dropdown.html.haml
+0
-2
changelogs/unreleased/249713-empty-results-status-fix.yml
changelogs/unreleased/249713-empty-results-status-fix.yml
+5
-0
ee/spec/frontend/fixtures/search.rb
ee/spec/frontend/fixtures/search.rb
+1
-1
locale/gitlab.pot
locale/gitlab.pot
+3
-3
spec/frontend/fixtures/search.rb
spec/frontend/fixtures/search.rb
+2
-2
spec/presenters/search_service_presenter_spec.rb
spec/presenters/search_service_presenter_spec.rb
+34
-0
spec/views/search/_results.html.haml_spec.rb
spec/views/search/_results.html.haml_spec.rb
+7
-1
No files found.
app/controllers/search_controller.rb
View file @
e72a08a1
...
@@ -3,16 +3,8 @@
...
@@ -3,16 +3,8 @@
class
SearchController
<
ApplicationController
class
SearchController
<
ApplicationController
include
ControllerWithCrossProjectAccessCheck
include
ControllerWithCrossProjectAccessCheck
include
SearchHelper
include
SearchHelper
include
RendersCommits
include
RedisTracking
include
RedisTracking
SCOPE_PRELOAD_METHOD
=
{
projects: :with_web_entity_associations
,
issues: :with_web_entity_associations
,
merge_requests: :with_web_entity_associations
,
epics: :with_web_entity_associations
}.
freeze
track_redis_hll_event
:show
,
name:
'i_search_total'
,
feature: :search_track_unique_users
,
feature_default_enabled:
true
track_redis_hll_event
:show
,
name:
'i_search_total'
,
feature: :search_track_unique_users
,
feature_default_enabled:
true
around_action
:allow_gitaly_ref_name_caching
around_action
:allow_gitaly_ref_name_caching
...
@@ -41,14 +33,12 @@ class SearchController < ApplicationController
...
@@ -41,14 +33,12 @@ class SearchController < ApplicationController
@search_term
=
params
[
:search
]
@search_term
=
params
[
:search
]
@sort
=
params
[
:sort
]
||
default_sort
@sort
=
params
[
:sort
]
||
default_sort
@scope
=
search_service
.
scope
@search_service
=
Gitlab
::
View
::
Presenter
::
Factory
.
new
(
search_service
,
current_user:
current_user
).
fabricate!
@show_snippets
=
search_service
.
show_snippets?
@scope
=
@search_service
.
scope
@search_results
=
search_service
.
search_results
@show_snippets
=
@search_service
.
show_snippets?
@search_objects
=
search_service
.
search_objects
(
preload_method
)
@search_results
=
@search_service
.
search_results
@search_highlight
=
search_service
.
search_highlight
@search_objects
=
@search_service
.
search_objects
@search_highlight
=
@search_service
.
search_highlight
render_commits
if
@scope
==
'commits'
eager_load_user_status
if
@scope
==
'users'
increment_search_counters
increment_search_counters
end
end
...
@@ -79,10 +69,6 @@ class SearchController < ApplicationController
...
@@ -79,10 +69,6 @@ class SearchController < ApplicationController
private
private
def
preload_method
SCOPE_PRELOAD_METHOD
[
@scope
.
to_sym
]
end
# overridden in EE
# overridden in EE
def
default_sort
def
default_sort
'created_desc'
'created_desc'
...
@@ -102,14 +88,6 @@ class SearchController < ApplicationController
...
@@ -102,14 +88,6 @@ class SearchController < ApplicationController
true
true
end
end
def
render_commits
@search_objects
=
prepare_commits_for_rendering
(
@search_objects
)
end
def
eager_load_user_status
@search_objects
=
@search_objects
.
eager_load
(
:status
)
# rubocop:disable CodeReuse/ActiveRecord
end
def
check_single_commit_result?
def
check_single_commit_result?
return
false
if
params
[
:force_search_results
]
return
false
if
params
[
:force_search_results
]
return
false
unless
@project
.
present?
return
false
unless
@project
.
present?
...
...
app/presenters/search_service_presenter.rb
0 → 100644
View file @
e72a08a1
# frozen_string_literal: true
class
SearchServicePresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
include
RendersCommits
presents
:search_service
SCOPE_PRELOAD_METHOD
=
{
projects: :with_web_entity_associations
,
issues: :with_web_entity_associations
,
merge_requests: :with_web_entity_associations
,
epics: :with_web_entity_associations
}.
freeze
SORT_ENABLED_SCOPES
=
%w(issues merge_requests)
.
freeze
def
search_objects
@search_objects
||=
begin
objects
=
search_service
.
search_objects
(
SCOPE_PRELOAD_METHOD
[
scope
.
to_sym
])
case
scope
when
'users'
objects
.
eager_load
(
:status
)
# rubocop:disable CodeReuse/ActiveRecord
when
'commits'
prepare_commits_for_rendering
(
objects
)
else
objects
end
end
end
def
show_sort_dropdown?
SORT_ENABLED_SCOPES
.
include?
(
scope
)
end
def
show_results_status?
!
without_count?
||
show_snippets?
||
show_sort_dropdown?
end
def
without_count?
search_objects
.
is_a?
(
Kaminari
::
PaginatableWithoutCount
)
end
end
app/views/search/_results.html.haml
View file @
e72a08a1
...
@@ -6,26 +6,7 @@
...
@@ -6,26 +6,7 @@
=
render
partial:
"search/results/empty"
=
render
partial:
"search/results/empty"
=
render_if_exists
'shared/promotions/promote_advanced_search'
=
render_if_exists
'shared/promotions/promote_advanced_search'
-
else
-
else
.search-results-status
=
render
partial:
'search/results_status'
,
locals:
{
search_service:
@search_service
}
.row-content-block.gl-display-flex
.gl-display-md-flex.gl-text-left.gl-align-items-center.gl-flex-grow-1
-
unless
@search_objects
.
is_a?
(
Kaminari
::
PaginatableWithoutCount
)
=
search_entries_info
(
@search_objects
,
@scope
,
@search_term
)
-
unless
@show_snippets
-
if
@project
-
link_to_project
=
link_to
(
@project
.
full_name
,
@project
,
class:
'ml-md-1'
)
-
if
@scope
==
'blobs'
=
s_
(
"SearchCodeResults|in"
)
.mx-md-1
=
render
partial:
"shared/ref_switcher"
,
locals:
{
ref:
repository_ref
(
@project
),
form_path:
request
.
fullpath
,
field_name:
'repository_ref'
}
=
s_
(
'SearchCodeResults|of %{link_to_project}'
).
html_safe
%
{
link_to_project:
link_to_project
}
-
else
=
_
(
"in project %{link_to_project}"
).
html_safe
%
{
link_to_project:
link_to_project
}
-
elsif
@group
-
link_to_group
=
link_to
(
@group
.
name
,
@group
,
class:
'ml-md-1'
)
=
_
(
"in group %{link_to_group}"
).
html_safe
%
{
link_to_group:
link_to_group
}
.gl-display-md-flex.gl-flex-direction-column
=
render
partial:
'search/sort_dropdown'
=
render_if_exists
'shared/promotions/promote_advanced_search'
=
render_if_exists
'shared/promotions/promote_advanced_search'
.results.gl-display-md-flex.gl-mt-3
.results.gl-display-md-flex.gl-mt-3
...
...
app/views/search/_results_status.html.haml
0 → 100644
View file @
e72a08a1
-
search_service
=
local_assigns
.
fetch
(
:search_service
)
-
return
unless
search_service
.
show_results_status?
.search-results-status
.row-content-block.gl-display-flex
.gl-display-md-flex.gl-text-left.gl-align-items-center.gl-flex-grow-1
-
unless
search_service
.
without_count?
=
search_entries_info
(
search_service
.
search_objects
,
search_service
.
scope
,
params
[
:search
])
-
unless
search_service
.
show_snippets?
-
if
search_service
.
project
-
link_to_project
=
link_to
(
search_service
.
project
.
full_name
,
search_service
.
project
,
class:
'ml-md-1'
)
-
if
search_service
.
scope
==
'blobs'
=
_
(
"in"
)
.mx-md-1
=
render
partial:
"shared/ref_switcher"
,
locals:
{
ref:
repository_ref
(
search_service
.
project
),
form_path:
request
.
fullpath
,
field_name:
'repository_ref'
}
=
s_
(
'SearchCodeResults|of %{link_to_project}'
).
html_safe
%
{
link_to_project:
link_to_project
}
-
else
=
_
(
"in project %{link_to_project}"
).
html_safe
%
{
link_to_project:
link_to_project
}
-
elsif
search_service
.
group
-
link_to_group
=
link_to
(
search_service
.
group
.
name
,
search_service
.
group
,
class:
'ml-md-1'
)
=
_
(
"in group %{link_to_group}"
).
html_safe
%
{
link_to_group:
link_to_group
}
-
if
search_service
.
show_sort_dropdown?
.gl-display-md-flex.gl-flex-direction-column
=
render
partial:
'search/sort_dropdown'
app/views/search/_sort_dropdown.html.haml
View file @
e72a08a1
-
return
unless
[
'issues'
,
'merge_requests'
].
include?
(
@scope
)
-
sort_value
=
@sort
-
sort_value
=
@sort
-
sort_title
=
search_sort_option_title
(
sort_value
)
-
sort_title
=
search_sort_option_title
(
sort_value
)
...
...
changelogs/unreleased/249713-empty-results-status-fix.yml
0 → 100644
View file @
e72a08a1
---
title
:
'
Search
page:
fix
empty
results
status'
merge_request
:
48034
author
:
type
:
fixed
ee/spec/frontend/fixtures/search.rb
View file @
e72a08a1
...
@@ -57,7 +57,7 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
...
@@ -57,7 +57,7 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
it
'ee/search/blob_search_result.html'
do
it
'ee/search/blob_search_result.html'
do
expect_next_instance_of
(
SearchService
)
do
|
search_service
|
expect_next_instance_of
(
SearchService
)
do
|
search_service
|
expect
(
search_service
).
to
receive
(
:search_objects
).
and_return
(
blobs
)
allow
(
search_service
).
to
receive
(
:search_objects
).
and_return
(
blobs
)
end
end
get
:show
,
params:
{
get
:show
,
params:
{
...
...
locale/gitlab.pot
View file @
e72a08a1
...
@@ -23874,9 +23874,6 @@ msgstr ""
...
@@ -23874,9 +23874,6 @@ msgstr ""
msgid "SearchAutocomplete|in project %{projectName}"
msgid "SearchAutocomplete|in project %{projectName}"
msgstr ""
msgstr ""
msgid "SearchCodeResults|in"
msgstr ""
msgid "SearchCodeResults|of %{link_to_project}"
msgid "SearchCodeResults|of %{link_to_project}"
msgstr ""
msgstr ""
...
@@ -32238,6 +32235,9 @@ msgstr ""
...
@@ -32238,6 +32235,9 @@ msgstr ""
msgid "import flow"
msgid "import flow"
msgstr ""
msgstr ""
msgid "in"
msgstr ""
msgid "in group %{link_to_group}"
msgid "in group %{link_to_group}"
msgstr ""
msgstr ""
...
...
spec/frontend/fixtures/search.rb
View file @
e72a08a1
...
@@ -67,8 +67,8 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
...
@@ -67,8 +67,8 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
end
end
it
'search/blob_search_result.html'
do
it
'search/blob_search_result.html'
do
expect_next_instance_of
(
SearchService
)
do
|
search_service
|
allow_next_instance_of
(
SearchServicePresenter
)
do
|
search_service
|
expect
(
search_service
).
to
receive
(
:search_objects
).
and_return
(
blobs
)
allow
(
search_service
).
to
receive
(
:search_objects
).
and_return
(
blobs
)
end
end
get
:show
,
params:
{
get
:show
,
params:
{
...
...
spec/presenters/search_service_presenter_spec.rb
0 → 100644
View file @
e72a08a1
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
SearchServicePresenter
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:search_service
)
{
SearchService
.
new
(
user
,
search:
search
,
scope:
scope
)
}
let
(
:presenter
)
{
described_class
.
new
(
search_service
,
current_user:
user
)
}
describe
'#show_results_status?'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:search
)
{
''
}
let
(
:scope
)
{
nil
}
before
do
allow
(
presenter
).
to
receive
(
:search_objects
).
and_return
([])
allow
(
presenter
).
to
receive
(
:without_count?
).
and_return
(
!
with_count
)
allow
(
presenter
).
to
receive
(
:show_snippets?
).
and_return
(
show_snippets
)
allow
(
presenter
).
to
receive
(
:show_sort_dropdown?
).
and_return
(
show_sort_dropdown
)
end
where
(
:with_count
,
:show_snippets
,
:show_sort_dropdown
,
:result
)
do
true
|
true
|
true
|
true
false
|
true
|
false
|
true
false
|
false
|
true
|
true
false
|
false
|
false
|
false
end
with_them
do
it
{
expect
(
presenter
.
show_results_status?
).
to
eq
(
result
)
}
end
end
end
spec/views/search/_results.html.haml_spec.rb
View file @
e72a08a1
...
@@ -3,17 +3,23 @@
...
@@ -3,17 +3,23 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
'search/_results'
do
RSpec
.
describe
'search/_results'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:search_objects
)
{
Issue
.
page
(
1
).
per
(
2
)
}
let
(
:search_objects
)
{
Issue
.
page
(
1
).
per
(
2
)
}
let
(
:scope
)
{
'issues'
}
let
(
:scope
)
{
'issues'
}
let
(
:term
)
{
'foo'
}
before
do
before
do
controller
.
params
[
:action
]
=
'show'
controller
.
params
[
:action
]
=
'show'
controller
.
params
[
:search
]
=
term
create_list
(
:issue
,
3
)
create_list
(
:issue
,
3
)
@search_objects
=
search_objects
@search_objects
=
search_objects
@scope
=
scope
@scope
=
scope
@search_term
=
'foo'
@search_term
=
term
@search_service
=
SearchServicePresenter
.
new
(
SearchService
.
new
(
user
,
search:
term
,
scope:
scope
))
allow
(
@search_service
).
to
receive
(
:search_objects
).
and_return
(
search_objects
)
end
end
it
'displays the page size'
do
it
'displays the page size'
do
...
...
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