-
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.
Add confirmation page for finder facets
Introduces page to confirm changes to the facets of a finder: - Hides diff / generated schema in a details component. - Have a shortened summary, don't bother attempting to summarise for humans, they can always click on view diff if needed. - Minimises the diff by sorting the properties as per the most common ordering in the existing JSON files (we don't want any diffs if someone submits without making any changes!) - Has summary list facets in the order they're defined (with the exception of deleted facets, which are a bit fiddly to slot into the correct spot. Jotting them onto the end is sufficient).
- Loading branch information
1 parent
4ca46df
commit fafecc7
Showing
5 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,50 @@ | ||
<% | ||
summary_card_actions ||= [] | ||
%> | ||
|
||
# Value for the summary page, where we only want to summarise the current facets | ||
summary_rows = schema.facets.map do |facet| | ||
{ | ||
key: facet["name"], | ||
value: facet["allowed_values"] ? | ||
facet["allowed_values"].first(3).map { |value| value["label"] }.join(", ") + (facet["allowed_values"].length > 3 ? "…" : "") | ||
: facet["type"].humanize, | ||
} | ||
end | ||
|
||
if (defined? previous_schema) | ||
# We're on the edit page, so want to summarise the changes. So overriding `summary_rows`. | ||
removed_facets = previous_schema.facets.map { |facet| facet["name"] } - schema.facets.map { |facet| facet["name"] } | ||
previous_schema_facet_names = previous_schema.facets.map { |facet| facet["name"] } | ||
proposed_schema_facet_names = schema.facets.map { |facet| facet["name"] } | ||
|
||
summary_rows = proposed_schema_facet_names.map do |facet_name| | ||
if (previous_schema_facet_names.include?(facet_name)) | ||
old_facet_config = previous_schema.facets.find { |f| f["name"] == facet_name } | ||
new_facet_config = schema.facets.find { |f| f["name"] == facet_name } | ||
updated = !facet_name.in?(removed_facets) && !old_facet_config.nil? && old_facet_config != new_facet_config | ||
|
||
{ | ||
key: facet_name, | ||
value: raw("Updated (click on 'View diff' for details)"), | ||
} if updated | ||
else | ||
{ | ||
key: facet_name, | ||
value: raw("Added (click on 'View diff' for details)"), | ||
} | ||
end | ||
end | ||
summary_rows.compact!.concat(removed_facets.map do |facet_name| | ||
{ | ||
key: facet_name, | ||
value: raw("Deleted"), | ||
} | ||
end) | ||
end | ||
%> | ||
<%= render "govuk_publishing_components/components/summary_card", { | ||
title: "Filters and options", | ||
rows: schema["facets"].map { |facet| { key: facet["name"] , value: facet["allowed_values"] ? facet["allowed_values"].first(3).map{ |value| value["label"] }.join(", ") + (facet["allowed_values"].length > 3 ? "…" : "") : facet["type"].humanize }}, | ||
rows: summary_rows, | ||
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,67 @@ | ||
<% content_for :breadcrumbs do %> | ||
<%= render "govuk_publishing_components/components/breadcrumbs", { | ||
collapse_on_mobile: true, | ||
breadcrumbs: [ | ||
{ | ||
title: "All finders", | ||
url: root_path | ||
}, | ||
{ | ||
title: "#{current_format.title} finder", | ||
url: "/admin/#{current_format.admin_slug}" | ||
}, | ||
{ | ||
title: "Request change", | ||
url: "/admin/facets/#{current_format.admin_slug}" | ||
}, | ||
{ | ||
title: "Check changes", | ||
url: request.original_url | ||
} | ||
] | ||
} %> | ||
<% end %> | ||
<% content_for :page_title, "Edit #{current_format.title} finder" %> | ||
<% content_for :title, "Check your changes before submitting" %> | ||
<% content_for :context, "#{current_format.title} finder" %> | ||
|
||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full govuk-body govuk-!-margin-top-8"> | ||
<%= render "facets_summary_card", { | ||
schema: @proposed_schema, | ||
previous_schema: @current_format.finder_schema, | ||
} %> | ||
|
||
<details> | ||
<summary>View diff</summary> | ||
<%= | ||
Diffy::Diff.new( | ||
JSON.pretty_generate(@current_format.finder_schema.as_json).to_s, | ||
JSON.pretty_generate(@proposed_schema.as_json).to_s, | ||
Check notice Code scanning / Brakeman Unescaped model attribute. Note
Unescaped model attribute.
|
||
allow_empty_diff: false, | ||
).to_s(:html).html_safe | ||
%> | ||
</details> | ||
|
||
<details> | ||
<summary>View generated schema</summary> | ||
<pre><code><%= JSON.pretty_generate(@proposed_schema.as_json) %></code></pre> | ||
</details> | ||
|
||
<p class="govuk-body govuk-body govuk-!-margin-top-7"> | ||
By submitting you are confirming that these changes are required to the specialist finder. | ||
</p> | ||
|
||
<div class="govuk-button-group govuk-!-margin-top-7"> | ||
<%= form_tag "/admin/zendesk/#{current_format.admin_slug}", method: 'post' do %> | ||
<%= hidden_field_tag :proposed_schema, JSON.pretty_generate(@proposed_schema) %> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Submit changes" | ||
} %> | ||
<% end %> | ||
|
||
<%= link_to("Cancel", "/admin/#{current_format.admin_slug}", class: "govuk-link govuk-link--no-visited-state") %> | ||
</div> | ||
</div> | ||
</div> |
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