Skip to content

Commit

Permalink
Add suitability flag to application index
Browse files Browse the repository at this point in the history
This adds a tag to each application in the index view when an
application is flagged for suitability.
  • Loading branch information
thomasleese committed Jul 26, 2024
1 parent 7474dfc commit b1d52de
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<li class="app-search-results__item">
<h2 class="app-search-result__item-title">
<%= govuk_link_to full_name, href %>
<% if unsuitable %>
<%= govuk_tag(text: "Flagged for suitablilty", colour: "red") %>
<% end %>
</h2>

<%= render(DescriptionList::Component.new(
Expand Down
5 changes: 4 additions & 1 deletion app/components/application_form_search_result/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

module ApplicationFormSearchResult
class Component < ViewComponent::Base
def initialize(application_form, current_staff:)
def initialize(application_form, current_staff:, unsuitable:)
super
@application_form = application_form
@current_staff = current_staff
@unsuitable = unsuitable
end

def full_name
Expand All @@ -26,6 +27,8 @@ def summary_rows
)
end

attr_reader :unsuitable

private

attr_reader :application_form, :current_staff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def stage_filter_options
STAGE_FILTER_OPTIONS.map { |name| stage_filter_entry(name) }
end

def flag_as_unsuitable?(application_form)
suitability_active? &&
suitability_matcher.flag_as_unsuitable?(application_form:)
end

private

ACTION_REQUIRED_BY_OPTIONS = %w[admin assessor external].freeze
Expand Down Expand Up @@ -142,4 +147,12 @@ def stage_filter_entry(name)
end

attr_reader :params, :session

def suitability_active?
@suitability_active ||= FeatureFlags::FeatureFlag.active?(:suitability)
end

def suitability_matcher
@suitability_matcher ||= SuitabilityMatcher.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<% if (records = @view_object.application_forms_records).present? %>
<ul class="app-search-results">
<% records.each do |application_form| %>
<%= render(ApplicationFormSearchResult::Component.new(application_form, current_staff:)) %>
<%= render(ApplicationFormSearchResult::Component.new(application_form, current_staff:, unsuitable: @view_object.flag_as_unsuitable?(application_form))) %>
<% end %>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

RSpec.describe ApplicationFormSearchResult::Component, type: :component do
subject(:component) do
render_inline(described_class.new(application_form, current_staff:))
render_inline(
described_class.new(application_form, current_staff:, unsuitable: false),
)
end

let(:application_form) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
let(:params) { {} }
let(:session) { {} }

before do
FeatureFlags::FeatureFlag.activate(:suitability)
end
before { FeatureFlags::FeatureFlag.activate(:suitability) }

after do
FeatureFlags::FeatureFlag.deactivate(:suitability)
end
after { FeatureFlags::FeatureFlag.deactivate(:suitability) }

describe "#application_forms_pagy" do
subject(:application_forms_pagy) { view_object.application_forms_pagy }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
)
end

before { FeatureFlags::FeatureFlag.activate(:suitability) }

after { FeatureFlags::FeatureFlag.deactivate(:suitability) }

let(:params) { {} }
let(:current_staff) { create(:staff) }

Expand Down

0 comments on commit b1d52de

Please sign in to comment.