-
Notifications
You must be signed in to change notification settings - Fork 193
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/876 style pension view #9902
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba3f3be
remove Details title per design
Harriethw b0a8526
add edit button to view of Block
Harriethw db46042
add new summary card for the block view
Harriethw 45e4eb4
use summary card component for showing blocks
Harriethw ce993ec
re-style banner on block view
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
4 changes: 4 additions & 0 deletions
4
...ponents/content_block_manager/content_block/document/show/summary_card_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,4 @@ | ||
<%= render "govuk_publishing_components/components/summary_card", { | ||
title:, | ||
rows:, | ||
} %> |
97 changes: 97 additions & 0 deletions
97
...pp/components/content_block_manager/content_block/document/show/summary_card_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,97 @@ | ||
class ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent < ViewComponent::Base | ||
def initialize(content_block_document:) | ||
@content_block_document = content_block_document | ||
end | ||
|
||
private | ||
|
||
attr_reader :content_block_document | ||
|
||
def rows | ||
[ | ||
title_item, | ||
*details_items, | ||
organisation_item, | ||
instructions_item, | ||
status_item, | ||
embed_code_item, | ||
].compact | ||
end | ||
|
||
def title | ||
"#{content_block_document.block_type.humanize} details" | ||
end | ||
|
||
def embed_code_item | ||
{ | ||
key: "Embed code", | ||
value: content_block_document.embed_code, | ||
data: { | ||
module: "copy-embed-code", | ||
"embed-code": content_block_document.embed_code, | ||
}, | ||
} | ||
end | ||
|
||
def title_item | ||
{ | ||
key: "Title", | ||
value: content_block_document.title, | ||
} | ||
end | ||
|
||
def organisation_item | ||
{ | ||
key: "Lead organisation", | ||
value: content_block_edition.lead_organisation, | ||
} | ||
end | ||
|
||
def instructions_item | ||
{ | ||
key: "Instructions to publishers", | ||
value: content_block_edition.instructions_to_publishers.presence || "None", | ||
} | ||
end | ||
|
||
def details_items | ||
content_block_edition.details.map do |key, value| | ||
{ | ||
key: key.humanize, | ||
value:, | ||
} | ||
end | ||
end | ||
|
||
def status_item | ||
if content_block_edition.state == "scheduled" | ||
{ | ||
key: "Status", | ||
value: scheduled_value, | ||
actions: [ | ||
{ | ||
label: sanitize("Edit <span class='govuk-visually-hidden'>schedule</span>"), | ||
href: helpers.content_block_manager.content_block_manager_content_block_document_schedule_edit_path(content_block_document), | ||
}, | ||
], | ||
} | ||
else | ||
{ | ||
key: "Status", | ||
value: last_updated_value, | ||
} | ||
end | ||
end | ||
|
||
def last_updated_value | ||
"Published #{time_ago_in_words(content_block_edition.updated_at)} ago by #{content_block_edition.creator.name}" | ||
end | ||
|
||
def scheduled_value | ||
"Scheduled for publication at #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}" | ||
end | ||
|
||
def content_block_edition | ||
@content_block_edition = content_block_document.latest_edition | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,7 +254,7 @@ | |
assert_text "Content Block Manager" | ||
|
||
ContentBlockManager::ContentBlock::Document.find_each do |document| | ||
should_show_summary_card_for_email_address_content_block( | ||
should_show_summary_title_for_email_address_content_block( | ||
document.title, | ||
document.latest_edition.details[:email_address], | ||
) | ||
|
@@ -263,7 +263,7 @@ | |
|
||
Then("I should see the details for all documents from my organisation") do | ||
ContentBlockManager::ContentBlock::Document.with_lead_organisation(@user.organisation.id).each do |document| | ||
should_show_summary_card_for_email_address_content_block( | ||
should_show_summary_title_for_email_address_content_block( | ||
document.title, | ||
document.latest_edition.details[:email_address], | ||
) | ||
|
@@ -289,9 +289,9 @@ | |
end | ||
|
||
Then("I should see the details for the email address content block") do | ||
assert_text "View email address" | ||
expect(page).to have_selector("h1", text: @content_block.document.title) | ||
|
||
should_show_summary_list_for_email_address_content_block( | ||
should_show_summary_card_for_email_address_content_block( | ||
@content_block.document.title, | ||
@email_address, | ||
@organisation, | ||
|
@@ -302,6 +302,10 @@ | |
click_link "Edit", match: :first | ||
end | ||
|
||
When("I click to edit the {string}") do |block_type| | ||
click_link "Edit #{block_type}", match: :first | ||
end | ||
|
||
When("I fill out the form") do | ||
change_details | ||
end | ||
|
@@ -314,7 +318,7 @@ | |
end | ||
|
||
Then("the edition should have been updated successfully") do | ||
should_show_summary_list_for_email_address_content_block( | ||
should_show_summary_card_for_email_address_content_block( | ||
"Changed title", | ||
"[email protected]", | ||
"Ministry of Example", | ||
|
6 changes: 3 additions & 3 deletions
6
lib/engines/content_block_manager/features/support/helpers.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
76 changes: 76 additions & 0 deletions
76
..._block_manager/test/components/content_block/document/show/summary_card_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,76 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponentTest < ViewComponent::TestCase | ||
extend Minitest::Spec::DSL | ||
include ContentBlockManager::Engine.routes.url_helpers | ||
|
||
let(:organisation) { create(:organisation, name: "Department for Example") } | ||
let!(:content_block_edition) do | ||
create( | ||
:content_block_edition, | ||
:email_address, | ||
details: { foo: "bar", something: "else" }, | ||
creator: build(:user), | ||
organisation:, | ||
scheduled_publication: Time.zone.now, | ||
state: "published", | ||
updated_at: 1.day.ago, | ||
) | ||
end | ||
let(:content_block_document) { content_block_edition.document } | ||
|
||
it "renders a published content block correctly" do | ||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__row", count: 7 | ||
|
||
assert_selector ".govuk-summary-card__title", text: "Email address details" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Title" | ||
assert_selector ".govuk-summary-list__value", text: content_block_document.title | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Foo" | ||
assert_selector ".govuk-summary-list__value", text: "bar" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Something" | ||
assert_selector ".govuk-summary-list__value", text: "else" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Lead organisation" | ||
assert_selector ".govuk-summary-list__value", text: "Department for Example" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Status" | ||
assert_selector ".govuk-summary-list__value", text: "Published 1 day ago by #{content_block_edition.creator.name}" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Instructions to publishers" | ||
assert_selector ".govuk-summary-list__value", text: "None" | ||
|
||
assert_selector ".govuk-summary-list__row[data-module='copy-embed-code']", text: "Embed code" | ||
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code" | ||
assert_selector ".govuk-summary-list__key", text: "Embed code" | ||
assert_selector ".govuk-summary-list__value", text: content_block_document.embed_code | ||
end | ||
|
||
it "renders a scheduled content block correctly" do | ||
content_block_document.latest_edition.state = "scheduled" | ||
|
||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__row", count: 7 | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Status" | ||
assert_selector ".govuk-summary-list__value", text: "Scheduled for publication at #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}" | ||
assert_selector ".govuk-summary-list__actions", text: "Edit schedule" | ||
assert_selector ".govuk-summary-list__actions a[href='#{content_block_manager_content_block_document_schedule_edit_path(content_block_document)}']" | ||
end | ||
|
||
describe "when there are instructions to publishers" do | ||
it "renders them" do | ||
content_block_document.latest_edition.instructions_to_publishers = "instructions" | ||
|
||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Instructions to publishers" | ||
assert_selector ".govuk-summary-list__value", text: "instructions" | ||
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'm not yet deleting the SummaryListComponent in
Show
because the SummaryCardComponent inIndex
inherits from it and there's a fair bit to unpick - think that makes sense to do when we go to re-design theIndex
view, but could pick it up here if we think we need to.