Commit 83310410 authored by Micaël Bergeron's avatar Micaël Bergeron Committed by Jose Ivan Vargas

Display the Advanced Search as disabled when a ref is specified

This commit adds some context on the search page when the
repository_ref parameter is present.
parent ade7aa1c
...@@ -281,6 +281,10 @@ input[type='checkbox']:hover { ...@@ -281,6 +281,10 @@ input[type='checkbox']:hover {
} }
} }
.ref-truncated {
@include str-truncated(10em);
}
// Disable webkit input icons, link to solution: https://stackoverflow.com/questions/9421551/how-do-i-remove-all-default-webkit-search-field-styling // Disable webkit input icons, link to solution: https://stackoverflow.com/questions/9421551/how-do-i-remove-all-default-webkit-search-field-styling
/* stylelint-disable property-no-vendor-prefix */ /* stylelint-disable property-no-vendor-prefix */
input[type='search']::-webkit-search-decoration, input[type='search']::-webkit-search-decoration,
......
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
- page_description(_("%{count} %{scope} for term '%{term}'") % { count: @search_results.formatted_count(@scope), scope: @scope, term: @search_term }) - page_description(_("%{count} %{scope} for term '%{term}'") % { count: @search_results.formatted_count(@scope), scope: @scope, term: @search_term })
- page_card_attributes("Namespace" => @group&.full_path, "Project" => @project&.full_path) - page_card_attributes("Namespace" => @group&.full_path, "Project" => @project&.full_path)
.page-title-holder.d-sm-flex.align-items-sm-center .page-title-holder.d-flex.flex-wrap.justify-content-between
%h1.page-title< %h1.page-title.mr-3= _('Search')
= _('Search') = render_if_exists 'search/form_elasticsearch', attrs: { class: 'mb-2 mb-sm-0 align-self-center' }
= render_if_exists 'search/form_elasticsearch', attrs: { class: 'ml-sm-auto' }
.gl-mt-3 .gl-mt-3
= render 'search/form' = render 'search/form'
......
...@@ -4,6 +4,7 @@ module EE ...@@ -4,6 +4,7 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
SWITCH_TO_BASIC_SEARCHABLE_TABS = %w[projects issues merge_requests milestones users epics].freeze SWITCH_TO_BASIC_SEARCHABLE_TABS = %w[projects issues merge_requests milestones users epics].freeze
PLACEHOLDER = '_PLACEHOLDER_'
override :search_filter_input_options override :search_filter_input_options
def search_filter_input_options(type, placeholder = _('Search or filter results...')) def search_filter_input_options(type, placeholder = _('Search or filter results...'))
...@@ -70,6 +71,40 @@ module EE ...@@ -70,6 +71,40 @@ module EE
Truncato.truncate(search_highlight[issue.id].description.first, count_tags: false, count_tail: false, max_length: 200).html_safe Truncato.truncate(search_highlight[issue.id].description.first, count_tags: false, count_tail: false, max_length: 200).html_safe
end end
def advanced_search_status_marker(project)
ref = params[:repository_ref]
enabled = project.nil? || ref.blank? || ref == project.default_branch
tags = {}
tags[:doc_link_start], tags[:doc_link_end] = tag.a(PLACEHOLDER,
href: help_page_path('user/search/advanced_search_syntax.md'),
rel: :noopener,
target: '_blank')
.split(PLACEHOLDER)
unless enabled
tags[:ref_elem] = tag.a(href: '#', class: 'ref-truncated has-tooltip', data: { title: ref }) do
tag.code(ref, class: 'gl-white-space-nowrap')
end
tags[:default_branch] = tag.code(project.default_branch)
tags[:default_branch_link_start], tags[:default_branch_link_end] = link_to(PLACEHOLDER,
search_path(safe_params.except(:repository_ref)),
data: { testid: 'es-search-default-branch' })
.split(PLACEHOLDER)
end
# making sure all the tags are marked `html_safe`
message =
if enabled
_('%{doc_link_start}Advanced search%{doc_link_end} is enabled.')
else
_('%{doc_link_start}Advanced search%{doc_link_end} is disabled since %{ref_elem} is not the default branch; %{default_branch_link_start}search on %{default_branch} instead%{default_branch_link_end}.')
end % tags.transform_values(&:html_safe)
# wrap it inside a `div` for testing purposes
tag.div(message.html_safe, data: { testid: 'es-status-marker', enabled: enabled })
end
private private
def search_multiple_assignees?(type) def search_multiple_assignees?(type)
......
- if search_service.use_elasticsearch? - if search_service.use_elasticsearch?
.form-text.text-muted{ **local_assigns.fetch(:attrs, {}) } .form-text.text-muted{ **local_assigns.fetch(:attrs, {}) }
= link_to _('Advanced search functionality'), help_page_path('user/search/advanced_search_syntax.md'), target: '_blank' = advanced_search_status_marker(@project)
= _('is enabled.')
---
title: Show that Advanced Search is disabled when searching in a specific ref.
merge_request: 43612
author:
type: fixed
...@@ -8,14 +8,16 @@ RSpec.describe 'Project elastic search', :js, :elastic do ...@@ -8,14 +8,16 @@ RSpec.describe 'Project elastic search', :js, :elastic do
before do before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
project.add_maintainer(user)
sign_in(user)
visit project_path(project)
end end
describe 'searching' do describe 'searching' do
before do
project.add_maintainer(user)
sign_in(user)
visit project_path(project)
end
it 'finds issues', :sidekiq_inline do it 'finds issues', :sidekiq_inline do
create(:issue, project: project, title: 'Test searching for an issue') create(:issue, project: project, title: 'Test searching for an issue')
ensure_elasticsearch_index! ensure_elasticsearch_index!
...@@ -84,6 +86,44 @@ RSpec.describe 'Project elastic search', :js, :elastic do ...@@ -84,6 +86,44 @@ RSpec.describe 'Project elastic search', :js, :elastic do
expect(page).to have_selector('.results', text: 'def username_regex') expect(page).to have_selector('.results', text: 'def username_regex')
end end
end end
describe 'displays Advanced Search status' do
before do
sign_in(user)
visit search_path(project_id: project.id, repository_ref: repository_ref)
end
context "when `repository_ref` isn't the default branch" do
let(:repository_ref) { Gitlab::Git::BLANK_SHA }
it 'displays that advanced search is disabled' do
expect(page).to have_selector('[data-testid="es-status-marker"][data-enabled="false"]')
default_branch_link = page.find('a[data-testid="es-search-default-branch"]')
params = CGI.parse(URI.parse(default_branch_link[:href]).query)
expect(default_branch_link).to have_content(project.default_branch)
expect(params).not_to include(:repository_ref)
end
end
context "when `repository_ref` is unset" do
let(:repository_ref) { "" }
it 'displays that advanced search is enabled' do
expect(page).to have_selector('[data-testid="es-status-marker"][data-enabled="true"]')
end
end
context "when `repository_ref` is the default branch" do
let(:repository_ref) { project.default_branch }
it 'displays that advanced search is enabled' do
expect(page).to have_selector('[data-testid="es-status-marker"][data-enabled="true"]')
end
end
end
end end
RSpec.describe 'Project elastic search redactions', :elastic do RSpec.describe 'Project elastic search redactions', :elastic do
......
...@@ -447,6 +447,12 @@ msgstr "" ...@@ -447,6 +447,12 @@ msgstr ""
msgid "%{description}- Sentry event: %{errorUrl}- First seen: %{firstSeen}- Last seen: %{lastSeen} %{countLabel}: %{count}%{userCountLabel}: %{userCount}" msgid "%{description}- Sentry event: %{errorUrl}- First seen: %{firstSeen}- Last seen: %{lastSeen} %{countLabel}: %{count}%{userCountLabel}: %{userCount}"
msgstr "" msgstr ""
msgid "%{doc_link_start}Advanced search%{doc_link_end} is disabled since %{ref_elem} is not the default branch; %{default_branch_link_start}search on %{default_branch} instead%{default_branch_link_end}."
msgstr ""
msgid "%{doc_link_start}Advanced search%{doc_link_end} is enabled."
msgstr ""
msgid "%{due_date} (Past due)" msgid "%{due_date} (Past due)"
msgstr "" msgstr ""
...@@ -2195,9 +2201,6 @@ msgstr "" ...@@ -2195,9 +2201,6 @@ msgstr ""
msgid "Advanced permissions, Large File Storage and Two-Factor authentication settings." msgid "Advanced permissions, Large File Storage and Two-Factor authentication settings."
msgstr "" msgstr ""
msgid "Advanced search functionality"
msgstr ""
msgid "After a successful password update you will be redirected to login screen." msgid "After a successful password update you will be redirected to login screen."
msgstr "" msgstr ""
...@@ -30517,9 +30520,6 @@ msgstr "" ...@@ -30517,9 +30520,6 @@ msgstr ""
msgid "is blocked by" msgid "is blocked by"
msgstr "" msgstr ""
msgid "is enabled."
msgstr ""
msgid "is invalid because there is downstream lock" msgid "is invalid because there is downstream lock"
msgstr "" msgstr ""
......
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