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 {
}
}
.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
/* stylelint-disable property-no-vendor-prefix */
input[type='search']::-webkit-search-decoration,
......
......@@ -6,10 +6,9 @@
- 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-title-holder.d-sm-flex.align-items-sm-center
%h1.page-title<
= _('Search')
= render_if_exists 'search/form_elasticsearch', attrs: { class: 'ml-sm-auto' }
.page-title-holder.d-flex.flex-wrap.justify-content-between
%h1.page-title.mr-3= _('Search')
= render_if_exists 'search/form_elasticsearch', attrs: { class: 'mb-2 mb-sm-0 align-self-center' }
.gl-mt-3
= render 'search/form'
......
......@@ -4,6 +4,7 @@ module EE
extend ::Gitlab::Utils::Override
SWITCH_TO_BASIC_SEARCHABLE_TABS = %w[projects issues merge_requests milestones users epics].freeze
PLACEHOLDER = '_PLACEHOLDER_'
override :search_filter_input_options
def search_filter_input_options(type, placeholder = _('Search or filter results...'))
......@@ -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
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
def search_multiple_assignees?(type)
......
- if search_service.use_elasticsearch?
.form-text.text-muted{ **local_assigns.fetch(:attrs, {}) }
= link_to _('Advanced search functionality'), help_page_path('user/search/advanced_search_syntax.md'), target: '_blank'
= _('is enabled.')
= advanced_search_status_marker(@project)
---
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
before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
project.add_maintainer(user)
sign_in(user)
visit project_path(project)
end
describe 'searching' do
before do
project.add_maintainer(user)
sign_in(user)
visit project_path(project)
end
it 'finds issues', :sidekiq_inline do
create(:issue, project: project, title: 'Test searching for an issue')
ensure_elasticsearch_index!
......@@ -84,6 +86,44 @@ RSpec.describe 'Project elastic search', :js, :elastic do
expect(page).to have_selector('.results', text: 'def username_regex')
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
RSpec.describe 'Project elastic search redactions', :elastic do
......
......@@ -447,6 +447,12 @@ msgstr ""
msgid "%{description}- Sentry event: %{errorUrl}- First seen: %{firstSeen}- Last seen: %{lastSeen} %{countLabel}: %{count}%{userCountLabel}: %{userCount}"
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)"
msgstr ""
......@@ -2195,9 +2201,6 @@ msgstr ""
msgid "Advanced permissions, Large File Storage and Two-Factor authentication settings."
msgstr ""
msgid "Advanced search functionality"
msgstr ""
msgid "After a successful password update you will be redirected to login screen."
msgstr ""
......@@ -30517,9 +30520,6 @@ msgstr ""
msgid "is blocked by"
msgstr ""
msgid "is enabled."
msgstr ""
msgid "is invalid because there is downstream lock"
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