Commit ffd1231d authored by Etienne Baqué's avatar Etienne Baqué

Merge branch '339279-format-results-tab' into 'master'

Global Search - Limited and Delimited Tab Counts

See merge request gitlab-org/gitlab!69397
parents 9cbf90dd f0040ded
......@@ -3,8 +3,10 @@
module Gitlab
module Elastic
class SearchResults
include ActionView::Helpers::NumberHelper
include Gitlab::Utils::StrongMemoize
ELASTIC_COUNT_LIMIT = 10000
DEFAULT_PER_PAGE = Gitlab::SearchResults::DEFAULT_PER_PAGE
attr_reader :current_user, :query, :public_and_internal_projects, :order_by, :sort, :filters
......@@ -70,21 +72,21 @@ module Gitlab
def formatted_count(scope)
case scope
when 'projects'
projects_count.to_s
elastic_search_limited_counter_with_delimiter(projects_count)
when 'notes'
notes_count.to_s
elastic_search_limited_counter_with_delimiter(notes_count)
when 'blobs'
blobs_count.to_s
elastic_search_limited_counter_with_delimiter(blobs_count)
when 'wiki_blobs'
wiki_blobs_count.to_s
elastic_search_limited_counter_with_delimiter(wiki_blobs_count)
when 'commits'
commits_count.to_s
elastic_search_limited_counter_with_delimiter(commits_count)
when 'issues'
issues_count.to_s
elastic_search_limited_counter_with_delimiter(issues_count)
when 'merge_requests'
merge_requests_count.to_s
elastic_search_limited_counter_with_delimiter(merge_requests_count)
when 'milestones'
milestones_count.to_s
elastic_search_limited_counter_with_delimiter(milestones_count)
end
end
......@@ -339,6 +341,16 @@ module Gitlab
def default_scope
'projects'
end
def elastic_search_limited_counter_with_delimiter(count)
if count.nil?
number_with_delimiter(0)
elsif count >= ELASTIC_COUNT_LIMIT
number_with_delimiter(ELASTIC_COUNT_LIMIT) + '+'
else
number_with_delimiter(count)
end
end
end
end
end
......@@ -9,7 +9,7 @@ module Gitlab
end
def formatted_count(scope)
snippet_titles_count.to_s
elastic_search_limited_counter_with_delimiter(snippet_titles_count)
end
def snippet_titles_count
......
......@@ -43,21 +43,21 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :clean_gitlab_redis_sha
let(:results) { described_class.new(user, 'hello world', limit_project_ids) }
where(:scope, :count_method, :expected) do
'projects' | :projects_count | '1234'
'notes' | :notes_count | '1234'
'blobs' | :blobs_count | '1234'
'wiki_blobs' | :wiki_blobs_count | '1234'
'commits' | :commits_count | '1234'
'issues' | :issues_count | '1234'
'merge_requests' | :merge_requests_count | '1234'
'milestones' | :milestones_count | '1234'
'unknown' | nil | nil
where(:scope, :count_method, :value, :expected) do
'projects' | :projects_count | 0 | '0'
'notes' | :notes_count | 100 | '100'
'blobs' | :blobs_count | 1000 | '1,000'
'wiki_blobs' | :wiki_blobs_count | 1111 | '1,111'
'commits' | :commits_count | 9999 | '9,999'
'issues' | :issues_count | 10000 | '10,000+'
'merge_requests' | :merge_requests_count | 20000 | '10,000+'
'milestones' | :milestones_count | nil | '0'
'unknown' | nil | nil | nil
end
with_them do
it 'returns the expected formatted count' do
expect(results).to receive(count_method).and_return(1234) if count_method
it 'returns the expected formatted count limited and delimited' do
expect(results).to receive(count_method).and_return(value) if count_method
expect(results.formatted_count(scope)).to eq(expected)
end
end
......
......@@ -40,6 +40,26 @@ RSpec.describe Gitlab::Elastic::SnippetSearchResults, :elastic, :clean_gitlab_re
end
end
describe '#formatted_count' do
using RSpec::Parameterized::TableSyntax
where(:value, :expected) do
1 | '1'
9999 | '9,999'
10000 | '10,000+'
20000 | '10,000+'
0 | '0'
nil | '0'
end
with_them do
it 'returns the expected formatted count limited and delimited' do
expect(results).to receive(:snippet_titles_count).and_return(value)
expect(results.formatted_count('snippets')).to eq(expected)
end
end
end
describe '#highlight_map' do
it 'returns the expected highlight map' do
expect(results).to receive(:snippet_titles).and_return([{ _source: { id: 1 }, highlight: 'test <span class="gl-text-gray-900 gl-font-weight-bold">highlight</span>' }])
......
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