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

Added Radius filter to Search results #4361

Merged
merged 5 commits into from
Jul 17, 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
2 changes: 1 addition & 1 deletion app/forms/find/location_filter_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion app/view_objects/find/result_filters/filters_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def initialize(params:)
@params = params
end

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

def qts_only_checked?
checked?('qts')
end
Expand Down Expand Up @@ -120,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
Expand Down
2 changes: 1 addition & 1 deletion app/view_objects/find/results_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ResultsView
include ActionView::Helpers::NumberHelper

DISTANCE = 'distance'
MILES = '50'
MILES = '10'

def initialize(query_parameters:)
@query_parameters = query_parameters
Expand Down
1 change: 1 addition & 0 deletions app/views/find/result_filters/_all.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<div class="app-filter__content">
<%= 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: %>
Expand Down
12 changes: 12 additions & 0 deletions app/views/find/result_filters/_radius.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @filters_view.location_query? %>
<fieldset class="govuk-fieldset app-filter__group" data-qa="filters__radius">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--s">
<%= form.label :radius, "Search radius", class: "govuk-label govuk-fieldset__legend govuk-fieldset__legend--s" %>
</legend>
<div class="govuk-checkboxes govuk-checkboxes--small">
<div class="govuk-checkboxes__item" data-qa="radius-select">
<%= form.select :radius, options_for_select(@filters_view.radius_options_for_select, @filters_view.radius), {}, class: "govuk-select" %>
</div>
</div>
</fieldset>
<% end %>
5 changes: 5 additions & 0 deletions config/locales/find.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ en:
html: <abbr title='Postgraduate diploma in education'>PGDE</abbr> without <abbr title='Qualified teacher status'>QTS</abbr>
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_filters_view:
radius_options_for_select:
label:
one: '%{count} mile'
other: '%{count} miles'
Comment on lines +206 to +207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

activemodel:
errors:
models:
Expand Down
2 changes: 1 addition & 1 deletion spec/features/find/search/location_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions spec/view_objects/find/result_filters/filters_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading