Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

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

Open
mathewjordan opened this issue Jan 6, 2022 · 1 comment

Comments

@mathewjordan
Copy link

mathewjordan commented Jan 6, 2022

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?

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

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!!

@stephenwf
Copy link
Member

Ah collection of collections! Yes that makes sense.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants