Commit c193af79 authored by Toon Claes's avatar Toon Claes

Use helper method to set filtered search input attributes

The list of attributes for the filtered search input was getting long, so use a
helper method to fill that hash.

Also, for multiple issue assignees, a helper is more convenient because it would
allow EE to override the behavior if MIA is supported.
parent 7182e9e2
...@@ -26,9 +26,11 @@ class FilteredSearchTokenKeysIssuesEE extends gl.FilteredSearchTokenKeys { ...@@ -26,9 +26,11 @@ class FilteredSearchTokenKeysIssuesEE extends gl.FilteredSearchTokenKeys {
static get() { static get() {
const tokenKeys = Array.from(super.get()); const tokenKeys = Array.from(super.get());
// Enable multiple assignees // Enable multiple assignees when available
const assigneeTokenKey = tokenKeys.find(tk => tk.key === 'assignee'); if (this.availableFeatures && this.availableFeatures.multipleAssignees) {
if (this.availableFeatures && this.availableFeatures.multipleAssignees) assigneeTokenKey.type = 'array'; const assigneeTokenKey = tokenKeys.find(tk => tk.key === 'assignee');
assigneeTokenKey.type = 'array';
}
tokenKeys.push(weightTokenKey); tokenKeys.push(weightTokenKey);
return tokenKeys; return tokenKeys;
......
module EE
module SearchHelper
def search_filter_input_options(type)
options = super
options[:data][:'multiple-assignees'] = 'true' if (type == :issues) && @project.feature_available?(:multiple_issue_assignees)
options
end
end
end
module SearchHelper module SearchHelper
prepend EE::SearchHelper
def search_autocomplete_opts(term) def search_autocomplete_opts(term)
return unless current_user return unless current_user
...@@ -134,6 +136,18 @@ module SearchHelper ...@@ -134,6 +136,18 @@ module SearchHelper
search_path(options) search_path(options)
end end
def search_filter_input_options(type)
{
id: "filtered-search-#{type}",
placeholder: 'Search or filter results...',
data: {
'project-id' => @project.id,
'username-params' => @users.to_json(only: [:id, :username]),
'base-endpoint' => project_path(@project)
}
}
end
# Sanitize a HTML field for search display. Most tags are stripped out and the # Sanitize a HTML field for search display. Most tags are stripped out and the
# maximum length is set to 200 characters. # maximum length is set to 200 characters.
def search_md_sanitize(object, field) def search_md_sanitize(object, field)
......
- type = local_assigns.fetch(:type) - type = local_assigns.fetch(:type)
- board = local_assigns.fetch(:board, nil) - board = local_assigns.fetch(:board, nil)
- block_css_class = type != :boards_modal ? 'row-content-block second-block' : '' - block_css_class = type != :boards_modal ? 'row-content-block second-block' : ''
- can_multiple_assignees = @project.feature_available?(:"multiple_#{type.to_s}_assignees")
.issues-filters .issues-filters
.issues-details-filters.filtered-search-block{ class: block_css_class, "v-pre" => type == :boards_modal } .issues-details-filters.filtered-search-block{ class: block_css_class, "v-pre" => type == :boards_modal }
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
.scroll-container .scroll-container
%ul.tokens-container.list-unstyled %ul.tokens-container.list-unstyled
%li.input-token %li.input-token
%input.form-control.filtered-search{ id: "filtered-search-#{type.to_s}", placeholder: 'Search or filter results...', data: { 'project-id' => @project.id, 'username-params' => @users.to_json(only: [:id, :username]), 'base-endpoint' => project_path(@project), 'multiple-assignees' => can_multiple_assignees } } %input.form-control.filtered-search{ search_filter_input_options(type) }
= icon('filter') = icon('filter')
#js-dropdown-hint.filtered-search-input-dropdown-menu.dropdown-menu.hint-dropdown #js-dropdown-hint.filtered-search-input-dropdown-menu.dropdown-menu.hint-dropdown
%ul{ data: { dropdown: true } } %ul{ data: { dropdown: true } }
......
...@@ -15,6 +15,9 @@ import '~/filtered_search/filtered_search_token_keys_issues_ee'; ...@@ -15,6 +15,9 @@ import '~/filtered_search/filtered_search_token_keys_issues_ee';
let tokenKeys; let tokenKeys;
beforeEach(() => { beforeEach(() => {
gl.FilteredSearchTokenKeysIssuesEE.init({
multipleAssignees: true,
});
tokenKeys = gl.FilteredSearchTokenKeysIssuesEE.get(); tokenKeys = gl.FilteredSearchTokenKeysIssuesEE.get();
}); });
......
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