Skip to content

Commit

Permalink
feat(annotations): scroll to annotation on load
Browse files Browse the repository at this point in the history
* PR Feedback
  • Loading branch information
mickr committed Jun 16, 2020
1 parent 6316c70 commit fdefff2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ class BaseViewer extends EventEmitter {
*/
initAnnotations() {
// Annotations must be loaded and ready before scrolling can occur on a deep-linked annotation.
this.annotator.addListener('annotations_initialized', this.handleAnnotationsOnLoad);
this.annotator.addListener('annotations_initialized', this.handleAnnotationsInitialized);

this.annotator.init(this.scale);

Expand Down Expand Up @@ -1046,17 +1046,12 @@ class BaseViewer extends EventEmitter {
* @param {Array} event.annotations - annotations array from emitted from box-annotations.
* @return {void}
*/
handleAnnotationsOnLoad = ({ annotations = [] }) => {
handleAnnotationsInitialized = ({ annotations = [] }) => {
const {
file: { id },
} = this.options;

const activeAnnotationId = getProp(this.options, `fileOptions.${id}.annotations.activeId`, null);

if (!activeAnnotationId) {
return;
}

const annotation = annotations.find(entry => entry.id === activeAnnotationId);

if (!annotation) {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.annotator.addListener).to.be.calledWith('annotations_create', base.handleAnnotationCreateEvent);
expect(base.annotator.addListener).to.be.calledWith(
'annotations_initialized',
base.handleAnnotationsOnLoad,
base.handleAnnotationsInitialized,
);
expect(base.emit).to.be.calledWith('annotator', base.annotator);
});
Expand Down Expand Up @@ -1300,7 +1300,7 @@ describe('lib/viewers/BaseViewer', () => {
});
});

describe('handleAnnotationsOnLoad()', () => {
describe('handleAnnotationsInitialized()', () => {
let scrollToAnnotationStub;

beforeEach(() => {
Expand All @@ -1319,7 +1319,7 @@ describe('lib/viewers/BaseViewer', () => {
},
};

base.handleAnnotationsOnLoad({ annotations: [{ id: '123' }] });
base.handleAnnotationsInitialized({ annotations: [{ id: '123' }] });

expect(scrollToAnnotationStub).not.to.be.called;
});
Expand All @@ -1332,7 +1332,7 @@ describe('lib/viewers/BaseViewer', () => {
},
};

base.handleAnnotationsOnLoad({ annotations: [{ id: 'ABC' }] });
base.handleAnnotationsInitialized({ annotations: [{ id: 'ABC' }] });

expect(scrollToAnnotationStub).to.be.calledWith('ABC');
});
Expand Down

0 comments on commit fdefff2

Please sign in to comment.