Skip to content

Commit

Permalink
fix(annotations): Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jun 22, 2020
1 parent abac192 commit 01e939b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 deletions.
16 changes: 6 additions & 10 deletions src/lib/AnnotationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export enum AnnotationMode {
NONE = 'none',
REGION = 'region',
}
export type ClickHandler = ({ activeControl, event }: { activeControl: AnnotationMode; event: MouseEvent }) => void;
export type ClickHandler = ({ event }: { event: MouseEvent }) => void;
export type Options = {
onRegionClick?: ClickHandler;
onEscape?: () => void;
onRegionClick?: ClickHandler;
};

declare const __: (key: string) => string;
Expand Down Expand Up @@ -105,10 +105,6 @@ export default class AnnotationControls {
*/
private handleFullscreenExit = (): void => this.handleFullscreenChange(false);

public getActiveMode = (): AnnotationMode => {
return this.currentMode;
};

/**
* Deactivate current control button
*/
Expand Down Expand Up @@ -144,16 +140,16 @@ export default class AnnotationControls {
* Region comment button click handler
*/
private handleClick = (onClick: ClickHandler, mode: AnnotationMode) => (event: MouseEvent): void => {
const prevActiveControl = this.currentMode;
const prevMode = this.currentMode;

this.resetControls();

if (prevActiveControl !== mode) {
if (prevMode !== mode) {
this.currentMode = mode as AnnotationMode;
this.controlsMap[mode]();
}

onClick({ activeControl: this.currentMode, event });
onClick({ event });
};

/**
Expand All @@ -175,7 +171,7 @@ export default class AnnotationControls {
/**
* Initialize the annotation controls with options.
*/
public init({ onRegionClick = noop, onEscape = noop }: Options = {}): void {
public init({ onEscape = noop, onRegionClick = noop }: Options = {}): void {
if (this.hasInit) {
return;
}
Expand Down
8 changes: 0 additions & 8 deletions src/lib/__tests__/AnnotationControls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe('lib/AnnotationControls', () => {
annotationControls.handleClick(stubs.onRegionClick, AnnotationMode.REGION)(stubs.event);

expect(stubs.onRegionClick).to.be.calledWith({
activeControl: AnnotationMode.REGION,
event: stubs.event,
});
});
Expand Down Expand Up @@ -235,11 +234,4 @@ describe('lib/AnnotationControls', () => {
expect(stubs.updateRegionButton).to.be.called;
});
});

describe('getActiveMode()', () => {
it('should return the current active mode', () => {
annotationControls.currentMode = 'region';
expect(annotationControls.getActiveMode()).to.equal('region');
});
});
});
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,8 @@ class DocBaseViewer extends BaseViewer {

if (this.areNewAnnotationsEnabled() && this.hasAnnotationCreatePermission()) {
this.annotationControls.init({
onRegionClick: this.handleRegionClick,
onEscape: this.handleAnnotationControlsEscape,
onRegionClick: this.handleRegionClick,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2303,8 +2303,8 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
ICON_FULLSCREEN_OUT,
);
expect(docBase.annotationControls.init).to.be.calledWith({
onRegionClick: docBase.handleRegionClick,
onEscape: docBase.handleAnnotationControlsEscape,
onRegionClick: docBase.handleRegionClick,
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ class ImageViewer extends ImageBaseViewer {
if (this.areNewAnnotationsEnabled() && this.hasAnnotationCreatePermission()) {
this.annotationControls = new AnnotationControls(this.controls);
this.annotationControls.init({
onRegionClick: this.handleRegionClick,
onEscape: this.handleAnnotationControlsEscape,
onRegionClick: this.handleRegionClick,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ describe('lib/viewers/image/ImageViewer', () => {
image.loadUI();

expect(AnnotationControls.prototype.init).to.be.calledWith({
onRegionClick: image.handleRegionClick,
onEscape: image.handleAnnotationControlsEscape,
onRegionClick: image.handleRegionClick,
});
});
});
Expand Down

0 comments on commit 01e939b

Please sign in to comment.