Skip to content

Commit d098235

Browse files
Update document type change summary copy
- Add `common_association_items` to display associations that will not be changed by the document type change - Add `association_to_label` for associations that have different labels in the interface to how they are referenced in the schema
1 parent 7b69424 commit d098235

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

app/components/admin/editions/document_type_change_summary.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<% if lost_association_items.any? || new_association_items.any? %>
1414
<%= render "govuk_publishing_components/components/summary_list", {
1515
title: "Associations",
16-
items: lost_association_items + new_association_items,
16+
items: lost_association_items + new_association_items + common_association_items,
1717
} %>
1818
<% else %>
1919
<h3 class="govuk-heading-m">Associations</h3>

app/components/admin/editions/document_type_change_summary.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ class Admin::Editions::DocumentTypeChangeSummary < ViewComponent::Base
22
attr_reader :lost_property_items,
33
:new_property_items,
44
:lost_association_items,
5-
:new_association_items
5+
:new_association_items,
6+
:common_association_items
67

78
def initialize(edition:, old_type:, new_type:)
89
@edition = edition
910
@old_type = old_type
1011
@new_type = new_type
12+
@association_to_label = {
13+
"ministerial_role_appointments" => "Ministers",
14+
}
1115

1216
compute_diffs
1317
end
@@ -19,6 +23,7 @@ def compute_diffs
1923
added_prop_keys = @new_type.properties.keys - @old_type.properties.keys # will need populating
2024
removed_assoc_keys = @old_type.associations.map { |a| a["key"] } - @new_type.associations.map { |a| a["key"] }
2125
added_assoc_keys = @new_type.associations.map { |a| a["key"] } - @old_type.associations.map { |a| a["key"] }
26+
common_assoc_keys = @new_type.associations.map { |a| a["key"] } & @old_type.associations.map { |a| a["key"] }
2227

2328
@lost_property_items = removed_prop_keys.map do |key|
2429
schema = @old_type.properties[key]
@@ -36,21 +41,18 @@ def compute_diffs
3641
}
3742
end
3843

39-
@lost_association_items = removed_assoc_keys.map do |key|
40-
field = key.humanize
41-
42-
{
43-
field:,
44-
value: "Will be deleted. A ‘#{@new_type.label}’ does not have a ‘#{field}’ association.",
45-
}
46-
end
44+
@lost_association_items = build_association_items(removed_assoc_keys, @new_type.label, proc { |label, field| "Will be deleted. A ‘#{label}’ does not have a ‘#{field}’ association." })
45+
@new_association_items = build_association_items(added_assoc_keys, @new_type.label, proc { |label, field| "Will need to be added. A ‘#{label}’ has a ‘#{field}’ association. This field will be blank after the change." })
46+
@common_association_items = build_association_items(common_assoc_keys, @new_type.label, proc { "These associations will be carried over, you will not have to fill them in again." })
47+
end
4748

48-
@new_association_items = added_assoc_keys.map do |key|
49-
field = key.humanize
49+
def build_association_items(items, label, value)
50+
items.map do |key|
51+
field = @association_to_label[key] || key.humanize
5052

5153
{
5254
field:,
53-
value: "Will need to be added. A ‘#{@new_type.label}’ has a ‘#{field}’ association. This field will be blank after the change.",
55+
value: value.call(label, field),
5456
}
5557
end
5658
end

test/components/admin/editions/document_type_change_summary_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def build_type(label:, properties: {}, associations: [])
1919
associations: [
2020
{ "key" => "organisations" },
2121
{ "key" => "world_locations" },
22+
{ "key" => "ministerial_role_appointments" },
2223
],
2324
)
2425

0 commit comments

Comments
 (0)