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 976fa7b commit f0b13e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ export const CODE_EXTENSIONS = [
'yaml',
];

export const EXCEL_EXTENSIONS = ['xls', 'xlsm', 'xlsx'];

export const IWORK_EXTENSIONS = ['pages', 'numbers', 'key'];

export const DOCUMENT_EXTENSIONS = CODE_EXTENSIONS.concat(NON_CODE_EXTENSIONS)
.concat(HTML_EXTENSIONS)
.concat(EXCEL_EXTENSIONS)
.concat(IWORK_EXTENSIONS)
.concat([
'doc',
'docx',
Expand All @@ -58,9 +64,6 @@ export const DOCUMENT_EXTENSIONS = CODE_EXTENSIONS.concat(NON_CODE_EXTENSIONS)
'gsheet',
'gslide',
'gslides',
'pages',
'numbers',
'key',
'msg',
'odp',
'ods',
Expand All @@ -70,9 +73,6 @@ export const DOCUMENT_EXTENSIONS = CODE_EXTENSIONS.concat(NON_CODE_EXTENSIONS)
'pptx',
'rtf',
'wpd',
'xls',
'xlsm',
'xlsx',
]);

export const TXT_EXTENSIONS = CODE_EXTENSIONS.concat(NON_CODE_EXTENSIONS);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../constants';
import { getIconFromExtension, getIconFromName } from '../icons/icons';
import { VIEWER_EVENT, ERROR_CODE, LOAD_METRIC, DOWNLOAD_REACHABILITY_METRICS } from '../events';
import { EXCEL_EXTENSIONS, IWORK_EXTENSIONS } from '../extensions';
import { AnnotationMode } from '../AnnotationControls';
import PreviewError from '../PreviewError';
import Timer from '../Timer';
Expand Down Expand Up @@ -173,6 +174,10 @@ 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
16 changes: 16 additions & 0 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ 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

0 comments on commit f0b13e4

Please sign in to comment.