Skip to content

Commit

Permalink
Swap Organisation filter's select_with_search for autocomplete
Browse files Browse the repository at this point in the history
It made no sense for this to be a "Grouped option" select (which
is only officially supported by the 'select with search'
component), as at time of writing there are over 1200 orgs in
total. No publisher is going to benefit from scrolling all the
way down the long list of orgs to see which ones sit under
"Live organisations" vs which ones sit under "Closed
organisations". They're simply going to search for the relevant
org - something that is fully supported by the 'autocomplete'
component provided we go with `options` rather than
`grouped_options`.

It looks like the decision to put these into grouped options
was made 11 years ago, primarily to avoid having two separate
dropdown inputs. It's not clear whether one simple input without
group options was ever considered:
8b02269
  • Loading branch information
ChrisBAshton committed Feb 21, 2025
1 parent 2aaf668 commit 20685b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
52 changes: 17 additions & 35 deletions app/helpers/admin/editions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,26 @@ def edition_type(edition)
end

def admin_organisation_filter_options(selected_organisation)
organisations = Organisation.with_translations(:en).order(:name).excluding_govuk_status_closed || []
closed_organisations = Organisation.with_translations(:en).closed || []
blank_option = [
{
text: "All organisations",
value: "",
selected: selected_organisation.blank?,
},
]
open_organisations = Organisation.with_translations(:en).order(:name).excluding_govuk_status_closed || []
if current_user.organisation
organisations = [current_user.organisation] + (organisations - [current_user.organisation])
open_organisations = [current_user.organisation] + (organisations - [current_user.organisation])
end
closed_organisations = Organisation.with_translations(:en).closed || []

[
[
"",
[
{
text: "All organisations",
value: "",
selected: selected_organisation.blank?,
},
],
],
[
"Live organisations",
organisations.map do |organisation|
{
text: organisation.select_name,
value: organisation.id,
selected: selected_organisation.to_s == organisation.id.to_s,
}
end,
],
[
"Closed organisations",
closed_organisations.map do |organisation|
{
text: organisation.select_name,
value: organisation.id,
selected: selected_organisation.to_s == organisation.id.to_s,
}
end,
],
]
blank_option + (open_organisations + closed_organisations).map do |organisation|
{
text: organisation.select_name,
value: organisation.id,
selected: selected_organisation.to_s == organisation.id.to_s,
}
end
end

def admin_author_filter_options(current_user)
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/editions/_filter_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<% end %>

<% if filter_by.include?(:organisation) %>
<%= render "components/select_with_search", {
<%= render "components/autocomplete", {
label: "Organisation",
id: "organisation_filter",
name: "organisation",
heading_size: "s",
grouped_options: admin_organisation_filter_options(@filter.options[:organisation]),
options: admin_organisation_filter_options(@filter.options[:organisation]),
} %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
value: @filter.options[:title],
} %>

<%= render "components/select_with_search", {
<%= render "components/autocomplete", {
label: "Organisation",
id: "organisation_filter",
name: "organisation_id",
heading_size: "s",
grouped_options: admin_organisation_filter_options(@filter.options[:organisation_id]),
options: admin_organisation_filter_options(@filter.options[:organisation_id]),
} %>

<%= render "govuk_publishing_components/components/select", {
Expand Down

0 comments on commit 20685b3

Please sign in to comment.