Skip to content

Commit

Permalink
Merge pull request #8237 from alphagov/1641-lead-org-and-support-org-…
Browse files Browse the repository at this point in the history
…change-component-to-reduce-number-of-fields

Replace supporting organisation component
  • Loading branch information
dnkrj authored Sep 13, 2023
2 parents 0a1e7ba + 5bf8c1c commit c1095d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
40 changes: 14 additions & 26 deletions app/views/admin/editions/_organisation_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if edition.can_be_related_to_organisations? %>
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "Organisations",
legend_text: "Lead organisations",
heading_level: 3,
heading_size: "m",
id: "edition_organisations",
Expand Down Expand Up @@ -34,30 +34,18 @@
<% end %>
</div>

<% 0.upto(5) do |index| %>
<% supporting_organisation_id = supporting_organisation_id_at_index(edition, index) %>
<% cache_if supporting_organisation_id.nil?, "#{taggable_organisations_cache_digest}-lead" do %>
<%= render "components/select-with-search", {
id: "edition_supporting_organisation_ids_#{index + 1}",
name: "edition[supporting_organisation_ids][]",
label: "Supporting organisation #{index + 1}",
heading_size: "s",
include_blank: true,
options: taggable_organisations_container.map do |name, id|
{
text: name,
value: id,
selected: id == supporting_organisation_id,
data_attributes: {
module: 'track-select-click',
track_category: 'supportingOrgSelection',
track_action: name,
track_label: request.path
},
}
end
} %>
<% end %>
<% end %>
<%= render "components/autocomplete", {
id: "edition_supporting_organisation_ids",
name: "edition[supporting_organisation_ids][]",
label: {
text: "Supporting organisations",
heading_size: "m",
},
select: {
multiple: true,
selected: edition.edition_organisations.reject(&:lead?).map(&:organisation_id),
options: [""] + taggable_organisations_container,
},
} %>
<% end %>
<% end %>
27 changes: 2 additions & 25 deletions test/support/admin_edition_controller_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,7 @@ def should_allow_organisations_for(edition_type)
end
end
refute_select "#edition_lead_organisation_ids_5"
(1..6).each do |i|
assert_select "label[for=edition_supporting_organisation_ids_#{i}]", text: "Supporting organisation #{i}"

assert_select("#edition_supporting_organisation_ids_#{i}") do |elements|
assert_equal 1, elements.length
assert_data_attributes_for_supporting_org(element: elements.first, track_label: new_edition_path(edition_type))
end
end
refute_select "#edition_supporting_organisation_ids_7"
assert_select("#edition_supporting_organisation_ids_")
end
end

Expand Down Expand Up @@ -484,15 +476,7 @@ def should_allow_organisations_for(edition_type)
end
end
refute_select "#edition_lead_organisation_ids_5"
(1..6).each do |i|
assert_select "label[for=edition_supporting_organisation_ids_#{i}]", text: "Supporting organisation #{i}"

assert_select("#edition_supporting_organisation_ids_#{i}") do |elements|
assert_equal 1, elements.length
assert_data_attributes_for_supporting_org(element: elements.first, track_label: edit_edition_path(edition))
end
end
refute_select "#edition_supporting_organisation_ids_7"
assert_select("#edition_supporting_organisation_ids_")
end
end

Expand Down Expand Up @@ -1206,13 +1190,6 @@ def assert_data_attributes_for_lead_org(element:, track_label:)
# assert_equal track_label, element["data-track-label"]
end

def assert_data_attributes_for_supporting_org(element:, track_label:)
# TODO: Add tracking back in. This is covered in this Trello card https://trello.com/c/eKGeFCQu/975-add-tracking-in-for-associations-on-the-edit-page
# assert_equal "track-select-click", element["data-module"]
# assert_equal "supportingOrgSelection", element["data-track-category"]
# assert_equal track_label, element["data-track-label"]
end

def new_edition_path(edition_type)
edition = build(edition_type)
@controller.new_polymorphic_path([:admin, edition])
Expand Down

0 comments on commit c1095d2

Please sign in to comment.