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
end
end
def search_entries_empty_message(scope, term)
(s_("SearchResults|We couldn't find any %{scope} matching %{term}") % {
def search_entries_empty_message(scope, term, group, project)
options = {
scope: search_entries_scope_label(scope, 0),
term: "<code>#{h(term)}</code>"
}).html_safe
term: "<code>#{h(term)}</code>".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
def repository_ref(project)
......
.search_box
.search_box.gl-my-8
.search_glyph
%h4
= 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 ""
msgid "SearchResults|Showing %{from} - %{to} of %{count} %{scope} for%{term_element} in your personal and project snippets"
msgstr ""
msgid "SearchResults|We couldn't find any %{scope} matching %{term}"
msgstr ""
msgid "SearchResults|code result"
msgid_plural "SearchResults|code results"
msgstr[0] ""
......@@ -29841,6 +29838,15 @@ msgstr ""
msgid "We could not determine the path to remove the issue"
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."
msgstr ""
......
......@@ -236,13 +236,36 @@ RSpec.describe SearchHelper do
end
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
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
end
end
end
describe 'search_filter_input_options' 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