Skip to content

Commit

Permalink
Add filter on actionable by
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 11, 2023
1 parent c0501e2 commit 8f2d30c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 21 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 :actionable_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,10 @@ def country_filter_options
)
end

def actionable_by_filter_options
ACTIONABLE_BY_OPTIONS.map { |name| actionable_by_filter_entry(name) }
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 +47,8 @@ def status_filter_options

private

ACTIONABLE_BY_OPTIONS = %w[admin assessor nobody].freeze

STATUS_FILTER_OPTIONS = {
preliminary_check: [],
submitted: [],
Expand Down Expand Up @@ -71,18 +77,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_actionable_by_filter
@application_forms_without_actionable_by_filter ||=
begin
filters = [
::Filters::Assessor,
Expand All @@ -98,6 +94,45 @@ def application_forms_without_status_filter
end
end

def application_forms_without_status_filter
@application_forms_without_status_filter ||=
::Filters::ActionableBy.apply(
scope: application_forms_without_actionable_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 actionable_by_filter_counts
@actionable_by_filter_counts ||=
application_forms_without_actionable_by_filter.group(:actionable_by).count
end

def actionable_by_filter_entry(name)
readable_name =
if name == "admin"
"Admin action"
elsif name == "assessor"
"Assessor action"
else
"No action"
end

OpenStruct.new(
id: name,
label: "#{readable_name} (#{actionable_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-actionable-by">
<%= f.govuk_check_boxes_fieldset :actionable_by, legend: { size: "s" }, small: true do %>
<% @view_object.actionable_by_filter_options.each do |option| %>
<%= f.govuk_check_box :actionable_by, option.id, label: { text: option.label }, checked: @view_object.filter_form.actionable_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
3 changes: 2 additions & 1 deletion config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,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 @@ -279,6 +279,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:
actionable_by: Workflow
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 :actionable_by_filter,
"#app-applications-filters-actionable-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_actionable_by_filter
then_i_see_a_list_of_applications_filtered_by_actionable_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_actionable_by_filter
admin_action_item =
applications_page.actionable_by_filter.items.find do |item|
item.label.text == "Admin action (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_actionable_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,
:actionable_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,
:actionable_by_assessor,
region: create(:region, country: create(:country, code: "ES")),
given_names: "Arnold",
family_name: "Drummond",
Expand Down

0 comments on commit 8f2d30c

Please sign in to comment.