Skip to content

Commit 361d73f

Browse files
Conrad Chanmergify[bot]
authored andcommitted
fix: Adding Accept-Language header for Xhr.js (#1368)
* fix: Adding Accept-Language header for Xhr.js * chore: fix unit tests and pr feedback * chore: add unit tests for Xhr.js
1 parent b34541f commit 361d73f

File tree

12 files changed

+89
-75
lines changed

12 files changed

+89
-75
lines changed

flow-typed/box-ui-elements.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ type Options = {
538538
consoleError?: boolean,
539539
consoleLog?: boolean,
540540
id?: string,
541+
language?: string,
541542
requestInterceptor?: Function,
542543
responseInterceptor?: Function,
543544
retryableStatusCodes?: Array<number>,

src/api/APIFactory.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class APIFactory {
162162
apiHost: options.apiHost || DEFAULT_HOSTNAME_API,
163163
uploadHost: options.uploadHost || DEFAULT_HOSTNAME_UPLOAD,
164164
cache: options.cache || new Cache(),
165+
language: options.language,
165166
});
166167
}
167168

src/api/OpenWith.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
*/
66

77
import Base from './Base';
8-
import {
9-
HEADER_ACCEPT_LANGUAGE,
10-
DEFAULT_LOCALE,
11-
ERROR_CODE_FETCH_INTEGRATIONS,
12-
BOX_EDIT_INTEGRATION_ID,
13-
BOX_EDIT_SFC_INTEGRATION_ID,
14-
} from '../constants';
8+
import { ERROR_CODE_FETCH_INTEGRATIONS, BOX_EDIT_INTEGRATION_ID, BOX_EDIT_SFC_INTEGRATION_ID } from '../constants';
159

1610
class OpenWith extends Base {
1711
/**
@@ -34,25 +28,13 @@ class OpenWith extends Base {
3428
* @param {string} fileId - Box file ID
3529
* @param {Function} successCallback - Success callback
3630
* @param {Function} errorCallback - Error callback
37-
* @param {string} locale - locale to receive translated strings from the API
3831
* @return {void}
3932
*/
40-
getOpenWithIntegrations(
41-
fileId: string,
42-
successCallback: Function,
43-
errorCallback: ElementsErrorCallback,
44-
locale: ?string = DEFAULT_LOCALE,
45-
) {
33+
getOpenWithIntegrations(fileId: string, successCallback: Function, errorCallback: ElementsErrorCallback) {
4634
this.errorCode = ERROR_CODE_FETCH_INTEGRATIONS;
47-
const params = {
48-
headers: {
49-
[HEADER_ACCEPT_LANGUAGE]: locale,
50-
},
51-
};
5235

5336
this.get({
5437
id: fileId,
55-
requestData: params,
5638
successCallback: openWithIntegrations => {
5739
const formattedOpenWithData = this.formatOpenWithData(openWithIntegrations);
5840
const consolidatedOpenWithIntegrations = this.consolidateBoxEditIntegrations(formattedOpenWithData);

src/api/__tests__/OpenWith-test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ describe('api/ContentOpenWith', () => {
2424
expect(openWith.formatOpenWithData).toBeCalledWith(data);
2525
expect(openWith.consolidateBoxEditIntegrations).toBeCalled();
2626
});
27-
28-
test('should correctly pass language header', () => {
29-
const successFn = jest.fn();
30-
const errorFn = jest.fn();
31-
openWith.get = ({ requestData }) => {
32-
const { headers } = requestData;
33-
expect(headers['Accept-Language']).toEqual('es-ES');
34-
};
35-
36-
openWith.getOpenWithIntegrations('123', successFn, errorFn, 'es-ES');
37-
});
3827
});
3928

4029
describe('consolidateBoxEditIntegrations()', () => {

src/elements/content-explorer/ContentExplorer.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,32 @@ class ContentExplorer extends Component<Props, State> {
192192
super(props);
193193

194194
const {
195-
token,
196-
sharedLink,
197-
sharedLinkPassword,
198195
apiHost,
199-
uploadHost,
200196
initialPage,
201197
initialPageSize,
202-
sortBy,
203-
sortDirection,
198+
language,
204199
requestInterceptor,
205200
responseInterceptor,
206201
rootFolderId,
202+
sharedLink,
203+
sharedLinkPassword,
204+
sortBy,
205+
sortDirection,
206+
token,
207+
uploadHost,
207208
}: Props = props;
208209

209210
this.api = new API({
210-
token,
211-
sharedLink,
212-
sharedLinkPassword,
213211
apiHost,
214-
uploadHost,
215-
requestInterceptor,
216-
responseInterceptor,
217212
clientName: CLIENT_NAME_CONTENT_EXPLORER,
218213
id: `${TYPED_ID_FOLDER_PREFIX}${rootFolderId}`,
214+
language,
215+
requestInterceptor,
216+
responseInterceptor,
217+
sharedLink,
218+
sharedLinkPassword,
219+
token,
220+
uploadHost,
219221
});
220222

221223
this.id = uniqueid('bce_');

src/elements/content-open-with/ContentOpenWith.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ class ContentOpenWith extends PureComponent<Props, State> {
126126
constructor(props: Props) {
127127
super(props);
128128

129-
const { token, apiHost, clientName, requestInterceptor, responseInterceptor } = props;
129+
const { token, apiHost, clientName, language, requestInterceptor, responseInterceptor } = props;
130130
this.id = uniqueid('bcow_');
131131
this.api = new API({
132-
token,
133132
apiHost,
134133
clientName,
134+
language,
135135
requestInterceptor,
136136
responseInterceptor,
137+
token,
137138
});
138139

139140
// Clone initial state to allow for state reset on new files
@@ -224,10 +225,10 @@ class ContentOpenWith extends PureComponent<Props, State> {
224225
* @return {void}
225226
*/
226227
fetchOpenWithData(): void {
227-
const { fileId, language }: Props = this.props;
228+
const { fileId }: Props = this.props;
228229
this.api
229230
.getOpenWithAPI(false)
230-
.getOpenWithIntegrations(fileId, this.fetchOpenWithSuccessHandler, this.fetchErrorHandler, language);
231+
.getOpenWithIntegrations(fileId, this.fetchOpenWithSuccessHandler, this.fetchErrorHandler);
231232
}
232233

233234
/**

src/elements/content-open-with/__tests__/ContentOpenWith-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('elements/content-open-with/ContentOpenWith', () => {
8686
instance.api = api;
8787

8888
instance.fetchOpenWithData();
89-
expect(openWithStub).toHaveBeenCalledWith('1234', expect.any(Function), expect.any(Function), 'en-US');
89+
expect(openWithStub).toHaveBeenCalledWith('1234', expect.any(Function), expect.any(Function));
9090
});
9191
});
9292

src/elements/content-picker/ContentPicker.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,31 +161,33 @@ class ContentPicker extends Component<Props, State> {
161161
super(props);
162162

163163
const {
164-
token,
165-
sharedLink,
166-
sharedLinkPassword,
167164
apiHost,
168-
uploadHost,
165+
clientName,
169166
initialPage,
170167
initialPageSize,
171-
sortBy,
172-
sortDirection,
173-
clientName,
168+
language,
174169
requestInterceptor,
175170
responseInterceptor,
176171
rootFolderId,
172+
sharedLink,
173+
sharedLinkPassword,
174+
sortBy,
175+
sortDirection,
176+
token,
177+
uploadHost,
177178
} = props;
178179

179180
this.api = new API({
180-
token,
181-
sharedLink,
182-
sharedLinkPassword,
183181
apiHost,
184-
uploadHost,
185182
clientName,
183+
id: `${TYPED_ID_FOLDER_PREFIX}${rootFolderId}`,
184+
language,
186185
requestInterceptor,
187186
responseInterceptor,
188-
id: `${TYPED_ID_FOLDER_PREFIX}${rootFolderId}`,
187+
sharedLink,
188+
sharedLinkPassword,
189+
token,
190+
uploadHost,
189191
});
190192

191193
this.id = uniqueid('bcp_');

src/elements/content-preview/ContentPreview.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,28 @@ class ContentPreview extends PureComponent<Props, State> {
213213
constructor(props: Props) {
214214
super(props);
215215
const {
216-
cache,
217-
token,
218-
sharedLink,
219-
sharedLinkPassword,
220216
apiHost,
217+
cache,
218+
fileId,
219+
language,
221220
requestInterceptor,
222221
responseInterceptor,
223-
fileId,
222+
sharedLink,
223+
sharedLinkPassword,
224+
token,
224225
} = props;
225226

226227
this.id = uniqueid('bcpr_');
227228
this.api = new API({
228-
cache,
229-
token,
230-
sharedLink,
231-
sharedLinkPassword,
232229
apiHost,
230+
cache,
233231
clientName: CLIENT_NAME_CONTENT_PREVIEW,
232+
language,
234233
requestInterceptor,
235234
responseInterceptor,
235+
sharedLink,
236+
sharedLinkPassword,
237+
token,
236238
});
237239
this.state = {
238240
...this.initialState,
@@ -1183,6 +1185,7 @@ class ContentPreview extends PureComponent<Props, State> {
11831185
getPreview={this.getPreview}
11841186
getViewer={this.getViewer}
11851187
history={history}
1188+
language={language}
11861189
sharedLink={sharedLink}
11871190
sharedLinkPassword={sharedLinkPassword}
11881191
requestInterceptor={requestInterceptor}

src/elements/content-sidebar/ContentSidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ContentSidebar extends React.Component<Props, State> {
110110
apiHost,
111111
cache,
112112
clientName,
113+
language,
113114
requestInterceptor,
114115
responseInterceptor,
115116
sharedLink,
@@ -121,6 +122,7 @@ class ContentSidebar extends React.Component<Props, State> {
121122
apiHost,
122123
cache,
123124
clientName,
125+
language,
124126
requestInterceptor,
125127
responseInterceptor,
126128
sharedLink,

0 commit comments

Comments
 (0)