Skip to content

Commit

Permalink
feat(annotations): Disable annotations for excel and iWork formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Apr 30, 2020
1 parent f0b13e4 commit 37d160b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
11 changes: 6 additions & 5 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ class BaseViewer extends EventEmitter {
const fileExt = this.options.file.extension;
this.fileLoadingIcon = getIconFromExtension(fileExt);
this.startAt = getProp(this.options, `fileOptions.${this.options.file.id}.${FILE_OPTION_START}`, {});

if (EXCEL_EXTENSIONS.includes(fileExt) || IWORK_EXTENSIONS.includes(fileExt)) {
this.options.showAnnotationsControls = false;
}
}

this.finishLoadingSetup();
Expand Down Expand Up @@ -1011,7 +1007,7 @@ class BaseViewer extends EventEmitter {
*/
areAnnotationsEnabled() {
// Do not attempt to fetch annotations if the user cannot create or view annotations
const { permissions } = this.options.file;
const { extension, permissions } = this.options.file;
if (!this.hasAnnotationPermissions(permissions)) {
return false;
}
Expand All @@ -1035,6 +1031,11 @@ class BaseViewer extends EventEmitter {
return this.viewerConfig.enabled;
}

// Disable new annotations for Excel and iWork formats
if (EXCEL_EXTENSIONS.includes(extension) || IWORK_EXTENSIONS.includes(extension)) {
this.options.showAnnotationsControls = false;
}

// Ignore viewer config if BoxAnnotations was pass into Preview as an option
// Otherwise, use global preview annotation option
return !!this.options.showAnnotations;
Expand Down
30 changes: 14 additions & 16 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,6 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.annotatorPromiseResolver).to.not.be.undefined;
});

it('should not show annotations in toolbar if the file is excel or iWork formats', () => {
base.addCommonListeners = () => {};
base.finishLoadingSetup = () => {};

base.options.file.extension = 'xlsx';
base.options.showAnnotationsControls = true;
base.setup();
expect(base.options.showAnnotationsControls).to.equal(false);

base.isSetup = false;
base.options.file.extension = 'numbers';
base.options.showAnnotationsControls = true;
base.setup();
expect(base.options.showAnnotationsControls).to.equal(false);
});

it('should add a mobile class to the container if on mobile', () => {
base.isMobile = true;
sandbox.stub(base, 'loadBoxAnnotations').returns(Promise.resolve());
Expand Down Expand Up @@ -1231,6 +1215,20 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.areAnnotationsEnabled()).to.be.false;
});

it('should not show annotations in toolbar if the file is excel or iWork formats', () => {
stubs.getViewerOption.withArgs('annotations').returns(null);

base.options.file.extension = 'xlsx';
base.options.showAnnotationsControls = true;
base.areAnnotationsEnabled();
expect(base.options.showAnnotationsControls).to.equal(false);

base.options.file.extension = 'numbers';
base.options.showAnnotationsControls = true;
base.areAnnotationsEnabled();
expect(base.options.showAnnotationsControls).to.equal(false);
});

it('should use BoxAnnotations options if an instance of BoxAnnotations is passed into Preview', () => {
stubs.getViewerOption.withArgs('annotations').returns(null);
base.options.showAnnotations = false;
Expand Down

0 comments on commit 37d160b

Please sign in to comment.