Commit 6d2c62d4 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch '249713-empty-results-status-fix' into 'master'

Fix empty results status

See merge request gitlab-org/gitlab!48034
parents 1848e5e4 e72a08a1
......@@ -3,16 +3,8 @@
class SearchController < ApplicationController
include ControllerWithCrossProjectAccessCheck
include SearchHelper
include RendersCommits
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
around_action :allow_gitaly_ref_name_caching
......@@ -41,14 +33,12 @@ class SearchController < ApplicationController
@search_term = params[:search]
@sort = params[:sort] || default_sort
@scope = search_service.scope
@show_snippets = search_service.show_snippets?
@search_results = search_service.search_results
@search_objects = search_service.search_objects(preload_method)
@search_highlight = search_service.search_highlight
render_commits if @scope == 'commits'
eager_load_user_status if @scope == 'users'
@search_service = Gitlab::View::Presenter::Factory.new(search_service, current_user: current_user).fabricate!
@scope = @search_service.scope
@show_snippets = @search_service.show_snippets?
@search_results = @search_service.search_results
@search_objects = @search_service.search_objects
@search_highlight = @search_service.search_highlight
increment_search_counters
end
......@@ -79,10 +69,6 @@ class SearchController < ApplicationController
private
def preload_method
SCOPE_PRELOAD_METHOD[@scope.to_sym]
end
# overridden in EE
def default_sort
'created_desc'
......@@ -102,14 +88,6 @@ class SearchController < ApplicationController
true
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?
return false if params[:force_search_results]
return false unless @project.present?
......
# 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
......@@ -6,26 +6,7 @@
= render partial: "search/results/empty"
= render_if_exists 'shared/promotions/promote_advanced_search'
- else
.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_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 partial: 'search/results_status', locals: { search_service: @search_service }
= render_if_exists 'shared/promotions/promote_advanced_search'
.results.gl-display-md-flex.gl-mt-3
......
- 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'
- return unless ['issues', 'merge_requests'].include?(@scope)
- sort_value = @sort
- sort_title = search_sort_option_title(sort_value)
......
---
title: 'Search page: fix empty results status'
merge_request: 48034
author:
type: fixed
......@@ -57,7 +57,7 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
it 'ee/search/blob_search_result.html' do
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
get :show, params: {
......
......@@ -23877,9 +23877,6 @@ msgstr ""
msgid "SearchAutocomplete|in project %{projectName}"
msgstr ""
msgid "SearchCodeResults|in"
msgstr ""
msgid "SearchCodeResults|of %{link_to_project}"
msgstr ""
......@@ -32250,6 +32247,9 @@ msgstr ""
msgid "import flow"
msgstr ""
msgid "in"
msgstr ""
msgid "in group %{link_to_group}"
msgstr ""
......
......@@ -67,8 +67,8 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
end
it 'search/blob_search_result.html' do
expect_next_instance_of(SearchService) do |search_service|
expect(search_service).to receive(:search_objects).and_return(blobs)
allow_next_instance_of(SearchServicePresenter) do |search_service|
allow(search_service).to receive(:search_objects).and_return(blobs)
end
get :show, params: {
......
# 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
......@@ -3,17 +3,23 @@
require 'spec_helper'
RSpec.describe 'search/_results' do
let(:user) { create(:user) }
let(:search_objects) { Issue.page(1).per(2) }
let(:scope) { 'issues' }
let(:term) { 'foo' }
before do
controller.params[:action] = 'show'
controller.params[:search] = term
create_list(:issue, 3)
@search_objects = search_objects
@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
it 'displays the page size' do
......
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