Skip to content

Commit

Permalink
Use Filters::ActionRequiredBy
Browse files Browse the repository at this point in the history
This adds a new filter to the application index page for assessors to
allow them to select applications which require action either by an
assessor or by an admin.
  • Loading branch information
thomasleese committed Sep 24, 2023
1 parent e2f8412 commit bbc4220
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 22 deletions.
9 changes: 5 additions & 4 deletions app/forms/assessor_interface/filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ class AssessorInterface::FilterForm
include ActiveModel::Model
include ActiveRecord::AttributeAssignment

attr_accessor :assessor_ids,
attr_accessor :action_required_by,
:assessor_ids,
:email,
:location,
:name,
:reference,
:email,
:statuses,
:submitted_at_before,
:submitted_at_after
:submitted_at_after,
:submitted_at_before
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def country_filter_options
)
end

def action_required_by_filter_options
ACTION_REQUIRED_BY_OPTIONS.map do |name|
action_required_by_filter_entry(name)
end
end

def status_filter_options
STATUS_FILTER_OPTIONS.each_with_object({}) do |(status, substatuses), memo|
memo[status_filter_entry(status)] = substatuses.map do |sub_status|
Expand All @@ -43,6 +49,8 @@ def status_filter_options

private

ACTION_REQUIRED_BY_OPTIONS = %w[admin assessor external].freeze

STATUS_FILTER_OPTIONS = {
preliminary_check: [],
submitted: [],
Expand Down Expand Up @@ -71,18 +79,8 @@ def filter_params
(session[:filter_params] || {}).with_indifferent_access
end

def application_forms_with_pagy
@application_forms_with_pagy ||=
pagy(
::Filters::Status.apply(
scope: application_forms_without_status_filter,
params: filter_params,
).order(submitted_at: :asc),
)
end

def application_forms_without_status_filter
@application_forms_without_status_filter ||=
def application_forms_without_action_required_by_filter
@application_forms_without_action_required_by_filter ||=
begin
filters = [
::Filters::Assessor,
Expand All @@ -98,6 +96,39 @@ def application_forms_without_status_filter
end
end

def application_forms_without_status_filter
@application_forms_without_status_filter ||=
::Filters::ActionRequiredBy.apply(
scope: application_forms_without_action_required_by_filter,
params: filter_params,
)
end

def application_forms_with_pagy
@application_forms_with_pagy ||=
pagy(
::Filters::Status.apply(
scope: application_forms_without_status_filter,
params: filter_params,
).order(submitted_at: :asc),
)
end

def action_required_by_filter_counts
@action_required_by_filter_counts ||=
application_forms_without_action_required_by_filter.group(
:action_required_by,
).count
end

def action_required_by_filter_entry(name)
OpenStruct.new(
id: name,
label:
"#{name.humanize} (#{action_required_by_filter_counts.fetch(name, 0)})",
)
end

def status_filter_counts
@status_filter_counts ||=
begin
Expand Down
16 changes: 12 additions & 4 deletions app/views/assessor_interface/application_forms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<div class="app-checkbox-filter__container">
<div class="app-checkbox-filter__container-inner">
<%= f.govuk_check_boxes_fieldset :assessor_ids, legend: { size: "s" }, small: true do %>
<%- @view_object.assessor_filter_options.each do |option| -%>
<% @view_object.assessor_filter_options.each do |option| %>
<%= f.govuk_check_box :assessor_ids, option.id, label: { text: option.name }, checked: @view_object.filter_form.assessor_ids&.include?(option.id.to_s) %>
<%- end -%>
<%- end -%>
<% end %>
<% end %>
</div>
</div>
</section>
Expand Down Expand Up @@ -48,6 +48,14 @@
<% end %>
</section>

<section id="app-applications-filters-action-required-by">
<%= f.govuk_check_boxes_fieldset :action_required_by, legend: { size: "s" }, small: true do %>
<% @view_object.action_required_by_filter_options.each do |option| %>
<%= f.govuk_check_box :action_required_by, option.id, label: { text: option.label }, checked: @view_object.filter_form.action_required_by&.include?(option.id) %>
<% end %>
<% end %>
</section>

<section id="app-applications-filters-status">
<%= f.govuk_check_boxes_fieldset :statuses, legend: { size: "s" }, small: true do %>
<% @view_object.status_filter_options.each do |option, suboptions| %>
Expand All @@ -67,7 +75,7 @@
<% end %>
<% end %>
</section>
<%- end -%>
<% end %>
</div>

<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion config/locales/components.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ en:

timeline_entry:
title:
action_required_by_changed: Workflow changed
action_required_by_changed: Action required by changed
assessor_assigned: Assessor assigned
reviewer_assigned: Reviewer assigned
state_changed: Status changed
Expand Down
3 changes: 2 additions & 1 deletion config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ en:
assessor_interface_create_note_form:
text: Add a note to this application
assessor_interface_filter_form:
email: Applicant email
location: Country trained in
name: Applicant name
reference: Application reference number
email: Applicant email
assessor_interface_professional_standing_request_location_form:
received_options:
true: "Yes"
Expand Down Expand Up @@ -277,6 +277,7 @@ en:
scotland_full_registration: Does the applicant have or are they eligible for full registration?
school_details_cannot_be_verified_work_history_checked: Choose the schools that need reference details to be amended
assessor_interface_filter_form:
action_required_by: Action required by
assessor_ids: Assessor name
states: Status of application
submitted_at: Created date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class Applications < SitePrism::Page
"#assessor_interface_filter_form_submitted_at_before_1i"
end

section :action_required_by_filter,
"#app-applications-filters-action-required-by" do
sections :items, GovukCheckboxItem, ".govuk-checkboxes__item"
end

section :status_filter, "#app-applications-filters-status" do
sections :statuses, GovukCheckboxItem, ".govuk-checkboxes__item"
end
Expand Down
24 changes: 24 additions & 0 deletions spec/system/assessor_interface/filtering_application_forms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
and_i_apply_the_submitted_at_filter
then_i_see_a_list_of_applications_filtered_by_submitted_at

when_i_clear_the_filters
and_i_apply_the_action_required_by_filter
then_i_see_a_list_of_applications_filtered_by_action_required_by

when_i_clear_the_filters
and_i_apply_the_status_filter
then_i_see_a_list_of_applications_filtered_by_state
Expand Down Expand Up @@ -124,6 +128,24 @@ def then_i_see_a_list_of_applications_filtered_by_submitted_at
expect(applications_page.search_results.first.name.text).to eq("John Smith")
end

def and_i_apply_the_action_required_by_filter
admin_action_item =
applications_page.action_required_by_filter.items.find do |item|
item.label.text == "Admin (1)"
rescue Capybara::ElementNotFound
false
end
admin_action_item.checkbox.click
applications_page.apply_filters.click
end

def then_i_see_a_list_of_applications_filtered_by_action_required_by
expect(applications_page.search_results.count).to eq(1)
expect(applications_page.search_results.first.name.text).to eq(
"Emma Dubois",
)
end

def and_i_apply_the_status_filter
awarded_state =
applications_page.status_filter.statuses.find do |status|
Expand Down Expand Up @@ -155,6 +177,7 @@ def application_forms
create(
:application_form,
:submitted,
:action_required_by_admin,
region: create(:region, country: create(:country, code: "FR")),
given_names: "Emma",
family_name: "Dubois",
Expand All @@ -165,6 +188,7 @@ def application_forms
create(
:application_form,
:submitted,
:action_required_by_assessor,
region: create(:region, country: create(:country, code: "ES")),
given_names: "Arnold",
family_name: "Drummond",
Expand Down

0 comments on commit bbc4220

Please sign in to comment.