-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - basic refactoring - move finder metadata summary to a view comp…
…onent Still need to internally refactor summary card code
- Loading branch information
Showing
4 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
app/components/finder_metadata_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,6 @@ | ||
<%= render "govuk_publishing_components/components/summary_card", { | ||
title: "Finder details", | ||
rows: render_finder_summary_rows, | ||
summary_card_actions: @summary_card_actions, | ||
margin_top: 6, | ||
} %> |
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,62 @@ | ||
class FinderMetadataSummaryCardComponent < ViewComponent::Base | ||
def initialize(schema, previous_schema: nil, summary_card_actions: []) | ||
@schema = schema | ||
@previous_schema = previous_schema | ||
@summary_card_actions = summary_card_actions | ||
end | ||
|
||
def render_finder_summary_rows | ||
[ | ||
({ | ||
Check failure on line 10 in app/components/finder_metadata_summary_card_component.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
key: "Title of the finder", | ||
value: @schema.name | ||
} if @previous_schema.nil? || @schema.name != @previous_schema.name), | ||
({ | ||
Check failure on line 14 in app/components/finder_metadata_summary_card_component.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
key: "Slug or URL", | ||
value: @schema.base_path | ||
} if @previous_schema.nil? || @schema.base_path != @previous_schema.base_path), | ||
({ | ||
Check failure on line 18 in app/components/finder_metadata_summary_card_component.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
key: "Organisations the finder should be attached to", | ||
value: (@schema.organisations || []).map { |content_id| helpers.organisation_name(content_id) }.compact.join(",") | ||
} if @previous_schema.nil? || @schema.organisations != @previous_schema.organisations), | ||
({ | ||
Check failure on line 22 in app/components/finder_metadata_summary_card_component.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
key: "Short description (For search engines)", | ||
value: @schema.description | ||
} if @previous_schema.nil? || @schema.description != @previous_schema.description), | ||
({ | ||
Check failure on line 26 in app/components/finder_metadata_summary_card_component.rb GitHub Actions / Lint Ruby / Run RuboCop
|
||
key: "Summary of the finder (Longer description shown below title)", | ||
value: sanitize("<div class='govspeak'>#{@schema.summary}</div>") | ||
} if @previous_schema.nil? || @schema.summary != @previous_schema.summary), | ||
({ | ||
key: "Any related links on GOV.UK?", | ||
value: related_links_value, | ||
} if @previous_schema.nil? || @schema.related != @previous_schema.related), | ||
({ | ||
key: "Should summary of each content show under the title in the finder list page?", | ||
value: @schema.show_summaries ? "Yes" : "No" | ||
} if @previous_schema.nil? || @schema.show_summaries != @previous_schema.show_summaries), | ||
({ | ||
key: "The document noun (How the documents on the finder are referred to)", | ||
value: (@schema.document_noun || "").humanize | ||
} if @previous_schema.nil? || @schema.document_noun != @previous_schema.document_noun), | ||
({ | ||
key: "Would you like to set up email alerts for the finder?", | ||
value: @schema.signup_content_id.present? ? "Yes" : "No" | ||
} if @previous_schema.nil? || (@schema.signup_content_id.present? != @previous_schema.signup_content_id.present?)) | ||
].compact | ||
end | ||
|
||
private | ||
|
||
def related_links_value | ||
if @schema.related | ||
related_links_content = "Yes" | ||
@schema.related.each_with_index do |content_id, index| | ||
related_links_content << sanitize("<p>Link #{index + 1}: #{content_id}</p>") | ||
end | ||
related_links_content | ||
else | ||
"No" | ||
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