Skip to content

Commit

Permalink
Use Filters::Stage
Browse files Browse the repository at this point in the history
This changes the case management index page to use the new stage filter,
and stop using the statuses filter.
  • Loading branch information
thomasleese committed Sep 18, 2023
1 parent 751b28f commit 05662eb
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 242 deletions.
2 changes: 1 addition & 1 deletion app/forms/assessor_interface/filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AssessorInterface::FilterForm
:location,
:name,
:reference,
:statuses,
:stage,
:submitted_at_after,
:submitted_at_before
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,29 @@ def action_required_by_filter_options
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|
status_filter_entry(status, sub_status)
end
end
def stage_filter_options
STAGE_FILTER_OPTIONS.map { |name| stage_filter_entry(name) }
end

private

ACTION_REQUIRED_BY_OPTIONS = %w[admin assessor external].freeze

STATUS_FILTER_OPTIONS = {
preliminary_check: [],
submitted: [],
assessment_in_progress: [],
waiting_on: %i[
further_information
professional_standing
qualification
reference
],
received: %i[
further_information
professional_standing
qualification
reference
],
overdue: [],
awarded_pending_checks: [],
awarded: [],
declined: [],
potential_duplicate_in_dqt: [],
withdrawn: [],
}.freeze
STAGE_FILTER_OPTIONS = %w[
pre_assessment
not_started
assessment
verification
review
completed
].freeze

def filter_params
(session[:filter_params] || {}).with_indifferent_access
end

def application_forms_without_action_required_by_filter
@application_forms_without_action_required_by_filter ||=
def application_forms_without_counted_filters
@application_forms_without_counted_filters ||=
begin
filters = [
::Filters::Assessor,
Expand All @@ -96,29 +77,29 @@ def application_forms_without_action_required_by_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,
::Filters::Stage.apply(
scope:
::Filters::ActionRequiredBy.apply(
scope: application_forms_without_counted_filters,
params: filter_params,
),
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
::Filters::Stage
.apply(
scope: application_forms_without_counted_filters,
params: filter_params,
)
.group(:action_required_by)
.count
end

def action_required_by_filter_entry(name)
Expand All @@ -129,52 +110,28 @@ def action_required_by_filter_entry(name)
)
end

def status_filter_counts
@status_filter_counts ||=
begin
all_options =
STATUS_FILTER_OPTIONS.each_with_object(
{},
) do |(status, substatuses), memo|
memo[status.to_s] = nil

substatuses.each do |substatus|
memo["#{status}_#{substatus}"] = status.to_s
end
end

table = ApplicationForm.arel_table

counts =
all_options.filter_map do |status, parent_status|
if parent_status.present?
Arel.star.count.filter(
table[:status].eq(parent_status).and(table[status].eq(true)),
)
else
Arel.star.count.filter(table[:status].eq(status))
end
end

results = application_forms_without_status_filter.pick(*counts)

Hash[all_options.keys.zip(results)]
end
def stage_filter_counts
@stage_filter_counts ||=
::Filters::ActionRequiredBy
.apply(
scope: application_forms_without_counted_filters,
params: filter_params,
)
.group(:stage)
.count
end

def status_filter_entry(*status_path)
name = status_path.join("_")

def stage_filter_entry(name)
readable_name =
I18n.t(
status_path.last,
name,
scope: %i[components status_tag],
default: status_path.last.to_s.humanize,
default: name.to_s.humanize,
)

OpenStruct.new(
id: name,
label: "#{readable_name} (#{status_filter_counts.fetch(name, 0)})",
label: "#{readable_name} (#{stage_filter_counts.fetch(name, 0)})",
)
end

Expand Down
20 changes: 4 additions & 16 deletions app/views/assessor_interface/application_forms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,10 @@
<% 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| %>
<% if suboptions.present? %>
<div class="govuk-checkboxes__item govuk-!-padding-left-0 govuk-!-margin-top-1 govuk-!-margin-bottom-1">
<span class="govuk-label"><%= option.label %></span>
</div>

<div class="govuk-!-margin-left-4">
<% suboptions.each do |option| %>
<%= f.govuk_check_box :statuses, option.id, label: { text: option.label }, checked: @view_object.filter_form.statuses&.include?(option.id) %>
<% end %>
</div>
<% else %>
<%= f.govuk_check_box :statuses, option.id, label: { text: option.label }, checked: @view_object.filter_form.statuses&.include?(option.id) %>
<% end %>
<section id="app-applications-filters-stage">
<%= f.govuk_check_boxes_fieldset :stage, legend: { size: "s" }, small: true do %>
<% @view_object.stage_filter_options.each do |option| %>
<%= f.govuk_check_box :stage, option.id, label: { text: option.label }, checked: @view_object.filter_form.stage&.include?(option.id) %>
<% end %>
<% end %>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Applications < SitePrism::Page
sections :items, GovukCheckboxItem, ".govuk-checkboxes__item"
end

section :status_filter, "#app-applications-filters-status" do
sections :statuses, GovukCheckboxItem, ".govuk-checkboxes__item"
section :stage_filter, "#app-applications-filters-stage" do
sections :items, GovukCheckboxItem, ".govuk-checkboxes__item"
end

sections :search_results, ".app-search-results__item" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
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
and_i_apply_the_stage_filter
then_i_see_a_list_of_applications_filtered_by_stage
end

private
Expand Down Expand Up @@ -146,18 +146,18 @@ def then_i_see_a_list_of_applications_filtered_by_action_required_by
)
end

def and_i_apply_the_status_filter
awarded_state =
applications_page.status_filter.statuses.find do |status|
status.label.text == "Awarded (1)"
def and_i_apply_the_stage_filter
completed_item =
applications_page.stage_filter.items.find do |item|
item.label.text == "Completed (1)"
rescue Capybara::ElementNotFound
false
end
awarded_state.checkbox.click
completed_item.checkbox.click
applications_page.apply_filters.click
end

def then_i_see_a_list_of_applications_filtered_by_state
def then_i_see_a_list_of_applications_filtered_by_stage
expect(applications_page.search_results.count).to eq(1)
expect(applications_page.search_results.first.name.text).to eq("John Smith")
end
Expand Down
Loading

0 comments on commit 05662eb

Please sign in to comment.