Skip to content
Snippets Groups Projects
Unverified Commit 9a00105c authored by Jack Reed's avatar Jack Reed Committed by GitHub
Browse files

Merge pull request #2364 from ProjectMirador/2329-handle-anno-resources-object

Handle annotation resources that are a single object…
parents af884050 6d362a39
Branches
Tags
No related merge requests found
......@@ -22,5 +22,11 @@ describe('Annotation', () => {
{ resources: [{ foo: 'bar' }] },
).resources.forEach(resource => expect(resource).toBeInstanceOf(AnnotationResource));
});
it('handles resources that are just a single object instead of an array of objects', () => {
new Annotation(
{ resources: { foo: 'bar' } },
).resources.forEach(resource => expect(resource).toBeInstanceOf(AnnotationResource));
});
});
});
import flatten from 'lodash/flatten';
import AnnotationResource from './AnnotationResource';
/** */
export default class Annotation {
......@@ -21,6 +22,7 @@ export default class Annotation {
/** */
get resources() {
if (!this.json || !this.json.resources) return [];
return this.json.resources.map(resource => new AnnotationResource(resource));
return flatten([this.json.resources]).map(resource => new AnnotationResource(resource));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment