diff options
author | Sean McGivern <sean@gitlab.com> | 2018-11-19 09:54:03 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-11-19 09:54:03 +0000 |
commit | c70c4038290f9898b516473413acfae362bc1627 (patch) | |
tree | bb434e5e869036d5ff9bb85c54e57d0eb3bb1b93 /app | |
parent | 7a7060e0647bad9c5380068e50e912deecee2379 (diff) | |
parent | 2a5319832454fe40cfea151dd7b9e2aa520b3450 (diff) | |
download | gitlab-ce-c70c4038290f9898b516473413acfae362bc1627.tar.gz |
Merge branch '52385-search-bar-for-dashboard-list' into 'master'
Resolve "Search filter bar for issues dashboard list"
Closes #53584, #52430, and #52385
See merge request gitlab-org/gitlab-ce!22641
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/init_legacy_filters.js | 14 | ||||
-rw-r--r-- | app/assets/javascripts/pages/dashboard/issues/index.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/pages/dashboard/merge_requests/index.js | 12 | ||||
-rw-r--r-- | app/assets/javascripts/search_autocomplete.js | 9 | ||||
-rw-r--r-- | app/controllers/concerns/issuable_collections.rb | 36 | ||||
-rw-r--r-- | app/controllers/concerns/merge_requests_action.rb | 2 | ||||
-rw-r--r-- | app/controllers/dashboard_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/root_controller.rb | 4 | ||||
-rw-r--r-- | app/finders/issuable_finder.rb | 14 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 12 | ||||
-rw-r--r-- | app/helpers/dashboard_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 15 | ||||
-rw-r--r-- | app/views/dashboard/issues.html.haml | 4 | ||||
-rw-r--r-- | app/views/dashboard/merge_requests.html.haml | 4 | ||||
-rw-r--r-- | app/views/shared/issuable/_filter.html.haml | 32 | ||||
-rw-r--r-- | app/views/shared/issuable/_search_bar.html.haml | 5 |
16 files changed, 72 insertions, 117 deletions
diff --git a/app/assets/javascripts/init_legacy_filters.js b/app/assets/javascripts/init_legacy_filters.js deleted file mode 100644 index b6ff97d1279..00000000000 --- a/app/assets/javascripts/init_legacy_filters.js +++ /dev/null @@ -1,14 +0,0 @@ -/* eslint-disable no-new */ -import LabelsSelect from './labels_select'; -import subscriptionSelect from './subscription_select'; -import UsersSelect from './users_select'; -import issueStatusSelect from './issue_status_select'; -import MilestoneSelect from './milestone_select'; - -export default () => { - new UsersSelect(); - new LabelsSelect(); - new MilestoneSelect(); - issueStatusSelect(); - subscriptionSelect(); -}; diff --git a/app/assets/javascripts/pages/dashboard/issues/index.js b/app/assets/javascripts/pages/dashboard/issues/index.js index c4901dd1cb6..9055738f86e 100644 --- a/app/assets/javascripts/pages/dashboard/issues/index.js +++ b/app/assets/javascripts/pages/dashboard/issues/index.js @@ -1,7 +1,13 @@ import projectSelect from '~/project_select'; -import initLegacyFilters from '~/init_legacy_filters'; +import initFilteredSearch from '~/pages/search/init_filtered_search'; +import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; +import { FILTERED_SEARCH } from '~/pages/constants'; document.addEventListener('DOMContentLoaded', () => { + initFilteredSearch({ + page: FILTERED_SEARCH.ISSUES, + filteredSearchTokenKeys: IssuableFilteredSearchTokenKeys, + }); + projectSelect(); - initLegacyFilters(); }); diff --git a/app/assets/javascripts/pages/dashboard/merge_requests/index.js b/app/assets/javascripts/pages/dashboard/merge_requests/index.js index c4901dd1cb6..260484726f3 100644 --- a/app/assets/javascripts/pages/dashboard/merge_requests/index.js +++ b/app/assets/javascripts/pages/dashboard/merge_requests/index.js @@ -1,7 +1,15 @@ import projectSelect from '~/project_select'; -import initLegacyFilters from '~/init_legacy_filters'; +import initFilteredSearch from '~/pages/search/init_filtered_search'; +import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; +import { FILTERED_SEARCH } from '~/pages/constants'; document.addEventListener('DOMContentLoaded', () => { + IssuableFilteredSearchTokenKeys.addExtraTokensForMergeRequests(); + + initFilteredSearch({ + page: FILTERED_SEARCH.MERGE_REQUESTS, + filteredSearchTokenKeys: IssuableFilteredSearchTokenKeys, + }); + projectSelect(); - initLegacyFilters(); }); diff --git a/app/assets/javascripts/search_autocomplete.js b/app/assets/javascripts/search_autocomplete.js index 17def77b2d7..0a4583b5861 100644 --- a/app/assets/javascripts/search_autocomplete.js +++ b/app/assets/javascripts/search_autocomplete.js @@ -253,7 +253,6 @@ export class SearchAutocomplete { } getCategoryContents() { - const userId = gon.current_user_id; const userName = gon.current_username; const { projectOptions, groupOptions, dashboardOptions } = gl; @@ -279,21 +278,21 @@ export class SearchAutocomplete { const issueItems = [ { text: s__('SearchAutocomplete|Issues assigned to me'), - url: `${issuesPath}/?assignee_id=${userId}`, + url: `${issuesPath}/?assignee_username=${userName}`, }, { text: s__("SearchAutocomplete|Issues I've created"), - url: `${issuesPath}/?author_id=${userId}`, + url: `${issuesPath}/?author_username=${userName}`, }, ]; const mergeRequestItems = [ { text: s__('SearchAutocomplete|Merge requests assigned to me'), - url: `${mrPath}/?assignee_id=${userId}`, + url: `${mrPath}/?assignee_username=${userName}`, }, { text: s__("SearchAutocomplete|Merge requests I've created"), - url: `${mrPath}/?author_id=${userId}`, + url: `${mrPath}/?author_username=${userName}`, }, ]; diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index 5217b4be928..34a8c50fcbd 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -81,36 +81,36 @@ module IssuableCollections end def issuable_finder_for(finder_class) - finder_class.new(current_user, filter_params) + finder_class.new(current_user, finder_options) end # rubocop:disable Gitlab/ModuleWithInstanceVariables - # rubocop: disable CodeReuse/ActiveRecord - def filter_params - set_sort_order_from_cookie - set_default_state + def finder_options + params[:state] = default_state if params[:state].blank? - # Skip irrelevant Rails routing params - @filter_params = params.dup.except(:controller, :action, :namespace_id) - @filter_params[:sort] ||= default_sort_order + options = { + scope: params[:scope], + state: params[:state], + sort: set_sort_order_from_cookie || default_sort_order + } - @sort = @filter_params[:sort] + # Used by view to highlight active option + @sort = options[:sort] if @project - @filter_params[:project_id] = @project.id + options[:project_id] = @project.id elsif @group - @filter_params[:group_id] = @group.id - @filter_params[:include_subgroups] = true - @filter_params[:use_cte_for_search] = true + options[:group_id] = @group.id + options[:include_subgroups] = true + options[:use_cte_for_search] = true end - @filter_params.permit(finder_type.valid_params) + params.permit(finder_type.valid_params).merge(options) end - # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables - def set_default_state - params[:state] = 'opened' if params[:state].blank? + def default_state + 'opened' end def set_sort_order_from_cookie @@ -121,7 +121,7 @@ module IssuableCollections sort_value = update_cookie_value(sort_param) set_secure_cookie(remember_sorting_key, sort_value) - params[:sort] = sort_value + sort_value end def remember_sorting_key diff --git a/app/controllers/concerns/merge_requests_action.rb b/app/controllers/concerns/merge_requests_action.rb index 285f2c3a8a0..ed10f32512e 100644 --- a/app/controllers/concerns/merge_requests_action.rb +++ b/app/controllers/concerns/merge_requests_action.rb @@ -19,7 +19,7 @@ module MergeRequestsAction (MergeRequestsFinder if action_name == 'merge_requests') end - def filter_params + def finder_options super.merge(non_archived: true) end end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c032fb2efb5..4ce9be44403 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -4,13 +4,6 @@ class DashboardController < Dashboard::ApplicationController include IssuesAction include MergeRequestsAction - FILTER_PARAMS = [ - :author_id, - :assignee_id, - :milestone_title, - :label_name - ].freeze - before_action :event_filter, only: :activity before_action :projects, only: [:issues, :merge_requests] before_action :set_show_full_reference, only: [:issues, :merge_requests] @@ -51,10 +44,13 @@ class DashboardController < Dashboard::ApplicationController end def check_filters_presence! - @no_filters_set = FILTER_PARAMS.none? { |k| params.key?(k) } + @no_filters_set = finder_type.scalar_params.none? { |k| params.key?(k) } return unless @no_filters_set + # Call to set selected `state` and `sort` options in view + finder_options + respond_to do |format| format.html { render } format.atom { head :bad_request } diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index ebf70f25bda..7b6657e1196 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -45,9 +45,9 @@ class RootController < Dashboard::ProjectsController when 'todos' redirect_to(dashboard_todos_path) when 'issues' - redirect_to(issues_dashboard_path(assignee_id: current_user.id)) + redirect_to(issues_dashboard_path(assignee_username: current_user.username)) when 'merge_requests' - redirect_to(merge_requests_dashboard_path(assignee_id: current_user.id)) + redirect_to(merge_requests_dashboard_path(assignee_username: current_user.username)) end end diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 93bef592c65..fdc630cbf72 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -14,7 +14,9 @@ # project_id: integer # milestone_title: string # author_id: integer +# author_username: string # assignee_id: integer or 'None' or 'Any' +# assignee_username: string # search: string # label_name: string # sort: string @@ -49,25 +51,15 @@ class IssuableFinder assignee_username author_id author_username - authorized_only - group_id - iids label_name milestone_title my_reaction_emoji - non_archived - project_id - scope search - sort - state - include_subgroups - use_cte_for_search ] end def self.array_params - @array_params ||= { label_name: [], iids: [], assignee_username: [] } + @array_params ||= { label_name: [], assignee_username: [] } end def self.valid_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4f91e3e4117..74042f0bae8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -173,17 +173,7 @@ module ApplicationHelper without = options.delete(:without) add_label = options.delete(:label) - exist_opts = { - state: params[:state], - scope: params[:scope], - milestone_title: params[:milestone_title], - assignee_id: params[:assignee_id], - author_id: params[:author_id], - search: params[:search], - label_name: params[:label_name] - } - - options = exist_opts.merge(options) + options = request.query_parameters.merge(options) if without.present? without.each do |key| diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index 463f4145bdd..d90ef8903a7 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -2,11 +2,11 @@ module DashboardHelper def assigned_issues_dashboard_path - issues_dashboard_path(assignee_id: current_user.id) + issues_dashboard_path(assignee_username: current_user.username) end def assigned_mrs_dashboard_path - merge_requests_dashboard_path(assignee_id: current_user.id) + merge_requests_dashboard_path(assignee_username: current_user.username) end def dashboard_nav_links diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 4f9e1322b56..80cc568820a 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -163,15 +163,26 @@ module SearchHelper if @project.present? opts[:data]['project-id'] = @project.id opts[:data]['base-endpoint'] = project_path(@project) - else - # Group context + elsif @group.present? opts[:data]['group-id'] = @group.id opts[:data]['base-endpoint'] = group_canonical_path(@group) + else + opts[:data]['base-endpoint'] = root_dashboard_path end opts end + def search_history_storage_prefix + if @project.present? + @project.full_path + elsif @group.present? + @group.full_path + else + 'dashboard' + end + end + # Sanitize a HTML field for search display. Most tags are stripped out and the # maximum length is set to 200 characters. def search_md_sanitize(object, field) diff --git a/app/views/dashboard/issues.html.haml b/app/views/dashboard/issues.html.haml index 832ba877558..fdd5c19d562 100644 --- a/app/views/dashboard/issues.html.haml +++ b/app/views/dashboard/issues.html.haml @@ -1,6 +1,6 @@ - @hide_top_links = true - page_title _("Issues") -- @breadcrumb_link = issues_dashboard_path(assignee_id: current_user.id) +- @breadcrumb_link = issues_dashboard_path(assignee_username: current_user.username) = content_for :meta_tags do = auto_discovery_link_tag(:atom, safe_params.merge(rss_url_options).to_h, title: "#{current_user.name} issues") @@ -16,7 +16,7 @@ .nav-controls = render 'shared/issuable/feed_buttons' -= render 'shared/issuable/filter', type: :issues += render 'shared/issuable/search_bar', type: :issues - if current_user && @no_filters_set = render 'shared/dashboard/no_filter_selected' diff --git a/app/views/dashboard/merge_requests.html.haml b/app/views/dashboard/merge_requests.html.haml index fba8d1cf667..77cfa1271df 100644 --- a/app/views/dashboard/merge_requests.html.haml +++ b/app/views/dashboard/merge_requests.html.haml @@ -1,6 +1,6 @@ - @hide_top_links = true - page_title _("Merge Requests") -- @breadcrumb_link = merge_requests_dashboard_path(assignee_id: current_user.id) +- @breadcrumb_link = merge_requests_dashboard_path(assignee_username: current_user.username) .page-title-holder %h1.page-title= _('Merge Requests') @@ -12,7 +12,7 @@ .top-area = render 'shared/issuable/nav', type: :merge_requests, display_count: !@no_filters_set -= render 'shared/issuable/filter', type: :merge_requests += render 'shared/issuable/search_bar', type: :merge_requests - if current_user && @no_filters_set = render 'shared/dashboard/no_filter_selected' diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml deleted file mode 100644 index c7037335866..00000000000 --- a/app/views/shared/issuable/_filter.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -.issues-filters - .issues-details-filters.row-content-block.second-block - = form_tag page_filter_path(without: [:assignee_id, :author_id, :milestone_title, :label_name, :search]), method: :get, class: 'filter-form js-filter-form' do - - if params[:search].present? - = hidden_field_tag :search, params[:search] - .issues-other-filters - .filter-item.inline - - if params[:author_id].present? - = hidden_field_tag(:author_id, params[:author_id]) - = dropdown_tag(user_dropdown_label(params[:author_id], "Author"), options: { toggle_class: "js-user-search js-filter-submit js-author-search", title: "Filter by author", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit", - placeholder: "Search authors", data: { any_user: "Any Author", first_user: current_user&.username, current_user: true, project_id: @project&.id, group_id: @group&.id, selected: params[:author_id], field_name: "author_id", default_label: "Author" } }) - - .filter-item.inline - - if params[:assignee_id].present? - = hidden_field_tag(:assignee_id, params[:assignee_id]) - = dropdown_tag(user_dropdown_label(params[:assignee_id], "Assignee"), options: { toggle_class: "js-user-search js-filter-submit js-assignee-search", title: "Filter by assignee", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-assignee js-filter-submit", - placeholder: "Search assignee", data: { any_user: "Any Assignee", first_user: current_user&.username, null_user: true, current_user: true, project_id: @project&.id, group_id: @group&.id, selected: params[:assignee_id], field_name: "assignee_id", default_label: "Assignee" } }) - - .filter-item.inline.milestone-filter - = render "shared/issuable/milestone_dropdown", selected: finder.milestones.try(:first), name: :milestone_title, show_any: true, show_upcoming: true, show_started: true - - .filter-item.inline.labels-filter - = render "shared/issuable/label_dropdown", selected: selected_labels, use_id: false, selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" } - - - unless @no_filters_set - .float-right - = render 'shared/sort_dropdown' - - - has_labels = @labels && @labels.any? - .row-content-block.second-block.filtered-labels{ class: ("hidden" unless has_labels) } - - if has_labels - = render 'shared/labels_row', labels: @labels diff --git a/app/views/shared/issuable/_search_bar.html.haml b/app/views/shared/issuable/_search_bar.html.haml index 95f32bd0180..824bbe3524b 100644 --- a/app/views/shared/issuable/_search_bar.html.haml +++ b/app/views/shared/issuable/_search_bar.html.haml @@ -1,7 +1,6 @@ - type = local_assigns.fetch(:type) - board = local_assigns.fetch(:board, nil) - block_css_class = type != :boards_modal ? 'row-content-block second-block' : '' -- full_path = @project.present? ? @project.full_path : @group.full_path - user_can_admin_list = board && can?(current_user, :admin_list, board.parent) - show_sorting_dropdown = local_assigns.fetch(:show_sorting_dropdown, true) @@ -10,7 +9,7 @@ - if type == :boards #js-multiple-boards-switcher.inline.boards-switcher{ "v-cloak" => true } = render_if_exists "shared/boards/switcher", board: board - = form_tag page_filter_path(without: [:assignee_id, :author_id, :milestone_title, :label_name, :search]), method: :get, class: 'filter-form js-filter-form' do + = form_tag page_filter_path, method: :get, class: 'filter-form js-filter-form' do - if params[:search].present? = hidden_field_tag :search, params[:search] - if @can_bulk_update @@ -25,7 +24,7 @@ dropdown_class: "filtered-search-history-dropdown", content_class: "filtered-search-history-dropdown-content", title: "Recent searches" }) do - .js-filtered-search-history-dropdown{ data: { full_path: full_path } } + .js-filtered-search-history-dropdown{ data: { full_path: search_history_storage_prefix } } .filtered-search-box-input-container.droplab-dropdown .scroll-container %ul.tokens-container.list-unstyled |