From f0b13e47df61206d06d7ae8497d2e990309c8f3d Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Thu, 30 Apr 2020 14:16:32 -0700 Subject: [PATCH] feat(annotations): Disable annotations for excel and iWork formats --- src/lib/extensions.js | 12 ++++++------ src/lib/viewers/BaseViewer.js | 5 +++++ src/lib/viewers/__tests__/BaseViewer-test.js | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/lib/extensions.js b/src/lib/extensions.js index 79004ed39d..c772785137 100644 --- a/src/lib/extensions.js +++ b/src/lib/extensions.js @@ -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', @@ -58,9 +64,6 @@ export const DOCUMENT_EXTENSIONS = CODE_EXTENSIONS.concat(NON_CODE_EXTENSIONS) 'gsheet', 'gslide', 'gslides', - 'pages', - 'numbers', - 'key', 'msg', 'odp', 'ods', @@ -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); diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 4f52680267..8bad39d79b 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -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'; @@ -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(); diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 87da25b6e6..f9547a00a5 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -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());