Skip to content

Commit

Permalink
Fix: Annotations cleanup (#449)
Browse files Browse the repository at this point in the history
* Fix: Localization of dialog delete button
* Ensure that toggling between plain and highlight comments properly removes temporary annotation comment and then shows the dialog on mobile devices
  • Loading branch information
pramodsum authored Oct 23, 2017
1 parent 15a7712 commit e8f6fd3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/annotations/AnnotationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class AnnotationDialog extends EventEmitter {
${this.localized.cancelButton}
</button>
<button class="bp-btn bp-btn-primary ${CLASS_BUTTON_DELETE_CONFIRM}" data-type="${constants.DATA_TYPE_CONFIRM_DELETE}">
${this.localized.delete}
${this.localized.deleteButton}
</button>
</div>
</div>`.trim();
Expand Down
1 change: 1 addition & 0 deletions src/lib/annotations/AnnotationThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class AnnotationThread extends EventEmitter {
this.dialog.removeAnnotation(tempAnnotation.annotationID);
}

this.showDialog();
this.emit(THREAD_EVENT.save);
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class Annotator extends EventEmitter {
* needs to bind event listeners to the DOM in the normal state (ie not
* in any annotation mode).
*
* @protected
* @return {void}
*/
bindDOMListeners() {}
Expand Down Expand Up @@ -719,7 +720,6 @@ class Annotator extends EventEmitter {
* @param {number} [rotationAngle] - current angle image is rotated
* @param {number} [pageNum] - Page number
* @return {void}
* @private
*/
rotateAnnotations(rotationAngle = 0, pageNum = 0) {
// Only render a specific page's annotations unless no page number
Expand Down Expand Up @@ -767,6 +767,7 @@ class Annotator extends EventEmitter {
/**
* Returns click handler for toggling annotation mode.
*
* @private
* @param {string} mode - Target annotation mode
* @return {Function|null} Click handler
*/
Expand All @@ -783,7 +784,7 @@ class Annotator extends EventEmitter {
/**
* Orient annotations to the correct scale and orientation of the annotated document.
*
* @protected
* @private
* @param {Object} data - Scale and orientation values needed to orient annotations.
* @return {void}
*/
Expand Down
1 change: 1 addition & 0 deletions src/lib/annotations/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ describe('lib/annotations/AnnotationThread', () => {
stubs.create = sandbox.stub(annotationService, 'create');
stubs.saveAnnotationToThread = sandbox.stub(thread, 'saveAnnotationToThread');
sandbox.stub(thread, 'getThreadEventData').returns({});
sandbox.stub(thread, 'showDialog');
});

it('should save annotation to thread if it does not exist in annotations array', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/annotations/doc/DocDrawingDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DocDrawingDialog extends AnnotationDialog {
if (this.pageEl && this.pageEl.contains(this.element)) {
this.pageEl.removeChild(this.element);
}

this.element = null;
}

/**
Expand Down Expand Up @@ -209,7 +211,7 @@ class DocDrawingDialog extends AnnotationDialog {
const commitButton = annotatorUtil.generateBtn(
constants.CLASS_ADD_DRAWING_BTN,
this.localized.drawSave,
`${ICON_DRAW_SAVE}${this.localized.saveButton}`.trim()
`${ICON_DRAW_SAVE} ${this.localized.saveButton}`
);
drawingButtonsEl.appendChild(commitButton);
}
Expand All @@ -218,7 +220,7 @@ class DocDrawingDialog extends AnnotationDialog {
const deleteButton = annotatorUtil.generateBtn(
constants.CLASS_DELETE_DRAWING_BTN,
this.localized.drawDelete,
`${ICON_DRAW_DELETE}${this.localized.deleteButton}`.trim()
`${ICON_DRAW_DELETE} ${this.localized.deleteButton}`
);
drawingButtonsEl.appendChild(deleteButton);
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib/annotations/doc/DocHighlightDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ class DocHighlightDialog extends AnnotationDialog {
super.addAnnotation(annotation);
}

/**
* Removes an annotation from the dialog.
*
* @param {string} annotationID - ID of annotation to remove
* @return {void}
*/
removeAnnotation(annotationID) {
const annotationEl = this.commentsDialogEl.querySelector(`[data-annotation-id="${annotationID}"]`);
if (annotationEl) {
annotationEl.parentNode.removeChild(annotationEl);
this.deactivateReply(); // Deactivate reply area and focus
}
}

/** @inheritdoc */
postAnnotation(textInput) {
const annotationTextEl = this.element.querySelector(constants.SELECTOR_ANNOTATION_TEXTAREA);
Expand Down
27 changes: 27 additions & 0 deletions src/lib/annotations/doc/__tests__/DocHighlightDialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ describe('lib/annotations/doc/DocHighlightDialog', () => {
});
});

describe('removeAnnotation()', () => {
it('should remove annotation element and deactivate reply', () => {
stubs.deactivate = sandbox.stub(dialog, 'deactivateReply');

dialog.addAnnotation(
new Annotation({
annotationID: 'someID',
text: 'blah',
user: {},
permissions: {}
})
);

dialog.removeAnnotation('someID');
const annotationEl = dialog.commentsDialogEl.querySelector('[data-annotation-id="someID"]');
expect(annotationEl).to.be.null;
expect(stubs.deactivate).to.be.called;
});

it('should not do anything if the specified annotation does not exist', () => {
stubs.deactivate = sandbox.stub(dialog, 'deactivateReply');

dialog.removeAnnotation('someID');
expect(stubs.deactivate).to.not.be.called;
});
});

describe('postAnnotation()', () => {
beforeEach(() => {
stubs.postFunc = AnnotationDialog.prototype.postAnnotation;
Expand Down

0 comments on commit e8f6fd3

Please sign in to comment.