From 6db58684a327c6be4ad4e620e25651b3e4e8956f Mon Sep 17 00:00:00 2001 From: Mick Ryan Date: Wed, 6 May 2020 18:20:02 -0700 Subject: [PATCH 1/4] feat(i18n): add options field * Add options field that can be passed into the instance. These options then will be passed to the annotator in Preview SDK. --- src/BoxAnnotations.ts | 19 ++++++++++++++++--- src/__tests__/BoxAnnotations-test.js | 13 +++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/BoxAnnotations.ts b/src/BoxAnnotations.ts index 046888fa8..64dc28b1e 100644 --- a/src/BoxAnnotations.ts +++ b/src/BoxAnnotations.ts @@ -2,6 +2,11 @@ import getProp from 'lodash/get'; import DocumentAnnotator from './document/DocumentAnnotator'; import { Permissions, PERMISSIONS, Type } from './@types'; +type AnnotationsOptions = { + messages?: Record; + locale?: string; +}; + type Annotator = { CONSTRUCTOR: typeof DocumentAnnotator; NAME: string; @@ -37,26 +42,30 @@ type ViewerOptions = Record; */ const ANNOTATORS: Annotator[] = [ { - NAME: 'Document', CONSTRUCTOR: DocumentAnnotator, - VIEWERS: ['Document', 'Presentation'], + NAME: 'Document', TYPES: [Type.region], + VIEWERS: ['Document', 'Presentation'], }, ]; class BoxAnnotations { annotators: Annotator[]; + annotationsOptions?: AnnotationsOptions; + viewerOptions?: ViewerOptions | null; /** * [constructor] * * @param {Object} viewerOptions - Viewer-specific annotator options + * @param {AnnotationsOptions } options - options passed to the annotations instance * @return {BoxAnnotations} BoxAnnotations instance */ - constructor(viewerOptions?: ViewerOptions) { + constructor(viewerOptions?: ViewerOptions, options?: AnnotationsOptions) { this.annotators = ANNOTATORS; + this.annotationsOptions = options; this.viewerOptions = viewerOptions; } @@ -113,6 +122,10 @@ class BoxAnnotations { return { ...annotator, TYPES: enabledTypes }; } + + getAnnotationsOptions(): AnnotationsOptions | undefined { + return this.annotationsOptions; + } } global.BoxAnnotations = BoxAnnotations; diff --git a/src/__tests__/BoxAnnotations-test.js b/src/__tests__/BoxAnnotations-test.js index ce0b88cce..a36bb725a 100644 --- a/src/__tests__/BoxAnnotations-test.js +++ b/src/__tests__/BoxAnnotations-test.js @@ -157,4 +157,17 @@ describe('BoxAnnotations', () => { expect(loader.determineAnnotator(options, config)).toBeNull(); }); }); + + describe('getAnnotationsOptions', () => { + it.each([undefined, { messages: { test: 'Hello' } }])( + 'should return the passed in options when they are %o', + mockOptions => { + loader = new BoxAnnotations(null, mockOptions); + + const options = loader.getAnnotationsOptions(); + + expect(options).toEqual(mockOptions); + }, + ); + }); }); From 605a10779c23fb8e094ca5046cc6c85b76c0bf45 Mon Sep 17 00:00:00 2001 From: Mick Ryan Date: Fri, 8 May 2020 15:55:42 -0700 Subject: [PATCH 2/4] feat(i18n): add options field * Add language field in type --- src/BoxAnnotations.ts | 5 +++-- src/__tests__/BoxAnnotations-test.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/BoxAnnotations.ts b/src/BoxAnnotations.ts index 64dc28b1e..c68833972 100644 --- a/src/BoxAnnotations.ts +++ b/src/BoxAnnotations.ts @@ -3,8 +3,9 @@ import DocumentAnnotator from './document/DocumentAnnotator'; import { Permissions, PERMISSIONS, Type } from './@types'; type AnnotationsOptions = { - messages?: Record; + language?: string; locale?: string; + messages?: Record; }; type Annotator = { @@ -123,7 +124,7 @@ class BoxAnnotations { return { ...annotator, TYPES: enabledTypes }; } - getAnnotationsOptions(): AnnotationsOptions | undefined { + getOptions(): AnnotationsOptions | undefined { return this.annotationsOptions; } } diff --git a/src/__tests__/BoxAnnotations-test.js b/src/__tests__/BoxAnnotations-test.js index a36bb725a..1be30c374 100644 --- a/src/__tests__/BoxAnnotations-test.js +++ b/src/__tests__/BoxAnnotations-test.js @@ -158,13 +158,13 @@ describe('BoxAnnotations', () => { }); }); - describe('getAnnotationsOptions', () => { + describe('getOptions', () => { it.each([undefined, { messages: { test: 'Hello' } }])( 'should return the passed in options when they are %o', mockOptions => { loader = new BoxAnnotations(null, mockOptions); - const options = loader.getAnnotationsOptions(); + const options = loader.getOptions(); expect(options).toEqual(mockOptions); }, From d2c20c97014fef8a7d79fb2ef548cc95c7aa956b Mon Sep 17 00:00:00 2001 From: Mick Ryan Date: Fri, 8 May 2020 17:22:59 -0700 Subject: [PATCH 3/4] feat(i18n): add options field * PR Feedback --- src/BoxAnnotations.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/BoxAnnotations.ts b/src/BoxAnnotations.ts index c68833972..bdae895cc 100644 --- a/src/BoxAnnotations.ts +++ b/src/BoxAnnotations.ts @@ -1,12 +1,6 @@ import getProp from 'lodash/get'; import DocumentAnnotator from './document/DocumentAnnotator'; -import { Permissions, PERMISSIONS, Type } from './@types'; - -type AnnotationsOptions = { - language?: string; - locale?: string; - messages?: Record; -}; +import { IntlOptions, Permissions, PERMISSIONS, Type } from './@types'; type Annotator = { CONSTRUCTOR: typeof DocumentAnnotator; @@ -53,7 +47,7 @@ const ANNOTATORS: Annotator[] = [ class BoxAnnotations { annotators: Annotator[]; - annotationsOptions?: AnnotationsOptions; + annotationsOptions?: IntlOptions; viewerOptions?: ViewerOptions | null; @@ -64,7 +58,7 @@ class BoxAnnotations { * @param {AnnotationsOptions } options - options passed to the annotations instance * @return {BoxAnnotations} BoxAnnotations instance */ - constructor(viewerOptions?: ViewerOptions, options?: AnnotationsOptions) { + constructor(viewerOptions?: ViewerOptions, options?: IntlOptions) { this.annotators = ANNOTATORS; this.annotationsOptions = options; this.viewerOptions = viewerOptions; @@ -124,7 +118,7 @@ class BoxAnnotations { return { ...annotator, TYPES: enabledTypes }; } - getOptions(): AnnotationsOptions | undefined { + getOptions(): IntlOptions | undefined { return this.annotationsOptions; } } From 90ce21aabac445eb03ec72467838aca89e2417c0 Mon Sep 17 00:00:00 2001 From: Mick Ryan Date: Mon, 11 May 2020 13:56:32 -0700 Subject: [PATCH 4/4] feat(i18n): add options field * Add intl wrapper object for options --- src/BoxAnnotations.ts | 10 +++++++--- src/__tests__/BoxAnnotations-test.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/BoxAnnotations.ts b/src/BoxAnnotations.ts index bdae895cc..77e8152ac 100644 --- a/src/BoxAnnotations.ts +++ b/src/BoxAnnotations.ts @@ -9,6 +9,10 @@ type Annotator = { VIEWERS: string[]; }; +type AnnotationsOptions = { + intl: IntlOptions; +}; + type PreviewOptions = { file?: { permissions?: Permissions; @@ -47,7 +51,7 @@ const ANNOTATORS: Annotator[] = [ class BoxAnnotations { annotators: Annotator[]; - annotationsOptions?: IntlOptions; + annotationsOptions?: AnnotationsOptions; viewerOptions?: ViewerOptions | null; @@ -58,7 +62,7 @@ class BoxAnnotations { * @param {AnnotationsOptions } options - options passed to the annotations instance * @return {BoxAnnotations} BoxAnnotations instance */ - constructor(viewerOptions?: ViewerOptions, options?: IntlOptions) { + constructor(viewerOptions?: ViewerOptions, options?: AnnotationsOptions) { this.annotators = ANNOTATORS; this.annotationsOptions = options; this.viewerOptions = viewerOptions; @@ -118,7 +122,7 @@ class BoxAnnotations { return { ...annotator, TYPES: enabledTypes }; } - getOptions(): IntlOptions | undefined { + getOptions(): AnnotationsOptions | undefined { return this.annotationsOptions; } } diff --git a/src/__tests__/BoxAnnotations-test.js b/src/__tests__/BoxAnnotations-test.js index 1be30c374..928ca8b5f 100644 --- a/src/__tests__/BoxAnnotations-test.js +++ b/src/__tests__/BoxAnnotations-test.js @@ -159,7 +159,7 @@ describe('BoxAnnotations', () => { }); describe('getOptions', () => { - it.each([undefined, { messages: { test: 'Hello' } }])( + it.each([undefined, { intl: { messages: { test: 'Hello' } } }])( 'should return the passed in options when they are %o', mockOptions => { loader = new BoxAnnotations(null, mockOptions);