Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialist document presenter refactor #3571

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/presenters/specialist_document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def facets
finder.dig("details", "facets")
end

def facet_values
def content_item_metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much better name 👍

# Metadata is a required field
content_item["details"]["metadata"]
end
Expand All @@ -122,7 +122,7 @@ def facets_with_friendly_values
facets_with_values.map do |facet|
facet_key = facet["key"]
# Cast all values into an array
values = [facet_values[facet_key]].flatten
values = [content_item_metadata[facet_key]].flatten

facet["values"] = case facet["type"]
when "date"
Expand All @@ -138,10 +138,10 @@ def facets_with_friendly_values
end

def facets_with_values
return [] unless facets && facet_values.any?
return [] unless facets && content_item_metadata.any?

facets
.select { |f| facet_values[f["key"]] && facet_values[f["key"]].present? }
.select { |f| content_item_metadata[f["key"]] && content_item_metadata[f["key"]].present? }
.reject { |f| f["key"] == first_published_at_facet_key }
.reject { |f| f["key"] == internal_notes_facet_key }
end
Expand Down Expand Up @@ -208,8 +208,8 @@ def internal_notes_facet_key
#
# Instead use first date in change history
def first_public_at
@first_public_at ||= if facet_values[first_published_at_facet_key]
facet_values[first_published_at_facet_key]
@first_public_at ||= if content_item_metadata[first_published_at_facet_key]
content_item_metadata[first_published_at_facet_key]
else
changes = reverse_chronological_change_history
changes.any? ? changes.last[:timestamp] : nil
Expand All @@ -236,7 +236,7 @@ def any_updates?
# Example:
# https://www.gov.uk/aaib-reports/lockheed-l1011-385-1-15-g-bhbr-19-december-1989
def bulk_published?
facet_values["bulk_published"].present?
content_item_metadata["bulk_published"].present?
end

def statutory_instrument?
Expand Down