Skip to content

Commit

Permalink
chore(resin): Add annotations resin tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jun 29, 2020
1 parent e8b3cbb commit d27a6b9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/AnnotationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum AnnotationMode {
}
export type ClickHandler = ({ event }: { event: MouseEvent }) => void;
export type Options = {
fileId?: string;
onEscape?: () => void;
onRegionClick?: ClickHandler;
};
Expand Down Expand Up @@ -171,7 +172,7 @@ export default class AnnotationControls {
/**
* Initialize the annotation controls with options.
*/
public init({ onEscape = noop, onRegionClick = noop }: Options = {}): void {
public init({ onEscape = noop, onRegionClick = noop, fileId = '' }: Options = {}): void {
if (this.hasInit) {
return;
}
Expand All @@ -185,6 +186,9 @@ export default class AnnotationControls {
groupElement,
);

groupElement.setAttribute('data-resin-feature', 'annotations');
regionButton.setAttribute('data-resin-target', 'highlightRegion');
regionButton.setAttribute('data-resin-file_id', fileId);
regionButton.setAttribute('data-testid', 'bp-AnnotationsControls-regionBtn');

this.onEscape = onEscape;
Expand Down
1 change: 1 addition & 0 deletions src/lib/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Controls {
this.controlsEl = this.containerEl.appendChild(document.createElement('div'));
this.controlsEl.className = 'bp-controls';
this.controlsEl.setAttribute('data-testid', 'bp-controls');
this.controlsEl.setAttribute('data-resin-component', 'toolbar');

this.containerEl.addEventListener('mousemove', this.mousemoveHandler);
this.controlsEl.addEventListener('mouseenter', this.mouseenterHandler);
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ class DocBaseViewer extends BaseViewer {

if (this.areNewAnnotationsEnabled() && this.hasAnnotationCreatePermission()) {
this.annotationControls.init({
fileId: this.options.file.id,
onEscape: this.handleAnnotationControlsEscape,
onRegionClick: this.handleRegionClick,
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
ICON_FULLSCREEN_OUT,
);
expect(docBase.annotationControls.init).to.be.calledWith({
fileId: docBase.options.file.id,
onEscape: docBase.handleAnnotationControlsEscape,
onRegionClick: docBase.handleRegionClick,
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class ImageViewer extends ImageBaseViewer {
if (this.areNewAnnotationsEnabled() && this.hasAnnotationCreatePermission()) {
this.annotationControls = new AnnotationControls(this.controls);
this.annotationControls.init({
fileId: this.options.file.id,
onEscape: this.handleAnnotationControlsEscape,
onRegionClick: this.handleRegionClick,
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ describe('lib/viewers/image/ImageViewer', () => {
image.loadUI();

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

0 comments on commit d27a6b9

Please sign in to comment.