Skip to content

Commit

Permalink
Add _SKE pending conditions_ supplementary status tag
Browse files Browse the repository at this point in the history
The various `ApplicationStatusTagComponent` classes all need to be
rendered with an additional _SKE pending conditions_ label when the
application in question is in the `recruited` state but has one or more
pending SKE conditions.
  • Loading branch information
stevehook committed Oct 12, 2023
1 parent d0b4243 commit f54e528
Show file tree
Hide file tree
Showing 30 changed files with 301 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ def status_row(application_choice)
if @show_status
{
key: 'Status',
value: render(ApplicationStatusTagComponent.new(application_choice:)),
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>

<% if @display_info_text %>
<% if @application_choice.application_not_sent? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module CandidateInterface
class ApplicationStatusTagComponent < ViewComponent::Base
delegate :status, to: :application_choice

def initialize(application_choice:, display_info_text: true)
def initialize(application_choice:, display_info_text: true, supplementary_statuses: [])
@application_choice = application_choice
@display_info_text = display_info_text
@supplementary_statuses = supplementary_statuses
end

def text
Expand Down Expand Up @@ -36,8 +37,27 @@ def colour
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end

attr_reader :application_choice
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ def status_row

{
key: 'Status',
value: render(ApplicationStatusTagComponent.new(application_choice:, display_info_text: false)),
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
display_info_text: false,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def course_details
def application_choice_status_row
{
key: 'Status',
value: render(ContinuousApplications::ApplicationStatusTagComponent.new(application_choice:)),
value: render(
ContinuousApplications::ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ def status_row(application_choice)
if @show_status
{
key: 'Status',
value: render(ApplicationStatusTagComponent.new(application_choice:)),
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
)
),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
<% end %>
</td>
<td class="govuk-table__cell">
<%= render CandidateInterface::ApplicationStatusTagComponent.new(application_choice: application_choice) %>
<%=
render CandidateInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
)
%>
</td>
</tr>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def course_details_row_value(application_choice)
def status_row(application_choice)
{
key: 'Status',
value: render(ApplicationStatusTagComponent.new(application_choice:)),
value: render(
ApplicationStatusTagComponent.new(
application_choice:,
supplementary_statuses: supplementary_statuses_for(application_choice:),
)
),
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
<%= application_choice.id %>
</span>
</h3>
<%= render ProviderInterface::ApplicationStatusTagComponent.new(application_choice: application_choice) %>
<span>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
) %>
</span>
</header>

<div class="govuk-grid-row app-grid-row--flex">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<%= application_choice.application_form.full_name %>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice: application_choice)) %>
<span>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
) %>
</span>
</h1>

<% if show_inset_text? -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module ProviderInterface
class ApplicationStatusTagComponent < ViewComponent::Base
delegate :status, to: :application_choice

def initialize(application_choice:)
def initialize(application_choice:, supplementary_statuses: [])
@application_choice = application_choice
@supplementary_statuses = supplementary_statuses
end

def text
Expand Down Expand Up @@ -33,8 +34,27 @@ def colour
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end

attr_reader :application_choice
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
<ul class="app-application-card__list govuk-list govuk-list--bullet">
<% application_choices.each do |application_choice| %>
<li class="govuk-list__item govuk-body-s">
<%= render SupportInterface::ApplicationStatusTagComponent.new(status: application_choice.status) %>
<%=
render(
SupportInterface::ApplicationStatusTagComponent.new(
status: application_choice.status,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
)
%>
<%= application_choice.current_course_option.course.name_and_code %> at <%= application_choice.current_course_option.provider.name %>
</li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def application_number_row
def status_row
{
key: 'Status',
value: render(SupportInterface::ApplicationStatusTagComponent.new(status: application_choice.status)),
value: render(
SupportInterface::ApplicationStatusTagComponent.new(
status: application_choice.status,
supplementary_statuses: supplementary_statuses_for(application_choice:),
),
),
}.merge(status_action_link)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<%= govuk_tag(text: text, colour: colour) %>
<% supplementary_tags do |supplementary_tag_text, supplementary_tag_colour| %>
<%= govuk_tag(text: supplementary_tag_text, colour: supplementary_tag_colour) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module SupportInterface
class ApplicationStatusTagComponent < ViewComponent::Base
def initialize(status:)
def initialize(status:, supplementary_statuses: [])
@status = status
@supplementary_statuses = supplementary_statuses
end

def text
Expand All @@ -26,5 +27,26 @@ def colour
raise "You need to define a colour for the #{@status} state"
end
end

def supplementary_tags
@supplementary_statuses.each do |supplementary_status|
yield supplementary_tag_text(supplementary_status), supplementary_tag_colour(supplementary_status)
end
end

private

def supplementary_tag_text(supplementary_status)
I18n.t!("supplementary_application_states.#{supplementary_status}.name")
end

def supplementary_tag_colour(supplementary_status)
case supplementary_status.to_s
when 'ske_pending_conditions'
'blue'
else
raise "You need to define a colour for the #{supplementary_status} supplementary state"
end
end
end
end
9 changes: 9 additions & 0 deletions app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def application_form_path
BackLinks.application_form_path
end

def supplementary_statuses_for(application_choice:)
[].tap do |supplementary_statuses|
if application_choice.recruited? &&
RecruitedWithPendingConditions.new(application_choice:).call
supplementary_statuses << :ske_pending_conditions
end
end
end

private

def back_link_url
Expand Down
31 changes: 3 additions & 28 deletions app/services/can_recruit_with_pending_conditions.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
class CanRecruitWithPendingConditions
attr_accessor :application_choice

def initialize(application_choice:)
self.application_choice = application_choice
end

class CanRecruitWithPendingConditions < HasPendingSkeConditionsOnly
def call
feature_flag_enabled? &&
application_has_offer? &&
offer_has_pending_ske_conditions? &&
all_non_ske_conditions_met? &&
application_choice.pending_conditions? &&
has_pending_ske_conditions_only? &&
provider_is_scitt? &&
course_is_within_time_limit?
end

private

def feature_flag_enabled?
FeatureFlag.active?(:recruit_with_pending_conditions)
end

def application_has_offer?
application_choice.offer.present?
end

def offer_has_pending_ske_conditions?
application_choice.offer.ske_conditions.any?(&:pending?)
end

def all_non_ske_conditions_met?
non_ske_conditions = application_choice.offer.conditions - application_choice.offer.ske_conditions
non_ske_conditions.all?(&:met?)
end

def provider_is_scitt?
application_choice.provider&.scitt?
end
Expand Down
35 changes: 35 additions & 0 deletions app/services/has_pending_ske_conditions_only.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class HasPendingSkeConditionsOnly
attr_accessor :application_choice

def initialize(application_choice:)
self.application_choice = application_choice
end

def has_pending_ske_conditions_only?
feature_flag_enabled? &&
application_has_offer? &&
offer_has_pending_ske_conditions? &&
all_non_ske_conditions_met?
end

private

def feature_flag_enabled?
FeatureFlag.active?(:recruit_with_pending_conditions)
end

def application_has_offer?
application_choice.offer.present?
end

def offer_has_pending_ske_conditions?
application_choice.offer.conditions.any? do |condition|
condition.is_a?(SkeCondition) && condition.pending?
end
end

def all_non_ske_conditions_met?
non_ske_conditions = application_choice.offer.conditions - application_choice.offer.ske_conditions
non_ske_conditions.all?(&:met?)
end
end
5 changes: 5 additions & 0 deletions app/services/recruited_with_pending_conditions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RecruitedWithPendingConditions < HasPendingSkeConditionsOnly
def call
application_choice.recruited? && has_pending_ske_conditions_only?
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<h1 class="govuk-heading-xl govuk-!-margin-bottom-6">
<%= @application_choice.application_form.full_name %>
<%= render(ProviderInterface::ApplicationStatusTagComponent.new(application_choice: @application_choice)) %>
<%= render(
ProviderInterface::ApplicationStatusTagComponent.new(
application_choice: @application_choice,
supplementary_statuses: supplementary_statuses_for(application_choice: @application_choice),
),
) %>
</h1>

<%= form_with(
Expand Down
Loading

0 comments on commit f54e528

Please sign in to comment.