Skip to content

Commit

Permalink
add an 'all organisations' default option for filter
Browse files Browse the repository at this point in the history
again mimic-ing what Whitehall have on their
filters, and makes it clearer to the user what
they are selecting.
  • Loading branch information
Harriethw committed Oct 29, 2024
1 parent 0d72d75 commit 9fc8ed2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
name: "lead_organisation",
label: "Lead organisation",
heading_size: "s",
include_blank: true,
include_blank: false,
options: options_for_lead_organisation,
} %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ def items_for_block_type
{
label: schema_name.humanize,
value: schema_name,
checked: !@filters.nil? && @filters[:block_type]&.include?(schema_name),
checked: @filters.any? && @filters[:block_type]&.include?(schema_name),
}
end
end

def options_for_lead_organisation
def all_organisations_option
{
text: "All organisations",
value: "",
selected: @filters.none? || @filters[:lead_organisation]&.empty?,
}
end

def taggable_organisations_options
helpers.taggable_organisations_container.map do |name, id|
{
text: name,
value: id,
selected: !@filters.nil? && @filters[:lead_organisation] == id.to_s,
selected: @filters.any? && @filters[:lead_organisation] == id.to_s,
}
end
end

def options_for_lead_organisation
[all_organisations_option].push(*taggable_organisations_options)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Search for a content object
When I visit the Content Block Manager home page
Then my organisation is already selected as a filter
And I should see the details for all documents from my organisation
When I select the lead organisation ""
When I select the lead organisation "All organisations"
And I click to view results
Then "3" content blocks are returned

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
should_show_summary_card_for_email_address_content_block(
document.title,
document.latest_edition.details[:email_address],
)
)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ class ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent
assert_selector "input[type='checkbox'][name='block_type[]'][value='postal_address']"
end

test "returns organisations with an 'all organisations' option" do
helper_mock = mock
ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.any_instance.stubs(:helpers).returns(helper_mock)
helper_mock.stubs(:content_block_manager).returns(helper_mock)
helper_mock.stubs(:content_block_manager_content_block_documents_path).returns("path")
helper_mock.stubs(:taggable_organisations_container).returns(
[["Department of Placeholder", 1], ["Ministry of Example", 2]],
)
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new(filters: {}))

assert_selector "select[name='lead_organisation']"
assert_selector "option[selected='selected'][value='']"
end

test "selects organisation if selected in filters" do
helper_mock = mock
ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.any_instance.stubs(:helpers).returns(helper_mock)
Expand Down

0 comments on commit 9fc8ed2

Please sign in to comment.