-
Notifications
You must be signed in to change notification settings - Fork 194
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
Content modelling/627 filter by type and lead organisation #9557
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b8cc3e
add option to filter by content block type
Harriethw a627a97
create filter options component for content blocks
Harriethw c7f6878
add SearchByLeadOrganisation to Content Block Documents
Harriethw fcf8af8
add lead_organisation filter to Content Block Document Filter
Harriethw 66a7a99
search by lead organisation from Content Block Manager
Harriethw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ents/content_block_manager/content_block/document/index/filter_options_component.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,35 @@ | ||
<%= form_with url: helpers.content_block_manager.content_block_manager_content_block_documents_path, method: :get do %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Keyword", | ||
bold: true, | ||
}, | ||
hint: 'For example, "driving standards"', | ||
name: "keyword", | ||
id: "keyword_filter", | ||
value: [email protected]? && @filters[:keyword], | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/checkboxes", { | ||
heading: "Content block type", | ||
heading_size: "s", | ||
no_hint_text: true, | ||
id: "block_type", | ||
name: "block_type[]", | ||
items: items_for_block_type, | ||
} %> | ||
|
||
<%= render "components/select_with_search", { | ||
id: "lead_organisation", | ||
name: "lead_organisation", | ||
label: "Lead organisation", | ||
heading_size: "s", | ||
include_blank: true, | ||
options: options_for_lead_organisation, | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/button", { | ||
text: "View results", | ||
margin_bottom: 4, | ||
} %> | ||
<% end %> |
28 changes: 28 additions & 0 deletions
28
...components/content_block_manager/content_block/document/index/filter_options_component.rb
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 @@ | ||
class ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent < ViewComponent::Base | ||
include ActionView::Helpers::RecordTagHelper | ||
def initialize(filters:) | ||
@filters = filters | ||
end | ||
|
||
private | ||
|
||
def items_for_block_type | ||
ContentBlockManager::ContentBlock::Schema.valid_schemas.map do |schema_name| | ||
{ | ||
label: schema_name.humanize, | ||
value: schema_name, | ||
checked: [email protected]? && @filters[:block_type]&.include?(schema_name), | ||
} | ||
end | ||
end | ||
|
||
def options_for_lead_organisation | ||
helpers.taggable_organisations_container.map do |name, id| | ||
{ | ||
text: name, | ||
value: id, | ||
selected: [email protected]? && @filters[:lead_organisation] == id.to_s, | ||
} | ||
end | ||
end | ||
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
12 changes: 12 additions & 0 deletions
12
...ls/content_block_manager/content_block/document/scopes/searchable_by_lead_organisation.rb
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,12 @@ | ||
module ContentBlockManager | ||
module ContentBlock::Document::Scopes::SearchableByLeadOrganisation | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :with_lead_organisation, | ||
lambda { |id| | ||
joins(latest_edition: :edition_organisation).where("content_block_edition_organisations.organisation_id = :id", id:) | ||
} | ||
end | ||
end | ||
end |
17 changes: 0 additions & 17 deletions
17
..._manager/app/views/content_block_manager/content_block/documents/_filter_options.html.erb
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,18 +2,23 @@ Feature: Search for a content object | |
Background: | ||
Given the content block manager feature flag is enabled | ||
Given I am a GDS admin | ||
And the organisation "Ministry of Example" exists | ||
And the organisation "Department of Placeholder" exists | ||
And a schema "email_address" exists with the following fields: | ||
| email_address | | ||
And a schema "postal_address" exists with the following fields: | ||
| an_address | | ||
And an email address content block has been created | ||
And an email address content block has been created with the following email address and title: | ||
| title | "example search title" | | ||
| email_address | "[email protected]" | | ||
| title | example search title | | ||
| email_address | [email protected] | | ||
And a "postal_address" type of content block has been created with fields: | ||
| an_address | ABC123 | | ||
| organisation | Department of Placeholder | | ||
|
||
Scenario: GDS Editor searches for a content object by keyword in title | ||
When I visit the Content Block Manager home page | ||
Then I should see the details for all documents | ||
And "2" content blocks are returned | ||
And "3" content blocks are returned | ||
When I enter the keyword "example search" | ||
And I click to view results | ||
Then I should see the content block with title "example search title" returned | ||
|
@@ -22,8 +27,24 @@ Feature: Search for a content object | |
Scenario: GDS Editor searches for a content object by keyword in details | ||
When I visit the Content Block Manager home page | ||
Then I should see the details for all documents | ||
And "2" content blocks are returned | ||
And "3" content blocks are returned | ||
When I enter the keyword "ministry justice" | ||
And I click to view results | ||
Then I should see the content block with title "example search title" returned | ||
And "1" content blocks are returned | ||
And "1" content blocks are returned | ||
|
||
Scenario: GDS Editor searches for a content object by block type | ||
When I visit the Content Block Manager home page | ||
Then I should see the details for all documents | ||
And "3" content blocks are returned | ||
When I check the block type "Email address" | ||
And I click to view results | ||
And "2" content blocks are returned | ||
|
||
Scenario: GDS Editor searches for a content object by lead organisation | ||
When I visit the Content Block Manager home page | ||
Then I should see the details for all documents | ||
And "3" content blocks are returned | ||
When I select the lead organisation "Department of Placeholder" | ||
And I click to view results | ||
And "1" content blocks are returned |
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
47 changes: 47 additions & 0 deletions
47
...ock_manager/test/components/content_block/document/index/filter_options_component_test.rb
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,47 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponentTest < ViewComponent::TestCase | ||
test "adds value of keyword to text input from filter" do | ||
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new( | ||
filters: { keyword: "ministry defense" }, | ||
)) | ||
|
||
assert_selector "input[name='keyword'][value='ministry defense']" | ||
end | ||
|
||
test "renders checkbox items for all valid schemas" do | ||
ContentBlockManager::ContentBlock::Schema.expects(:valid_schemas).returns(%w[email_address postal_address]) | ||
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new( | ||
filters: {}, | ||
)) | ||
|
||
assert_selector "input[type='checkbox'][name='block_type[]'][value='email_address']" | ||
assert_selector "input[type='checkbox'][name='block_type[]'][value='postal_address']" | ||
end | ||
|
||
test "checks checkbox items if checked in filters" do | ||
ContentBlockManager::ContentBlock::Schema.expects(:valid_schemas).returns(%w[email_address postal_address]) | ||
render_inline(ContentBlockManager::ContentBlock::Document::Index::FilterOptionsComponent.new( | ||
filters: { block_type: %w[email_address] }, | ||
)) | ||
|
||
assert_selector "input[type='checkbox'][name='block_type[]'][value='email_address'][checked]" | ||
assert_selector "input[type='checkbox'][name='block_type[]'][value='postal_address']" | ||
end | ||
|
||
test "selects organisation if selected in filters" 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: { lead_organisation: "2" }, | ||
)) | ||
|
||
assert_selector "select[name='lead_organisation']" | ||
assert_selector "option[selected='selected'][value=2]" | ||
end | ||
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
20 changes: 20 additions & 0 deletions
20
.../app/models/content_block_edition/document/scopes/searchable_by_lead_organisation_test.rb
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,20 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::SearchableByLeadOrganisationTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
describe ".with_lead_organisation" do | ||
test "finds documents with lead organisation on latest edition" do | ||
matching_organisation = create(:organisation, id: "1234") | ||
document_with_org = create(:content_block_document, :email_address) | ||
_edition_with_org = create(:content_block_edition, | ||
:email_address, | ||
document: document_with_org, | ||
organisation: matching_organisation) | ||
document_without_org = create(:content_block_document, :email_address) | ||
_edition_without_org = create(:content_block_edition, :email_address, document: document_without_org) | ||
_document_without_latest_edition = create(:content_block_document, :email_address) | ||
assert_equal [document_with_org], ContentBlockManager::ContentBlock::Document.with_lead_organisation("1234") | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like all this in a component 👍