Commit df1507b9 authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by Olena Horal-Koretska

Improve search empty state message

This MR improves empty results page messaging for group and project
searches. We display the group/project name to add more context to the
user.
parent 7f2e4e22
...@@ -92,11 +92,27 @@ module SearchHelper ...@@ -92,11 +92,27 @@ module SearchHelper
end end
end end
def search_entries_empty_message(scope, term) def search_entries_empty_message(scope, term, group, project)
(s_("SearchResults|We couldn't find any %{scope} matching %{term}") % { options = {
scope: search_entries_scope_label(scope, 0), scope: search_entries_scope_label(scope, 0),
term: "<code>#{h(term)}</code>" term: "<code>#{h(term)}</code>".html_safe
}).html_safe }
# We check project first because we have 3 possible combinations here:
# - group && project
# - group
# - group: nil, project: nil
if project
html_escape(_("We couldn't find any %{scope} matching %{term} in project %{project}")) % options.merge(
project: link_to(project.full_name, project_path(project), target: '_blank', rel: 'noopener noreferrer').html_safe
)
elsif group
html_escape(_("We couldn't find any %{scope} matching %{term} in group %{group}")) % options.merge(
group: link_to(group.full_name, group_path(group), target: '_blank', rel: 'noopener noreferrer').html_safe
)
else
html_escape(_("We couldn't find any %{scope} matching %{term}")) % options
end
end end
def repository_ref(project) def repository_ref(project)
......
.search_box .search_box.gl-my-8
.search_glyph .search_glyph
%h4 %h4
= sprite_icon('search', size: 24, css_class: 'gl-vertical-align-text-bottom') = sprite_icon('search', size: 24, css_class: 'gl-vertical-align-text-bottom')
= search_entries_empty_message(@scope, @search_term) = search_entries_empty_message(@scope, @search_term, @group, @project)
---
title: Improve empty search results message for group and project scopes
merge_request: 46237
author:
type: changed
...@@ -23495,9 +23495,6 @@ msgstr "" ...@@ -23495,9 +23495,6 @@ msgstr ""
msgid "SearchResults|Showing %{from} - %{to} of %{count} %{scope} for%{term_element} in your personal and project snippets" msgid "SearchResults|Showing %{from} - %{to} of %{count} %{scope} for%{term_element} in your personal and project snippets"
msgstr "" msgstr ""
msgid "SearchResults|We couldn't find any %{scope} matching %{term}"
msgstr ""
msgid "SearchResults|code result" msgid "SearchResults|code result"
msgid_plural "SearchResults|code results" msgid_plural "SearchResults|code results"
msgstr[0] "" msgstr[0] ""
...@@ -29841,6 +29838,15 @@ msgstr "" ...@@ -29841,6 +29838,15 @@ msgstr ""
msgid "We could not determine the path to remove the issue" msgid "We could not determine the path to remove the issue"
msgstr "" msgstr ""
msgid "We couldn't find any %{scope} matching %{term}"
msgstr ""
msgid "We couldn't find any %{scope} matching %{term} in group %{group}"
msgstr ""
msgid "We couldn't find any %{scope} matching %{term} in project %{project}"
msgstr ""
msgid "We couldn't reach the Prometheus server. Either the server no longer exists or the configuration details need updating." msgid "We couldn't reach the Prometheus server. Either the server no longer exists or the configuration details need updating."
msgstr "" msgstr ""
......
...@@ -236,13 +236,36 @@ RSpec.describe SearchHelper do ...@@ -236,13 +236,36 @@ RSpec.describe SearchHelper do
end end
describe 'search_entries_empty_message' do describe 'search_entries_empty_message' do
let!(:group) { build(:group) }
let!(:project) { build(:project, group: group) }
context 'global search' do
let(:message) { search_entries_empty_message('projects', '<h1>foo</h1>', nil, nil) }
it 'returns the formatted entry message' do
expect(message).to eq("We couldn&#39;t find any projects matching <code>&lt;h1&gt;foo&lt;/h1&gt;</code>")
expect(message).to be_html_safe
end
end
context 'group search' do
let(:message) { search_entries_empty_message('projects', '<h1>foo</h1>', group, nil) }
it 'returns the formatted entry message' do it 'returns the formatted entry message' do
message = search_entries_empty_message('projects', '<h1>foo</h1>') expect(message).to start_with('We couldn&#39;t find any projects matching <code>&lt;h1&gt;foo&lt;/h1&gt;</code> in group <a')
expect(message).to be_html_safe
end
end
expect(message).to eq("We couldn't find any projects matching <code>&lt;h1&gt;foo&lt;/h1&gt;</code>") context 'project search' do
let(:message) { search_entries_empty_message('projects', '<h1>foo</h1>', group, project) }
it 'returns the formatted entry message' do
expect(message).to start_with('We couldn&#39;t find any projects matching <code>&lt;h1&gt;foo&lt;/h1&gt;</code> in project <a')
expect(message).to be_html_safe expect(message).to be_html_safe
end end
end end
end
describe 'search_filter_input_options' do describe 'search_filter_input_options' do
context 'project' do context 'project' 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