Skip to content

Commit

Permalink
WIP - basic refactoring - move finder metadata summary to a view comp…
Browse files Browse the repository at this point in the history
…onent

Still need to internally refactor summary card code
  • Loading branch information
minhngocd committed Dec 16, 2024
1 parent efc74f1 commit d813ac5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 16 deletions.
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,
} %>
62 changes: 62 additions & 0 deletions app/components/finder_metadata_summary_card_component.rb
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

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
key: "Title of the finder",
value: @schema.name

Check failure on line 12 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
} if @previous_schema.nil? || @schema.name != @previous_schema.name),
({

Check failure on line 14 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
key: "Slug or URL",
value: @schema.base_path

Check failure on line 16 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
} 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

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
key: "Organisations the finder should be attached to",
value: (@schema.organisations || []).map { |content_id| helpers.organisation_name(content_id) }.compact.join(",")

Check failure on line 20 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
} if @previous_schema.nil? || @schema.organisations != @previous_schema.organisations),
({

Check failure on line 22 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
key: "Short description (For search engines)",
value: @schema.description

Check failure on line 24 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
} if @previous_schema.nil? || @schema.description != @previous_schema.description),
({

Check failure on line 26 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MultilineIfModifier: Favor a normal if-statement over a modifier clause in a multiline statement. (https://rubystyle.guide#no-multiline-if-modifiers)
key: "Summary of the finder (Longer description shown below title)",
value: sanitize("<div class='govspeak'>#{@schema.summary}</div>")

Check failure on line 28 in app/components/finder_metadata_summary_card_component.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
} 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
5 changes: 1 addition & 4 deletions app/views/admin/confirm_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds govuk-body govuk-!-margin-top-8">
<%= render "metadata_summary_card", {
schema: @proposed_schema,
previous_schema: @current_format.finder_schema,
} %>
<%= render FinderMetadataSummaryCardComponent.new(current_format.finder_schema,previous_schema: @current_format.finder_schema) %>

<p class="govuk-body govuk-body govuk-!-margin-top-7">
By submitting you are confirming that these changes are required to the specialist finder.
Expand Down
19 changes: 7 additions & 12 deletions app/views/admin/summary.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

<%= render "govuk_publishing_components/components/inset_text", {
} do %>
<%= render "govuk_publishing_components/components/inset_text", {} do %>
<%= link_to("View on website (opens in new tab)", current_format.live_url, class: "govuk-link", target: "_blank", rel: "noopener") %>
<% end %>

Expand All @@ -38,7 +37,6 @@
},
]
} %>

</div>
</div>

Expand All @@ -58,14 +56,11 @@
If you expect multiple changes over a period of time, it will be much more efficient to group these in one request.
</p>

<%= render "metadata_summary_card", {
schema: current_format.finder_schema,
summary_card_actions: [
{
label: "Request changes",
href: "/admin/metadata/#{current_format.admin_slug}"
},
],
} %>
<%= render FinderMetadataSummaryCardComponent.new(current_format.finder_schema,
summary_card_actions: [{
label: "Request changes",
href: "/admin/metadata/#{current_format.admin_slug}"
}])
%>
</div>
</div>

0 comments on commit d813ac5

Please sign in to comment.