Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter requests by created_at range #17216

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/api/app/controllers/concerns/webui/requests_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ def filter_requests
params[:states] = @filter_state if @filter_state.present?
params[:types] = @filter_action_type if @filter_action_type.present?

params[:created_at_from] = @filter_created_at_from if @filter_created_at_from.present?
params[:created_at_to] = @filter_created_at_to if @filter_created_at_to.present?

@bs_requests = BsRequest::FindFor::Query.new(params, initial_bs_requests).all
set_selected_filter
end

# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def set_filters
@filter_direction = params[:direction].presence || 'all'
@filter_direction = 'all' if ALLOWED_DIRECTIONS.exclude?(@filter_direction)
Expand All @@ -33,11 +38,17 @@ def set_filters
@filter_action_type = @filter_action_type.intersection(BsRequestAction::TYPES)

@filter_creators = params[:creators].present? ? params[:creators].compact_blank! : []

@filter_created_at_from = params[:created_at_from].presence || ''
@filter_created_at_to = params[:created_at_to].presence || ''
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

def set_selected_filter
@selected_filter = { direction: @filter_direction, action_type: @filter_action_type, search_text: params[:requests_search_text],
state: @filter_state, creators: @filter_creators }
state: @filter_state, creators: @filter_creators, created_at_from: @filter_created_at_from,
created_at_to: @filter_created_at_to }
end

def filter_by_text(text)
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/models/bs_request/find_for/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def all
@relation = BsRequest::FindFor::Project.new(@parameters, @relation).all
@relation = BsRequest::FindFor::User.new(@parameters, @relation).all if user_login.present?
@relation = BsRequest::FindFor::Group.new(@parameters, @relation).all if group_title.present?
created_at_from = Date.parse(@parameters['created_at_from']) if @parameters['created_at_from'].present?
created_at_to = Date.parse(@parameters['created_at_to']) if @parameters['created_at_to'].present?
@relation = @relation.where(created_at: (created_at_from&.beginning_of_day..created_at_to&.end_of_day))
@relation = @relation.where(id: ids) if @parameters.key?('ids')
@relation = @relation.do_search(search) if search.present?
@relation
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/views/webui/shared/_input.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.col-9.d-flex
= text_field_tag(filter_item, '',
class: 'form-control form-control-sm',
placeholder: placeholder, value: selected_input_value)
placeholder: placeholder, value: selected_input_value,
type: defined?(type) ? type : 'text')
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-# haml-lint:disable ViewLength
.accordion.accordion-flush
.mt-2.mb-2.accordion-item.border-0
.px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#request-filter-direction' },
Expand Down Expand Up @@ -73,7 +74,7 @@
checked: selected_filter[:action_type]&.include?('submit')}

.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' },
.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
Expand All @@ -96,5 +97,19 @@
key: "creators[#{creator}]", name: 'creators[]',
value: creator,
checked: selected_filter[:creators]&.include?(creator) }

.mt-2.mb-2.accordion-item.border-0
.px-3.py-2.accordion-button.no-style{ data: { 'bs-toggle': 'collapse', 'bs-target': '#request-filter-created-at' },
aria: { expanded: 'true', controls: 'request-filter-created-at' } }
%b Created at
.selected-content.small.ms-1
.px-4.pb-2.accordion-collapse.collapse.show#request-filter-created-at
= render partial: 'webui/shared/input', locals: { label: 'From', filter_item: 'created_at_from', type: 'date',
placeholder: 'mm/dd/yyyy', selected_input_value: selected_filter[:created_at_from] }
= render partial: 'webui/shared/input', locals: { label: 'To', filter_item: 'created_at_to', type: 'date',
placeholder: 'mm/dd/yyyy', selected_input_value: selected_filter[:created_at_to] }

.text-center.mt-4.mb-4
= link_to('Clear', url, class: 'btn btn-light border')

-# haml-lint:enable ViewLength
31 changes: 31 additions & 0 deletions src/api/spec/features/beta/webui/requests_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,35 @@
end
# rubocop:enable RSpec/ExampleLength
end

describe 'filters request by created_at' do
let!(:request_in_review) do
create(:bs_request_with_submit_action,
description: 'This is in review state',
creator: receiver,
source_package: source_project.packages.first,
target_project: other_source_project,
state: :review,
review_by_user: receiver)
end

# rubocop:disable RSpec/ExampleLength
it 'shows only requests within the selected date range' do
request_in_review.created_at = DateTime.now - 10.days # set request to be older
request_in_review.save # update and store the new value
find_by_id('requests-dropdown-trigger').click if mobile? # open the filter dropdown
within('#filters') do
# filter from yesterday to tomorrow
fill_in 'created_at_from', with: DateTime.now - 1.day
fill_in 'created_at_to', with: DateTime.now + 1.day
sleep 2 # there is a timeout before firing the filtering
end

within('#requests') do
expect(page).to have_no_link(href: "/request/show/#{request_in_review.number}")
expect(page).to have_link(href: "/request/show/#{outgoing_request.number}")
end
end
# rubocop:enable RSpec/ExampleLength
end
end
Loading