hyperion icon indicating copy to clipboard operation
hyperion copied to clipboard

traverseCollectionItems() assumes nested collections have an items property (Presentation 3.0)

Open mathewjordan opened this issue 3 years ago • 1 comments
trafficstars

If a presentation 3.0 Collection is loaded with vault, and that collection has an items array containing an item of type Collection, the error TypeError: can't access property "map", collection.items is undefined is shown as it assumes the nested collection in the items array to have its own items property. This doesn't seem to be an issue with presentation 2.0 collections as those are normalized and have an empty array.

const vault = new Vault();

vault
  .loadCollection("https://iiif.wellcomecollection.org/presentation/collections/archives")
  .then((collection) => {
    // collection...
  });

Would adding if checking for the collection.items prop catch this?

https://github.com/digirati-labs/hyperion/blob/557d7b4f8756f13e0693c62edc9d1a668229cce1/packages/parser/src/traverse.ts#L160-L169

traverseCollectionItems(collection: Collection): Collection {
   if (collection.items) {
     collection.items.map((collectionOrManifest: Manifest | Collection) => { 
       if (collectionOrManifest.type === 'Collection') { 
         return this.traverseCollection(collectionOrManifest as Collection); 
       } 
       return this.traverseManifest(collectionOrManifest as Manifest); 
     }); 
   }
   
   return collection; 
} 

Thanks!!

mathewjordan avatar Jan 06 '22 18:01 mathewjordan

Ah collection of collections! Yes that makes sense.

stephenwf avatar Jan 06 '22 18:01 stephenwf