-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3479 from alphagov/add-sort-facet
New all content finder UI: Add ability to sort
- Loading branch information
Showing
12 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# SortFacet is a "virtual" facet, in that it is only used for the new all content finder UI, where | ||
# sorting forms part of the overall filtering UI instead of being separate | ||
class SortFacet | ||
KEY = "order".freeze | ||
|
||
def name | ||
"Sort by" | ||
end | ||
alias_method :ga4_section, :name | ||
|
||
def key | ||
KEY | ||
end | ||
|
||
def to_partial_path | ||
self.class.name.underscore | ||
end | ||
|
||
def user_visible? | ||
true | ||
end | ||
|
||
# The methods below are the minimum required for this virtual facet to take the place of a real | ||
# `Facet` | ||
|
||
def has_filters? | ||
false | ||
end | ||
|
||
def filterable? | ||
true | ||
end | ||
|
||
def hide_facet_tag? | ||
false | ||
end | ||
|
||
def metadata? | ||
false | ||
end | ||
|
||
private | ||
|
||
attr_reader :sort_presenter | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/views/finders/all_content_finder_facets/_sort_facet.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= render "components/filter_section", { | ||
heading_text: sort_facet.name, | ||
id: "facet_sort", | ||
index_section: index, | ||
index_section_count: count, | ||
} do %> | ||
<%= render "govuk_publishing_components/components/radio", { | ||
heading: "Sort order", | ||
heading_level: 0, | ||
# Legend is visually hidden as non-screenreader users already have the section heading above | ||
visually_hidden_heading: true, | ||
margin_bottom: 2, | ||
name: sort_facet.key, | ||
small: true, | ||
items: @sort_presenter.to_radio_options, | ||
} %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "spec_helper" | ||
|
||
describe SortFacet do | ||
subject(:sort_facet) { described_class.new } | ||
|
||
describe "#name" do | ||
it "returns a value" do | ||
expect(sort_facet.name).not_to be_blank | ||
end | ||
end | ||
|
||
describe "#ga4_section" do | ||
it "is identical to #name" do | ||
expect(sort_facet.ga4_section).to eq(sort_facet.name) | ||
end | ||
end | ||
|
||
describe "#to_partial_path" do | ||
it "is the underscored class name" do | ||
expect(sort_facet.to_partial_path).to eq("sort_facet") | ||
end | ||
end | ||
|
||
it { is_expected.to be_user_visible } | ||
it { is_expected.to be_filterable } | ||
it { is_expected.not_to be_hide_facet_tag } | ||
it { is_expected.not_to be_metadata } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters