Skip to content

Commit

Permalink
Allow breadcrumbs to fallback and function with :parent_ssim
Browse files Browse the repository at this point in the history
  • Loading branch information
corylown committed Mar 19, 2024
1 parent 54bfcb3 commit e12d64b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/models/arclight/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Arclight
class Parent
attr_reader :id, :label, :eadid, :level

alias global_id id
Arclight.deprecation.deprecate_methods(self, global_id: 'Call `id` instead')

def initialize(id:, label:, eadid:, level:)
@id = id
@label = label
Expand Down
10 changes: 6 additions & 4 deletions app/models/arclight/parents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ module Arclight
# Object for parsing and formalizing Solr_Ead "Parents"
# https://github.com/awead/solr_ead/blob/8cf7ffaa66e0e4c9c0b12f5646d6c2e20984cd99/lib/solr_ead/behaviors.rb#L54-L57
class Parents
attr_reader :ids, :labels, :levels
attr_reader :ids, :legacy_ids, :labels, :levels

def initialize(ids:, labels:, eadid:, levels:)
def initialize(ids:, legacy_ids:, labels:, eadid:, levels:)
@ids = ids
@legacy_ids = legacy_ids
@labels = labels
@eadid = eadid
@levels = levels
Expand All @@ -21,17 +22,18 @@ def eadid
##
# @return [Array[Arclight::Parent]]
def as_parents
ids.map.with_index { |id, idx| Arclight::Parent.new(id: id, label: labels[idx], eadid: eadid, level: levels[idx]) }
(ids.presence || legacy_ids).map.with_index { |id, idx| Arclight::Parent.new(id: id, label: labels[idx], eadid: eadid, level: levels[idx]) }
end

##
# @param [SolrDocument] document
def self.from_solr_document(document)
ids = document.parent_ids
legacy_ids = document.legacy_parent_ids.map { |legacy_id| document.eadid == legacy_id ? legacy_id : "#{document.eadid}#{legacy_id}" }
labels = document.parent_labels
eadid = document.eadid
levels = document.parent_levels
new(ids: ids, labels: labels, eadid: eadid, levels: levels)
new(ids: ids, legacy_ids: legacy_ids, labels: labels, eadid: eadid, levels: levels)
end
end
end
2 changes: 2 additions & 0 deletions app/models/concerns/arclight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module SolrDocument

included do
attribute :parent_ids, :array, 'parent_ids_ssim'
attribute :legacy_parent_ids, :array, 'parent_ssim'
Arclight.deprecation.deprecate_methods(self, legacy_parent_ids: 'Use `parent_ids` instead')
attribute :parent_labels, :array, 'parent_unittitles_ssm'
attribute :parent_levels, :array, 'parent_levels_ssm'
attribute :unitid, :string, 'unitid_ssm'
Expand Down
2 changes: 1 addition & 1 deletion spec/models/arclight/parents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

context 'with no data' do
it 'returns an empty array' do
expect(described_class.new(ids: [], labels: [], eadid: '', levels: '').as_parents).to eq []
expect(described_class.new(ids: [], legacy_ids: [], labels: [], eadid: '', levels: '').as_parents).to eq []
end
end
end
Expand Down

0 comments on commit e12d64b

Please sign in to comment.