diff options
-rw-r--r-- | app/helpers/search_helper.rb | 11 | ||||
-rw-r--r-- | app/views/search/results/_empty.html.haml | 3 | ||||
-rw-r--r-- | changelogs/unreleased/43990-improve-search-empty-message.yml | 5 | ||||
-rw-r--r-- | locale/gitlab.pot | 2 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 9 |
5 files changed, 25 insertions, 5 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 2e2d324ab62..a4e9dd9584a 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -34,12 +34,12 @@ module SearchHelper from: from, to: to, count: count, - scope: search_entries_info_label(scope, count), + scope: search_entries_scope_label(scope, count), term: term } end - def search_entries_info_label(scope, count) + def search_entries_scope_label(scope, count) case scope when 'blobs', 'snippet_blobs', 'wiki_blobs' ns_('SearchResults|result', 'SearchResults|results', count) @@ -72,6 +72,13 @@ module SearchHelper end end + def search_entries_empty_message(scope, term) + (_("We couldn't find any %{scope} matching %{term}") % { + scope: search_entries_scope_label(scope, 0), + term: "<code>#{term}</code>" + }).html_safe + end + def find_project_for_result_blob(projects, result) @project end diff --git a/app/views/search/results/_empty.html.haml b/app/views/search/results/_empty.html.haml index 9d15995bb51..6c7c6de1178 100644 --- a/app/views/search/results/_empty.html.haml +++ b/app/views/search/results/_empty.html.haml @@ -2,5 +2,4 @@ .search_glyph %h4 = icon('search') - = _("We couldn't find any results matching") - %code= @search_term + = search_entries_empty_message(@scope, @search_term) diff --git a/changelogs/unreleased/43990-improve-search-empty-message.yml b/changelogs/unreleased/43990-improve-search-empty-message.yml new file mode 100644 index 00000000000..7a7ae48a574 --- /dev/null +++ b/changelogs/unreleased/43990-improve-search-empty-message.yml @@ -0,0 +1,5 @@ +--- +title: Use search scope label in empty results message +merge_request: 32660 +author: +type: changed diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 32deab7dd68..8051b9f3f87 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -13031,7 +13031,7 @@ msgstr "" msgid "Want to see the data? Please ask an administrator for access." msgstr "" -msgid "We couldn't find any results matching" +msgid "We couldn't find any %{scope} matching %{term}" msgstr "" msgid "We detected potential spam in the %{humanized_resource_name}. Please solve the reCAPTCHA to proceed." diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index e1dc589236b..43f65feeced 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -140,6 +140,15 @@ describe SearchHelper do end end + describe 'search_entries_empty_message' do + it 'returns the formatted entry message' do + message = search_entries_empty_message('projects', 'foo') + + expect(message).to eq("We couldn't find any projects matching <code>foo</code>") + expect(message).to be_html_safe + end + end + describe 'search_filter_input_options' do context 'project' do before do |