From 5856bb27109da46bde1d8c677d7be8c27f6bde46 Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 10 Jul 2024 17:08:53 +0100 Subject: [PATCH 1/5] Added Radius filter to Search results Filter only displays if the `radius` parameter is in the URL WIP: This does not have tests for the UI --- .../find/result_filters/filters_view.rb | 8 +++++++- app/views/find/result_filters/_all.html.erb | 1 + app/views/find/result_filters/_radius.html.erb | 14 ++++++++++++++ config/locales/find.yml | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/views/find/result_filters/_radius.html.erb diff --git a/app/view_objects/find/result_filters/filters_view.rb b/app/view_objects/find/result_filters/filters_view.rb index 7eb977d601..2d23e2d8e4 100644 --- a/app/view_objects/find/result_filters/filters_view.rb +++ b/app/view_objects/find/result_filters/filters_view.rb @@ -7,6 +7,12 @@ def initialize(params:) @params = params end + def radius_options = [1, 5, 10, 15, 20, 25, 50, 100, 200] + + def radius + params[:radius] + end + def qts_only_checked? checked?('qts') end @@ -120,7 +126,7 @@ def location_query_params loc: params[:loc], longitude: params[:longitude], query: params['provider.provider_name'], - radius: params[:radius], + # radius: params[:radius], sortby: params[:sortby] } end diff --git a/app/views/find/result_filters/_all.html.erb b/app/views/find/result_filters/_all.html.erb index 1588f31b61..2730a36c59 100644 --- a/app/views/find/result_filters/_all.html.erb +++ b/app/views/find/result_filters/_all.html.erb @@ -5,6 +5,7 @@
<%= form.submit "Apply filters", name: nil, class: "govuk-button", data: { qa: "apply-filters" } %> + <%= render "find/result_filters/radius", form: %> <%= render "find/result_filters/visa_filter", form: %> <%= render "find/result_filters/engineers_teach_physics_filter", form: %> <%= render "find/result_filters/study_type_filter", form: %> diff --git a/app/views/find/result_filters/_radius.html.erb b/app/views/find/result_filters/_radius.html.erb new file mode 100644 index 0000000000..9fa1f9ad86 --- /dev/null +++ b/app/views/find/result_filters/_radius.html.erb @@ -0,0 +1,14 @@ +<% if @filters_view.radius.present? %> +
+ + + +
+
+ <%= form.select :radius, options_for_select(@filters_view.radius_options.map { |r| [t(".radius_select.label", count: r), r] }, @filters_view.radius), {}, class: "govuk-select" %> +
+
+
+<% end %> diff --git a/config/locales/find.yml b/config/locales/find.yml index 12a30f551f..72ce34486d 100644 --- a/config/locales/find.yml +++ b/config/locales/find.yml @@ -33,6 +33,8 @@ en: missing_location: Enter a city, town or postcode missing_provider: Enter a real school, university or training provider blank_provider: Enter a provider name or code + fields: + location: "soemthing" fields: location: "Postcode, town or city" provider: "Training provider" @@ -200,6 +202,12 @@ en: html: PGDE without QTS links: national_pay_scales: https://www.gov.uk/government/publications/national-pay-scales-for-eligible-teaching-and-education-jobs/national-pay-scales-for-eligible-teaching-and-education-leadership-occupation-codes + result_filters: + radius: + radius_select: + label: + one: '%{count} mile' + other: '%{count} miles' activemodel: errors: models: From eea671ae9a99ee0f0e4fc90df02b9313c53edd2a Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 10 Jul 2024 17:12:00 +0100 Subject: [PATCH 2/5] Fix label/input naming --- app/views/find/result_filters/_radius.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/find/result_filters/_radius.html.erb b/app/views/find/result_filters/_radius.html.erb index 9fa1f9ad86..96aa340cd9 100644 --- a/app/views/find/result_filters/_radius.html.erb +++ b/app/views/find/result_filters/_radius.html.erb @@ -1,9 +1,7 @@ <% if @filters_view.radius.present? %>
- + <%= form.label :radius, "Search radius", class: "govuk-label govuk-fieldset__legend govuk-fieldset__legend--s" %>
From 2739d572e7bcb3a7a19d75a9976f680e688ccafd Mon Sep 17 00:00:00 2001 From: David Young Date: Wed, 10 Jul 2024 17:21:16 +0100 Subject: [PATCH 3/5] Refactored methods into Filters View --- app/forms/find/location_filter_form.rb | 2 +- .../find/result_filters/filters_view.rb | 5 +++- .../find/result_filters/_radius.html.erb | 4 ++-- config/locales/find.yml | 13 ++++------ .../find/result_filters/filters_view_spec.rb | 24 +++++++++++++++++++ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app/forms/find/location_filter_form.rb b/app/forms/find/location_filter_form.rb index 18485f5de9..4d0176ced5 100644 --- a/app/forms/find/location_filter_form.rb +++ b/app/forms/find/location_filter_form.rb @@ -41,7 +41,7 @@ def handle_location_option @params.merge!(geocode_params) @valid = true else - @errors = [I18n.t('find.location_filter.fields.location'), I18n.t('find.location_filter.errors.unknown_location')] + @errors = [I18n.t('find.fields.location'), I18n.t('find.location_filter.errors.unknown_location')] end end diff --git a/app/view_objects/find/result_filters/filters_view.rb b/app/view_objects/find/result_filters/filters_view.rb index 2d23e2d8e4..a2c01b9538 100644 --- a/app/view_objects/find/result_filters/filters_view.rb +++ b/app/view_objects/find/result_filters/filters_view.rb @@ -9,6 +9,10 @@ def initialize(params:) def radius_options = [1, 5, 10, 15, 20, 25, 50, 100, 200] + def radius_options_for_select + radius_options.map { |r| [I18n.t('find.result_filters_filters_view.radius_options_for_select.label', count: r), r] } + end + def radius params[:radius] end @@ -126,7 +130,6 @@ def location_query_params loc: params[:loc], longitude: params[:longitude], query: params['provider.provider_name'], - # radius: params[:radius], sortby: params[:sortby] } end diff --git a/app/views/find/result_filters/_radius.html.erb b/app/views/find/result_filters/_radius.html.erb index 96aa340cd9..c16c1c4af2 100644 --- a/app/views/find/result_filters/_radius.html.erb +++ b/app/views/find/result_filters/_radius.html.erb @@ -1,11 +1,11 @@ -<% if @filters_view.radius.present? %> +<% if @filters_view.location_query? %>
<%= form.label :radius, "Search radius", class: "govuk-label govuk-fieldset__legend govuk-fieldset__legend--s" %>
- <%= form.select :radius, options_for_select(@filters_view.radius_options.map { |r| [t(".radius_select.label", count: r), r] }, @filters_view.radius), {}, class: "govuk-select" %> + <%= form.select :radius, options_for_select(@filters_view.radius_options_for_select, @filters_view.radius), {}, class: "govuk-select" %>
diff --git a/config/locales/find.yml b/config/locales/find.yml index 72ce34486d..f4023322d1 100644 --- a/config/locales/find.yml +++ b/config/locales/find.yml @@ -33,8 +33,6 @@ en: missing_location: Enter a city, town or postcode missing_provider: Enter a real school, university or training provider blank_provider: Enter a provider name or code - fields: - location: "soemthing" fields: location: "Postcode, town or city" provider: "Training provider" @@ -202,12 +200,11 @@ en: html: PGDE without QTS links: national_pay_scales: https://www.gov.uk/government/publications/national-pay-scales-for-eligible-teaching-and-education-jobs/national-pay-scales-for-eligible-teaching-and-education-leadership-occupation-codes - result_filters: - radius: - radius_select: - label: - one: '%{count} mile' - other: '%{count} miles' + result_filters_filters_view: + radius_options_for_select: + label: + one: '%{count} mile' + other: '%{count} miles' activemodel: errors: models: diff --git a/spec/view_objects/find/result_filters/filters_view_spec.rb b/spec/view_objects/find/result_filters/filters_view_spec.rb index e1e689f277..9116627af7 100644 --- a/spec/view_objects/find/result_filters/filters_view_spec.rb +++ b/spec/view_objects/find/result_filters/filters_view_spec.rb @@ -354,6 +354,30 @@ module ResultFilters it { is_expected.to be(false) } end end + + describe '#radius' do + subject { described_class.new(params: { radius: 10 }).radius } + + it { is_expected.to eq(10) } + end + + describe '#radius_options_for_select' do + subject { described_class.new(params: {}).radius_options_for_select } + + it 'returns an array of arrays' do + expect(subject).to eq([ + ['1 mile', 1], + ['5 miles', 5], + ['10 miles', 10], + ['15 miles', 15], + ['20 miles', 20], + ['25 miles', 25], + ['50 miles', 50], + ['100 miles', 100], + ['200 miles', 200] + ]) + end + end end end end From 2fa6795c06f8a5f0bebfc59af810d36d2efd6d08 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 11 Jul 2024 09:39:41 +0100 Subject: [PATCH 4/5] Reduced default search radius to 10miles --- app/view_objects/find/results_view.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/view_objects/find/results_view.rb b/app/view_objects/find/results_view.rb index 057cc6e155..46330b9c3e 100644 --- a/app/view_objects/find/results_view.rb +++ b/app/view_objects/find/results_view.rb @@ -8,7 +8,7 @@ class ResultsView include ActionView::Helpers::NumberHelper DISTANCE = 'distance' - MILES = '50' + MILES = '10' def initialize(query_parameters:) @query_parameters = query_parameters From 10144b06c447f50674a65ae37000db1cbaab8950 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 11 Jul 2024 13:29:18 +0100 Subject: [PATCH 5/5] Updated spec --- spec/features/find/search/location_options_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/find/search/location_options_spec.rb b/spec/features/find/search/location_options_spec.rb index 3afe3abcc0..4fd1a9f8c6 100644 --- a/spec/features/find/search/location_options_spec.rb +++ b/spec/features/find/search/location_options_spec.rb @@ -62,7 +62,7 @@ def then_i_should_see_the_age_groups_form def and_the_correct_age_group_form_page_url_and_query_params_are_present URI(current_url).then do |uri| expect(uri.path).to eq('/age-groups') - expect(uri.query).to eq('c=England&l=1&latitude=51.4524877&loc=AA+Teamworks+W+Yorks+SCITT%2C+School+Street%2C+Greetland%2C+Halifax%2C+West+Yorkshire+HX4+8JB&longitude=-0.1204749&lq=Yorkshire&radius=50&sortby=distance') + expect(uri.query).to eq('c=England&l=1&latitude=51.4524877&loc=AA+Teamworks+W+Yorks+SCITT%2C+School+Street%2C+Greetland%2C+Halifax%2C+West+Yorkshire+HX4+8JB&longitude=-0.1204749&lq=Yorkshire&radius=10&sortby=distance') end end