Skip to content

Commit

Permalink
feat(i18n): add options field (#478)
Browse files Browse the repository at this point in the history
* 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.

* feat(i18n): add options field

* Add language field in type

* feat(i18n): add options field

* PR Feedback

* feat(i18n): add options field

* Add intl wrapper object for options

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mickr and mergify[bot] authored May 11, 2020
1 parent 75dcfbe commit 5e0bce0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/BoxAnnotations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getProp from 'lodash/get';
import DocumentAnnotator from './document/DocumentAnnotator';
import { Permissions, PERMISSIONS, Type } from './@types';
import { IntlOptions, Permissions, PERMISSIONS, Type } from './@types';

type Annotator = {
CONSTRUCTOR: typeof DocumentAnnotator;
Expand All @@ -9,6 +9,10 @@ type Annotator = {
VIEWERS: string[];
};

type AnnotationsOptions = {
intl: IntlOptions;
};

type PreviewOptions = {
file?: {
permissions?: Permissions;
Expand Down Expand Up @@ -37,26 +41,30 @@ type ViewerOptions = Record<string, ViewerOption>;
*/
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;
}

Expand Down Expand Up @@ -115,6 +123,10 @@ class BoxAnnotations {

return { ...annotator, TYPES: enabledTypes };
}

getOptions(): AnnotationsOptions | undefined {
return this.annotationsOptions;
}
}

global.BoxAnnotations = BoxAnnotations;
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/BoxAnnotations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,17 @@ describe('BoxAnnotations', () => {
expect(loader.determineAnnotator(options, config)).toBeNull();
});
});

describe('getOptions', () => {
it.each([undefined, { intl: { messages: { test: 'Hello' } } }])(
'should return the passed in options when they are %o',
mockOptions => {
loader = new BoxAnnotations(null, mockOptions);

const options = loader.getOptions();

expect(options).toEqual(mockOptions);
},
);
});
});

0 comments on commit 5e0bce0

Please sign in to comment.