summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Slaughter <pslaughter@gitlab.com>2019-08-07 07:21:58 -0500
committerPaul Slaughter <pslaughter@gitlab.com>2019-08-07 07:34:12 -0500
commit889f891cf637251a7134b1b6f641d9fe10ed8945 (patch)
tree20755b7617dd9739e74133c546a7e14d94b7723b
parent84e7bc765c42643e8d1b30e4030172694f33901a (diff)
downloadgitlab-ce-43990-improve-search-results-page.tar.gz
Improve search empty message with scopes hash43990-improve-search-results-page
There's a lot of duplication in the references to different types of scopes. This commit takes a step towards resolving that duplication by encapsulating the scopes in a hash.
-rw-r--r--app/helpers/search_helper.rb59
-rw-r--r--app/views/search/_category.html.haml28
-rw-r--r--app/views/search/results/_empty.html.haml3
-rw-r--r--locale/gitlab.pot32
4 files changed, 105 insertions, 17 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index f5c4686a3bf..efea569de47 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -225,4 +225,63 @@ module SearchHelper
can?(current_user, :read_users_list)
end
end
+
+ def search_scopes
+ {
+ blobs: {
+ label: _("Code"),
+ empty_message: _("We couldn't find any code matching %{term_start}%{search_term}%{term_end}")
+ },
+ issues: {
+ label: _("Issues"),
+ empty_message: _("We couldn't find any issues matching %{term_start}%{search_term}%{term_end}")
+ },
+ merge_requests: {
+ label: _("Merge requests"),
+ empty_message: _("We couldn't find any merge requests matching %{term_start}%{search_term}%{term_end}")
+ },
+ milestones: {
+ label: _("Milestones"),
+ empty_message: _("We couldn't find any milestones matching %{term_start}%{search_term}%{term_end}")
+ },
+ notes: {
+ label: _("Comments"),
+ empty_message: _("We couldn't find any comments matching %{term_start}%{search_term}%{term_end}")
+ },
+ wiki_blobs: {
+ label: _("Wiki"),
+ empty_message: _("We couldn't find any wiki entries matching %{term_start}%{search_term}%{term_end}")
+ },
+ commits: {
+ label: _("Commits"),
+ empty_message: _("We couldn't find any commits matching %{term_start}%{search_term}%{term_end}")
+ },
+ snippet_blobs: {
+ label: _("Snippet Contents"),
+ empty_message: _("We couldn't find any snippet content matching %{term_start}%{search_term}%{term_end}")
+ },
+ snippet_titles: {
+ label: _("Titles and Filenames"),
+ empty_message: _("We couldn't find any snippet names matching %{term_start}%{search_term}%{term_end}")
+ },
+ projects: {
+ label: _("Projects"),
+ empty_message: _("We couldn't find any projects matching %{term_start}%{search_term}%{term_end}")
+ },
+ users: {
+ label: _("Users"),
+ empty_message: _("We couldn't find any users matching %{term_start}%{search_term}%{term_end}")
+ }
+ }
+ end
+
+ def search_scope_label(scope)
+ search_scopes[scope.to_sym][:label]
+ end
+
+ def search_scope_empty_message(scope, search_term)
+ empty_message = search_scopes[scope.to_sym][:empty_message]
+
+ empty_message % { search_term: search_term, term_start: '<code>', term_end: '</code>'}
+ end
end
diff --git a/app/views/search/_category.html.haml b/app/views/search/_category.html.haml
index 18613ff4c16..29c03681e6e 100644
--- a/app/views/search/_category.html.haml
+++ b/app/views/search/_category.html.haml
@@ -2,7 +2,7 @@
- if search_tabs?(:members)
%li{ class: active_when(@scope == 'users') }
= link_to search_filter_path(scope: 'users') do
- Users
+ = search_scope_label(:users)
%span.badge.badge-pill
= limited_count(@search_results.limited_users_count)
@@ -14,43 +14,43 @@
- if project_search_tabs?(:blobs)
%li{ class: active_when(@scope == 'blobs'), data: { qa_selector: 'code_tab' } }
= link_to search_filter_path(scope: 'blobs') do
- = _("Code")
+ = search_scope_label(:blobs)
%span.badge.badge-pill
= @search_results.blobs_count
- if project_search_tabs?(:issues)
%li{ class: active_when(@scope == 'issues') }
= link_to search_filter_path(scope: 'issues') do
- = _("Issues")
+ = search_scope_label(:issues)
%span.badge.badge-pill
= limited_count(@search_results.limited_issues_count)
- if project_search_tabs?(:merge_requests)
%li{ class: active_when(@scope == 'merge_requests') }
= link_to search_filter_path(scope: 'merge_requests') do
- = _("Merge requests")
+ = search_scope_label(:merge_requests)
%span.badge.badge-pill
= limited_count(@search_results.limited_merge_requests_count)
- if project_search_tabs?(:milestones)
%li{ class: active_when(@scope == 'milestones') }
= link_to search_filter_path(scope: 'milestones') do
- = _("Milestones")
+ = search_scope_label(:milestones)
%span.badge.badge-pill
= limited_count(@search_results.limited_milestones_count)
- if project_search_tabs?(:notes)
%li{ class: active_when(@scope == 'notes') }
= link_to search_filter_path(scope: 'notes') do
- = _("Comments")
+ = search_scope_label(:notes)
%span.badge.badge-pill
= limited_count(@search_results.limited_notes_count)
- if project_search_tabs?(:wiki)
%li{ class: active_when(@scope == 'wiki_blobs') }
= link_to search_filter_path(scope: 'wiki_blobs') do
- = _("Wiki")
+ = search_scope_label(:wiki_blobs)
%span.badge.badge-pill
= @search_results.wiki_blobs_count
- if project_search_tabs?(:commits)
%li{ class: active_when(@scope == 'commits') }
= link_to search_filter_path(scope: 'commits') do
- = _("Commits")
+ = search_scope_label(:commits)
%span.badge.badge-pill
= @search_results.commits_count
= users
@@ -58,33 +58,33 @@
- elsif @show_snippets
%li{ class: active_when(@scope == 'snippet_blobs') }
= link_to search_filter_path(scope: 'snippet_blobs', snippets: true, group_id: nil, project_id: nil) do
- = _("Snippet Contents")
+ = search_scope_label(:snippet_blobs)
%span.badge.badge-pill
= @search_results.snippet_blobs_count
%li{ class: active_when(@scope == 'snippet_titles') }
= link_to search_filter_path(scope: 'snippet_titles', snippets: true, group_id: nil, project_id: nil) do
- = _("Titles and Filenames")
+ = search_scope_label(:snippet_titles)
%span.badge.badge-pill
= @search_results.snippet_titles_count
- else
%li{ class: active_when(@scope == 'projects') }
= link_to search_filter_path(scope: 'projects') do
- = _("Projects")
+ = search_scope_label(:projects)
%span.badge.badge-pill
= limited_count(@search_results.limited_projects_count)
%li{ class: active_when(@scope == 'issues') }
= link_to search_filter_path(scope: 'issues') do
- = _("Issues")
+ = search_scope_label(:issues)
%span.badge.badge-pill
= limited_count(@search_results.limited_issues_count)
%li{ class: active_when(@scope == 'merge_requests') }
= link_to search_filter_path(scope: 'merge_requests') do
- = _("Merge requests")
+ = search_scope_label(:merge_requests)
%span.badge.badge-pill
= limited_count(@search_results.limited_merge_requests_count)
%li{ class: active_when(@scope == 'milestones') }
= link_to search_filter_path(scope: 'milestones') do
- = _("Milestones")
+ = search_scope_label(:milestones)
%span.badge.badge-pill
= limited_count(@search_results.limited_milestones_count)
= render_if_exists 'search/category_elasticsearch'
diff --git a/app/views/search/results/_empty.html.haml b/app/views/search/results/_empty.html.haml
index 9d15995bb51..fa6e722993c 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_scope_empty_message(@scope, @search_term).html_safe
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 86317dd887f..37841cf5046 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -12401,7 +12401,37 @@ 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 code matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any comments matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any commits matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any issues matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any merge requests matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any milestones matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any projects matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any snippet content matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any snippet names matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any users matching %{term_start}%{search_term}%{term_end}"
+msgstr ""
+
+msgid "We couldn't find any wiki entries matching %{term_start}%{search_term}%{term_end}"
msgstr ""
msgid "We detected potential spam in the %{humanized_resource_name}. Please solve the reCAPTCHA to proceed."