diff --git a/__tests__/AnnotationCreation.test.js b/__tests__/AnnotationCreation.test.js index b3bfeb053dec48de7da38712f0bcc5bf5be2e867..5f79a8291da2447385a5c2ff82ac5120400d13bf 100644 --- a/__tests__/AnnotationCreation.test.js +++ b/__tests__/AnnotationCreation.test.js @@ -36,4 +36,16 @@ describe('AnnotationCreation', () => { wrapper = createWrapper(); expect(wrapper.dive().find(TextEditor).length).toBe(1); }); + it('can handle annotations without target selector', () => { + wrapper = createWrapper({ + annotation: { + body: { + purpose: 'commenting', + value: 'Foo bar', + }, + target: {}, + }, + }); + wrapper.dive(); + }); }); diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index c58f4452c61aa3ecdb7e05ae82b8a0d31dceedd2..54d09c628acf4da5703376bc93a83887a3584e21 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -50,16 +50,18 @@ class AnnotationCreation extends Component { } else { annoState.annoBody = props.annotation.body.value; } - if (Array.isArray(props.annotation.target.selector)) { - props.annotation.target.selector.forEach((selector) => { - if (selector.type === 'SvgSelector') { - annoState.svg = selector.value; - } else if (selector.type === 'FragmentSelector') { - annoState.xywh = selector.value.replace('xywh=', ''); - } - }); - } else { - annoState.svg = props.annotation.target.selector.value; + if (props.annotation.target.selector) { + if (Array.isArray(props.annotation.target.selector)) { + props.annotation.target.selector.forEach((selector) => { + if (selector.type === 'SvgSelector') { + annoState.svg = selector.value; + } else if (selector.type === 'FragmentSelector') { + annoState.xywh = selector.value.replace('xywh=', ''); + } + }); + } else { + annoState.svg = props.annotation.target.selector.value; + } } } this.state = {