Skip to content

Commit

Permalink
Use edition links for worldwide organisation people
Browse files Browse the repository at this point in the history
We are switching worldwide organisations to use edition links which do
not support multi-level link expanstion.

Therefore we need to switch the rendering code to use the new link
fields that have been added, in the absence of multi-level links.
  • Loading branch information
brucebolt committed Jan 22, 2024
1 parent 046dccf commit e6a080a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def person_in_primary_role
return unless content_item["links"]["primary_role_person"]

person = content_item.dig("links", "primary_role_person").first
current_roles = person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") }
current_roles = roles_for_person(person["content_id"])

{
name: person["title"],
href: person["web_url"],
image_url: person["details"]["image"]["url"],
image_alt: person["details"]["image"]["alt_text"],
description: organisation_roles_for(current_roles),
description: presented_title_for_roles(current_roles),
}
end

Expand All @@ -66,12 +66,12 @@ def people_in_non_primary_roles
return [] unless people.any?

people.map do |person|
current_roles = person.dig("links", "role_appointments").select { |role_app| role_app.dig("details", "current") }
current_roles = roles_for_person(person["content_id"])

{
name: person["title"],
href: person["web_url"],
description: organisation_roles_for(current_roles),
description: presented_title_for_roles(current_roles),
}
end
end
Expand Down Expand Up @@ -128,16 +128,24 @@ def sponsoring_organisations

private

def organisation_roles_for(current_appointments)
current_appointments
.map { |role_appointment| role_appointment.dig("links", "role").first }
.select { |role| organisation_role_ids.include?(role["content_id"]) }
def presented_title_for_roles(roles)
roles
.map { |role| role["title"] }
.compact.join(", ")
end

def organisation_role_ids
content_item.dig("links", "roles")&.map { |role| role["content_id"] } || []
def roles_for_person(person_content_id)
content_item
.dig("details", "people_role_associations")
.select { |people_role_association| people_role_association["person_content_id"] == person_content_id }
.first["role_appointments"]
.pluck("role_content_id")
.map { |role_content_id|
content_item.dig("links", "roles").select do |role|
role["content_id"] == role_content_id
end
}
.flatten
end

def world_locations
Expand Down

0 comments on commit e6a080a

Please sign in to comment.