Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate options form components #468

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if schools.present? %>
<% if records.present? %>
<%= form_with(
model:,
scope: :school,
scope:,
url:,
method: "get",
data: { turbo: false },
Expand All @@ -11,29 +11,29 @@
<%= f.hidden_field :search_param, value: search_param %>

<h1 class="govuk-heading-l govuk-!-margin-bottom-0">
<span class="govuk-caption-l"><%= t(".add_organisation") %></span>
<span class="govuk-caption-l"><%= title %></span>
</h1>

<%= f.govuk_radio_buttons_fieldset(
:id,
scope: :school,
input_field_name,
scope:,
legend: {
text: t(
".legend",
school_count: schools.count,
results_count: records.count,
search_param:,
),
size: "l",
},
hint: { text: form_description },
) do %>

<% schools.first(OPTIONS_PER_PAGE).each do |school| %>
<%= f.govuk_radio_button :id,
school.id,
label: { text: school.name },
<% records.first(OPTIONS_PER_PAGE).each do |record| %>
<%= f.govuk_radio_button input_field_name,
record.id,
label: { text: record.name },
link_errors: true,
hint: { text: school.town_and_postcode } %>
hint: { text: record.town_and_postcode } %>
<% end %>
<% end %>

Expand Down
57 changes: 57 additions & 0 deletions app/components/options_form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class OptionsFormComponent < ApplicationComponent
OPTIONS_PER_PAGE = 15

attr_reader :model, :url, :search_param, :records, :records_klass,
:back_link, :scope, :input_field_name, :title

def initialize(
model:,
url:,
search_param:,
records:,
records_klass:,
back_link:,
scope:,
input_field_name: :id,
title: I18n.t("components.options_form_component.add_organisation"),
classes: [],
html_attributes: {}
)
super(classes:, html_attributes:)

@model = model
@url = url
@search_param = search_param
@records = records
@records_klass = records_klass.to_s.downcase
@back_link = back_link
@scope = scope
@input_field_name = input_field_name
@title = title
end

def form_description
if records.count > OPTIONS_PER_PAGE
t(
"components.options_form_component.paginated_form_description_html",
results_count: OPTIONS_PER_PAGE,
klass: records_klass,
link_to: govuk_link_to(
t("components.options_form_component.narrow_your_search"),
back_link,
no_visited_state: true,
),
)
else
t(
"components.options_form_component.form_description_html",
klass: records_klass,
link_to: govuk_link_to(
t("components.options_form_component.change_your_search"),
back_link,
no_visited_state: true,
),
)
end
end
end
51 changes: 0 additions & 51 deletions app/components/provider_options_form_component.html.erb

This file was deleted.

46 changes: 0 additions & 46 deletions app/components/provider_options_form_component.rb

This file was deleted.

46 changes: 0 additions & 46 deletions app/components/school_options_form_component.rb

This file was deleted.

6 changes: 4 additions & 2 deletions app/views/claims/support/schools/school_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<% end %>

<div class="govuk-width-container">
<%= render SchoolOptionsFormComponent.new(
<%= render OptionsFormComponent.new(
model: school_form,
scope: :school,
url: check_school_option_claims_support_schools_path,
search_param:,
schools:,
records: schools,
records_klass: "school",
back_link: new_claims_support_school_path,
) %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<% end %>

<div class="govuk-width-container">
<%= render ProviderOptionsFormComponent.new(
<%= render OptionsFormComponent.new(
model: provider_form,
scope: :provider,
url: check_provider_option_placements_support_providers_path,
search_param:,
providers:,
records: providers,
records_klass: "provider",
back_link: new_placements_support_provider_path,
) %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<% end %>

<div class="govuk-width-container">
<%= render SchoolOptionsFormComponent.new(
<%= render OptionsFormComponent.new(
model: school_form,
scope: :school,
url: check_school_option_placements_support_schools_path,
search_param:,
schools:,
records: schools,
records_klass: "school",
back_link: new_placements_support_school_path,
) %>

Expand Down
26 changes: 0 additions & 26 deletions config/locales/en/components.yml

This file was deleted.

11 changes: 11 additions & 0 deletions config/locales/en/components/options_form_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
en:
components:
options_form_component:
add_organisation: Add organisation
continue: Continue
paginated_form_description_html: Showing the first %{results_count} results. %{link_to} if the %{klass} you’re looking for is not listed.
form_description_html: "%{link_to} if the %{klass} you’re looking for is not listed."
change_your_search: Change your search
narrow_your_search: Try narrowing down your search
no_results: No results found for '%{search_param}'
legend: "%{results_count} results found for '%{search_param}'"
11 changes: 0 additions & 11 deletions config/locales/en/components/school_options_form_component.yml

This file was deleted.

Loading
Loading