From 29ed76155bcbfe43e162e1dd89d8f770c7e4f493 Mon Sep 17 00:00:00 2001 From: Lukas Krause Date: Thu, 12 Dec 2024 15:42:42 +0100 Subject: [PATCH 1/4] Use autocomplete search for requests index creator filter --- .../concerns/webui/requests_filter.rb | 2 +- .../webui/users/bs_requests_controller.rb | 2 -- .../webui/shared/bs_requests/_form.html.haml | 17 ----------------- .../bs_requests/_requests_filter.html.haml | 9 +++++---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/api/app/controllers/concerns/webui/requests_filter.rb b/src/api/app/controllers/concerns/webui/requests_filter.rb index f1418602d82..492cfafdfac 100644 --- a/src/api/app/controllers/concerns/webui/requests_filter.rb +++ b/src/api/app/controllers/concerns/webui/requests_filter.rb @@ -32,7 +32,7 @@ def set_filters @filter_action_type = params[:action_type].presence || [] @filter_action_type = @filter_action_type.intersection(BsRequestAction::TYPES) - @filter_creators = params[:creators].presence || [] + @filter_creators = params[:creators].present? ? params[:creators].compact_blank! : [] end def set_selected_filter diff --git a/src/api/app/controllers/webui/users/bs_requests_controller.rb b/src/api/app/controllers/webui/users/bs_requests_controller.rb index a700f8e106c..ede54e194ce 100644 --- a/src/api/app/controllers/webui/users/bs_requests_controller.rb +++ b/src/api/app/controllers/webui/users/bs_requests_controller.rb @@ -20,8 +20,6 @@ def index format.html do filter_requests - # TODO: Temporarily disable list of creators due to performance issues - # @bs_requests_creators = @bs_requests.distinct.pluck(:creator) @bs_requests = @bs_requests.order('number DESC').page(params[:page]) @bs_requests = @bs_requests.includes(:bs_request_actions, :comments, :reviews) @bs_requests = @bs_requests.includes(:labels) if Flipper.enabled?(:labels, User.session) diff --git a/src/api/app/views/webui/shared/bs_requests/_form.html.haml b/src/api/app/views/webui/shared/bs_requests/_form.html.haml index 0403b51e850..e476d000331 100644 --- a/src/api/app/views/webui/shared/bs_requests/_form.html.haml +++ b/src/api/app/views/webui/shared/bs_requests/_form.html.haml @@ -69,20 +69,3 @@ clearTimeout(submitFiltersTimeout); submitFiltersTimeout = setTimeout(submitRequestFilters, 2000); }); - - $(document).on("input", "#request-creator-search", function(event) { - var searchInput = event.target; - var filterValue = searchInput.value.toLowerCase(); - var dropdown = document.getElementById("request-creator-dropdown"); - var dropdownInputFields = dropdown.getElementsByTagName("input"); - - for (i = 1; i < dropdownInputFields.length; i++) { - dropdownInputValue = dropdownInputFields[i].value; - - if (dropdownInputValue.toLowerCase().indexOf(filterValue) > -1) { - dropdownInputFields[i].closest(".dropdown-item-text").style.display = ""; - } else { - dropdownInputFields[i].closest(".dropdown-item-text").style.display = "none"; - } - } - }); diff --git a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml index 818d2355ae8..87313f47c1d 100644 --- a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml +++ b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml @@ -72,22 +72,23 @@ label_icon: action_type_icon('submit'), checked: selected_filter[:action_type]&.include?('submit')} --# TODO: Temporarily disable list of creators due to performance issues .mt-2.mb-2.accordion-item.border-0 %h6.px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#request-filter-creator' }, aria: { expanded: 'true', controls: 'request-filter-creator' } } %b Creator .px-4.pb-2.accordion-collapse.collapse.show#request-filter-creator #request-creator-dropdown - = text_field_tag('request-creator-search', nil, autocomplete: 'off', placeholder: 'Search creators...', class: 'form-control mb-2') + = render partial: 'webui/shared/autocomplete', locals: { html_id: 'creators_search', label: 'Creators:', + html_name: 'creators[]', required: false, + data: { source: autocomplete_users_path } } - - if creators.include?(User.session.login) + - if selected_filter[:creators].include?(User.session.login) .dropdown-item-text = render partial: 'webui/shared/check_box', locals: { label: "#{User.session.login} (me)", key: "creators[#{User.session.login}]", name: 'creators[]', value: User.session.login, checked: selected_filter[:creators]&.include?(User.session.login) } - - creators.each do |creator| + - selected_filter[:creators].each do |creator| - next if creator == User.session.login .dropdown-item-text = render partial: 'webui/shared/check_box', locals: { label: creator, From 21a9526314170613679374a65ff903a673a0c3d7 Mon Sep 17 00:00:00 2001 From: Lukas Krause Date: Fri, 13 Dec 2024 16:49:56 +0100 Subject: [PATCH 2/4] Show preview of selected creator filters on collapsed accordion --- .../views/webui/shared/bs_requests/_requests_filter.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml index 87313f47c1d..12c95234b01 100644 --- a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml +++ b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml @@ -76,6 +76,7 @@ %h6.px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#request-filter-creator' }, aria: { expanded: 'true', controls: 'request-filter-creator' } } %b Creator + .selected-content.small.ms-1 .px-4.pb-2.accordion-collapse.collapse.show#request-filter-creator #request-creator-dropdown = render partial: 'webui/shared/autocomplete', locals: { html_id: 'creators_search', label: 'Creators:', From 50b69eca1d811db07a6062e22a56906912a57d09 Mon Sep 17 00:00:00 2001 From: Lukas Krause Date: Tue, 17 Dec 2024 21:22:46 +0100 Subject: [PATCH 3/4] Adapt `requests_index_spec` to cover creators filter --- .../beta/webui/requests_index_spec.rb | 57 +++++++++++++------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/src/api/spec/features/beta/webui/requests_index_spec.rb b/src/api/spec/features/beta/webui/requests_index_spec.rb index 4648479ba58..635c8e250a3 100644 --- a/src/api/spec/features/beta/webui/requests_index_spec.rb +++ b/src/api/spec/features/beta/webui/requests_index_spec.rb @@ -113,36 +113,57 @@ # rubocop:enable RSpec/ExampleLength end - describe 'using the request creator filter', skip: 'Temporarily disable list of creators due to performance issues' do + describe 'using the request creator filter' do before do - find_by_id('requests-dropdown-trigger').click if mobile? # open the filter dropdown - find_by_id('filter-creator-requests-button').click - end + if mobile? + find_by_id('requests-dropdown-trigger').click # open the filter dropdown + sleep 0.5 # wait for dropdown to open + end - it 'lists only the requests of the selected creator' do - check("creators[#{receiver.login}]") + within('#filters') do + fill_in('creators_search', with: receiver.login[0, 2]) + find('.ui-menu-item-wrapper', match: :first).click + # Remove focus from autocomplete search to allow the autosubmit + find('label[for="creators_search"]').click + sleep 2 + end - expect(page).to have_link(href: "/request/show/#{outgoing_request.number}") - expect(page).to have_no_link(href: "/request/show/#{incoming_request.number}") - expect(page).to have_no_link(href: "/request/show/#{other_incoming_request.number}") - end + if mobile? + find_by_id('requests-dropdown-trigger').click # open the filter dropdown + sleep 0.5 # wait for dropdown to open + end - it 'allows to filter by multiple request creators' do - check("creators[#{receiver.login}]") - check("creators[#{another_submitter.login}]") + within('#filters') do + fill_in('creators_search', with: another_submitter.login[0, 2]) + find('.ui-menu-item-wrapper', match: :first).click + # Remove focus from autocomplete search to allow the autosubmit + find('label[for="creators_search"]').click + sleep 2 + end + end + it 'filters the requests by multiple creators' do expect(page).to have_link(href: "/request/show/#{outgoing_request.number}") expect(page).to have_link(href: "/request/show/#{other_incoming_request.number}") expect(page).to have_no_link(href: "/request/show/#{incoming_request.number}") end - it 'only shows the creators that match the search value filled in the dropdown' do - fill_in('request-creator-search', with: submitter.login[0, 2].to_s) + # rubocop:disable RSpec/ExampleLength + it 'allows to modify the filter selection' do + if mobile? + find_by_id('requests-dropdown-trigger').click # open the filter dropdown + sleep 0.5 # wait for dropdown to open + end - within('div#request-creator-dropdown') do - expect(page).to have_field('creators[]', with: submitter.login.to_s) - expect(page).to have_no_field('creators[]', with: receiver.login.to_s) + within('#filters') do + uncheck("creators[#{receiver.login}]") + sleep 2 end + + expect(page).to have_no_link(href: "/request/show/#{outgoing_request.number}") + expect(page).to have_link(href: "/request/show/#{other_incoming_request.number}") + expect(page).to have_no_link(href: "/request/show/#{incoming_request.number}") end + # rubocop:enable RSpec/ExampleLength end end From bdb04e11b9351dcf85492b1e17e91402d76cb3ab Mon Sep 17 00:00:00 2001 From: Lukas Krause Date: Wed, 18 Dec 2024 16:23:15 +0100 Subject: [PATCH 4/4] Dont show label of autocomplete search for creator filter The accordion already indicates that this filter is for creators, no need to show this info twice. --- src/api/app/views/webui/shared/_autocomplete.html.haml | 4 +++- .../views/webui/shared/bs_requests/_requests_filter.html.haml | 2 +- src/api/spec/features/beta/webui/requests_index_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/app/views/webui/shared/_autocomplete.html.haml b/src/api/app/views/webui/shared/_autocomplete.html.haml index 07264c11060..76b58873e57 100644 --- a/src/api/app/views/webui/shared/_autocomplete.html.haml +++ b/src/api/app/views/webui/shared/_autocomplete.html.haml @@ -4,9 +4,11 @@ disabled = local_assigns.fetch(:disabled, false) data = local_assigns.fetch(:data, {}) html_name = local_assigns.fetch(:html_name, html_id) + with_label = local_assigns.fetch(:with_label, true) .mb-3.ui-front - = label_tag(html_id, label) + - if with_label + = label_tag(html_id, label) - if required %abbr.text-danger{ title: 'required' } * .input-group diff --git a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml index 12c95234b01..010ec7fd36a 100644 --- a/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml +++ b/src/api/app/views/webui/shared/bs_requests/_requests_filter.html.haml @@ -80,7 +80,7 @@ .px-4.pb-2.accordion-collapse.collapse.show#request-filter-creator #request-creator-dropdown = render partial: 'webui/shared/autocomplete', locals: { html_id: 'creators_search', label: 'Creators:', - html_name: 'creators[]', required: false, + html_name: 'creators[]', required: false, with_label: false, data: { source: autocomplete_users_path } } - if selected_filter[:creators].include?(User.session.login) diff --git a/src/api/spec/features/beta/webui/requests_index_spec.rb b/src/api/spec/features/beta/webui/requests_index_spec.rb index 635c8e250a3..e069f32294c 100644 --- a/src/api/spec/features/beta/webui/requests_index_spec.rb +++ b/src/api/spec/features/beta/webui/requests_index_spec.rb @@ -124,7 +124,7 @@ fill_in('creators_search', with: receiver.login[0, 2]) find('.ui-menu-item-wrapper', match: :first).click # Remove focus from autocomplete search to allow the autosubmit - find('label[for="creators_search"]').click + find(:xpath, '//*[@id="request-creator-dropdown"]/div/div/span/i').click sleep 2 end @@ -137,7 +137,7 @@ fill_in('creators_search', with: another_submitter.login[0, 2]) find('.ui-menu-item-wrapper', match: :first).click # Remove focus from autocomplete search to allow the autosubmit - find('label[for="creators_search"]').click + find(:xpath, '//*[@id="request-creator-dropdown"]/div/div/span/i').click sleep 2 end end