Skip to content

Commit

Permalink
feat(i18n): add options field
Browse files Browse the repository at this point in the history
* Add options field that can be passed into the instance. These options then will be passed to the annotator in Preview SDK.
  • Loading branch information
mickr committed May 8, 2020
1 parent 471ab57 commit b45425b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/BoxAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import getProp from 'lodash/get';
import DocumentAnnotator from './document/DocumentAnnotator';
import { Permissions, PERMISSIONS, Type } from './@types';

type AnnotationsOptions = {
messages?: Record<string, string>;
locale?: string;
};

type Annotator = {
CONSTRUCTOR: typeof DocumentAnnotator;
NAME: string;
Expand Down Expand Up @@ -37,26 +42,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 @@ -113,6 +122,10 @@ class BoxAnnotations {

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

getAnnotationsOptions(): 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 @@ -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);
},
);
});
});

0 comments on commit b45425b

Please sign in to comment.