Skip to content

Commit 5e0bce0

Browse files
mickrmergify[bot]
andauthored
feat(i18n): add options field (#478)
* 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>
1 parent 75dcfbe commit 5e0bce0

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/BoxAnnotations.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import getProp from 'lodash/get';
22
import DocumentAnnotator from './document/DocumentAnnotator';
3-
import { Permissions, PERMISSIONS, Type } from './@types';
3+
import { IntlOptions, Permissions, PERMISSIONS, Type } from './@types';
44

55
type Annotator = {
66
CONSTRUCTOR: typeof DocumentAnnotator;
@@ -9,6 +9,10 @@ type Annotator = {
99
VIEWERS: string[];
1010
};
1111

12+
type AnnotationsOptions = {
13+
intl: IntlOptions;
14+
};
15+
1216
type PreviewOptions = {
1317
file?: {
1418
permissions?: Permissions;
@@ -37,26 +41,30 @@ type ViewerOptions = Record<string, ViewerOption>;
3741
*/
3842
const ANNOTATORS: Annotator[] = [
3943
{
40-
NAME: 'Document',
4144
CONSTRUCTOR: DocumentAnnotator,
42-
VIEWERS: ['Document', 'Presentation'],
45+
NAME: 'Document',
4346
TYPES: [Type.region],
47+
VIEWERS: ['Document', 'Presentation'],
4448
},
4549
];
4650

4751
class BoxAnnotations {
4852
annotators: Annotator[];
4953

54+
annotationsOptions?: AnnotationsOptions;
55+
5056
viewerOptions?: ViewerOptions | null;
5157

5258
/**
5359
* [constructor]
5460
*
5561
* @param {Object} viewerOptions - Viewer-specific annotator options
62+
* @param {AnnotationsOptions } options - options passed to the annotations instance
5663
* @return {BoxAnnotations} BoxAnnotations instance
5764
*/
58-
constructor(viewerOptions?: ViewerOptions) {
65+
constructor(viewerOptions?: ViewerOptions, options?: AnnotationsOptions) {
5966
this.annotators = ANNOTATORS;
67+
this.annotationsOptions = options;
6068
this.viewerOptions = viewerOptions;
6169
}
6270

@@ -115,6 +123,10 @@ class BoxAnnotations {
115123

116124
return { ...annotator, TYPES: enabledTypes };
117125
}
126+
127+
getOptions(): AnnotationsOptions | undefined {
128+
return this.annotationsOptions;
129+
}
118130
}
119131

120132
global.BoxAnnotations = BoxAnnotations;

src/__tests__/BoxAnnotations-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,17 @@ describe('BoxAnnotations', () => {
169169
expect(loader.determineAnnotator(options, config)).toBeNull();
170170
});
171171
});
172+
173+
describe('getOptions', () => {
174+
it.each([undefined, { intl: { messages: { test: 'Hello' } } }])(
175+
'should return the passed in options when they are %o',
176+
mockOptions => {
177+
loader = new BoxAnnotations(null, mockOptions);
178+
179+
const options = loader.getOptions();
180+
181+
expect(options).toEqual(mockOptions);
182+
},
183+
);
184+
});
172185
});

0 commit comments

Comments
 (0)