Skip to content

Commit

Permalink
Use edition links for worldwide organisation offices
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.

This change adds support for edition links, but also retains
compatibility with non-edition links. This will allow us to deploy the
frontend changes in advance of republishing the content items,
preventing any downtime of these pages. The code for backward
compatibility will be removed once the content items have all been
republished with edition links.
  • Loading branch information
brucebolt committed Jan 22, 2024
1 parent c3b86d9 commit ef6aa6a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ def people_in_non_primary_roles

def main_office
return unless (office_item = content_item.dig("links", "main_office")&.first)
return unless (office_contact_item = office_item.dig("links", "contact")&.first)

office_contact_item = if office_item.dig("links", "contact")
office_item.dig("links", "contact")&.first # To be removed once switched to edition links
else
contact_for_office(office_item["content_id"])
end
return unless office_contact_item

WorldwideOffice.new(
contact: WorldwideOrganisation::LinkedContactPresenter.new(office_contact_item),
Expand All @@ -101,7 +107,12 @@ def home_page_offices
return [] unless content_item.dig("links", "home_page_offices")

content_item.dig("links", "home_page_offices").map { |office|
next unless (contact = office.dig("links", "contact")&.first)
contact = if office.dig("links", "contact")
office.dig("links", "contact")&.first # To be removed once switched to edition links
else
contact_for_office(office["content_id"])
end
next unless contact

WorldwideOrganisation::LinkedContactPresenter.new(contact)
}.compact
Expand Down Expand Up @@ -136,6 +147,18 @@ def sponsoring_organisations

private

def contact_for_office(office_content_id)
contact_mapping = content_item.dig("details", "office_contact_associations").select { |office_contact_association|
office_contact_association["office_content_id"] == office_content_id
}.first

return unless contact_mapping

content_item.dig("links", "contacts").select { |contact|
contact["content_id"] == contact_mapping["contact_content_id"]
}.first
end

def presented_title_for_roles(roles)
roles
.map { |role| role["title"] }
Expand Down

0 comments on commit ef6aa6a

Please sign in to comment.