Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Do not display disabled annotation types on fetch #301

Merged
merged 3 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,13 @@ class Annotator extends EventEmitter {
Object.keys(threadMap).forEach((threadID) => {
const annotations = threadMap[threadID];
const firstAnnotation = annotations[0];
if (!firstAnnotation || !this.isModeAnnotatable(firstAnnotation.type)) {
return;
}

// Bind events on valid annotation thread
const thread = this.createAnnotationThread(annotations, firstAnnotation.location, firstAnnotation.type);
if (thread) {
this.bindCustomListenersOnThread(thread);
}
this.bindCustomListenersOnThread(thread);
});

this.emit('annotationsfetched');
Expand Down Expand Up @@ -603,6 +604,10 @@ class Annotator extends EventEmitter {
* @return {void}
*/
bindCustomListenersOnThread(thread) {
if (!thread) {
return;
}

// Thread was deleted, remove from thread map
thread.addListener('threaddeleted', () => {
const page = thread.location.page || 1;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/annotations/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ describe('lib/annotations/Annotator', () => {
stubs.threadPromise = Promise.resolve(threadMap);
stubs.serviceMock.expects('getThreadMap').returns(stubs.threadPromise);
sandbox.stub(annotator, 'emit');
sandbox.stub(annotator, 'isModeAnnotatable').returns(true);
});

it('should reset and create a new thread map by fetching annotation data from the server', () => {
Expand All @@ -357,7 +358,7 @@ describe('lib/annotations/Annotator', () => {
return stubs.threadPromise.then(() => {
expect(Object.keys(annotator.threads).length === 0).to.be.true;
expect(annotator.createAnnotationThread).to.be.calledTwice;
expect(annotator.bindCustomListenersOnThread).to.be.calledOnce;
expect(annotator.bindCustomListenersOnThread).to.be.calledTwice;
expect(result).to.be.an.object;
});
});
Expand Down Expand Up @@ -459,6 +460,11 @@ describe('lib/annotations/Annotator', () => {
stubs.threadMock.expects('addListener').withArgs('threadcleanup', sinon.match.func);
annotator.bindCustomListenersOnThread(stubs.thread);
});

it('should do nothing when given thread is empty', () => {
expect(annotator.bindCustomListenersOnThread).to.not.throw(undefined);
expect(annotator.bindCustomListenersOnThread).to.not.throw(null);
})
});

describe('unbindCustomListenersOnThread()', () => {
Expand Down