box-ui-elements 23.4.0-beta.23 → 23.4.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ class BaseUpload extends Base {
30
30
 
31
31
  folderId: string;
32
32
 
33
- overwrite: boolean;
33
+ overwrite: boolean | 'error';
34
34
 
35
35
  conflictCallback: ?(fileName: string) => string;
36
36
 
@@ -159,6 +159,10 @@ class BaseUpload extends Base {
159
159
  this.errorCallback(errorData);
160
160
  // Automatically handle name conflict errors
161
161
  } else if (errorData && errorData.status === 409) {
162
+ if (this.overwrite === 'error') {
163
+ this.errorCallback(errorData);
164
+ return;
165
+ }
162
166
  if (this.overwrite) {
163
167
  // Error response contains file ID to upload a new file version for
164
168
  const conflictFileId = errorData.context_info.conflicts.id;
@@ -173,6 +173,7 @@ class MultiputUpload extends BaseMultiput {
173
173
  errorCallback,
174
174
  progressCallback,
175
175
  successCallback,
176
+ // $FlowFixMe
176
177
  overwrite = true,
177
178
  conflictCallback,
178
179
  fileId,
@@ -182,7 +183,7 @@ class MultiputUpload extends BaseMultiput {
182
183
  file: File,
183
184
  fileId: ?string,
184
185
  folderId: string,
185
- overwrite?: boolean,
186
+ overwrite?: boolean | 'error',
186
187
  progressCallback?: Function,
187
188
  successCallback?: Function,
188
189
  }): void {
@@ -217,6 +218,7 @@ class MultiputUpload extends BaseMultiput {
217
218
  errorCallback,
218
219
  progressCallback,
219
220
  successCallback,
221
+ // $FlowFixMe
220
222
  overwrite = true,
221
223
  conflictCallback,
222
224
  fileId,
@@ -227,7 +229,7 @@ class MultiputUpload extends BaseMultiput {
227
229
  fileDescription: ?string,
228
230
  fileId: ?string,
229
231
  folderId: string,
230
- overwrite?: boolean,
232
+ overwrite?: boolean | 'error',
231
233
  progressCallback?: Function,
232
234
  successCallback?: Function,
233
235
  }): void {
@@ -337,6 +339,10 @@ class MultiputUpload extends BaseMultiput {
337
339
  }
338
340
 
339
341
  if (errorData && errorData.status === 409) {
342
+ if (this.overwrite === 'error') {
343
+ this.errorCallback(errorData);
344
+ return;
345
+ }
340
346
  this.resolveConflict(errorData);
341
347
  this.createSessionRetry();
342
348
  return;
@@ -437,6 +443,7 @@ class MultiputUpload extends BaseMultiput {
437
443
  progressCallback,
438
444
  sessionId,
439
445
  successCallback,
446
+ // $FlowFixMe
440
447
  overwrite = true,
441
448
  conflictCallback,
442
449
  fileId,
@@ -446,7 +453,7 @@ class MultiputUpload extends BaseMultiput {
446
453
  file: File,
447
454
  fileId: ?string,
448
455
  folderId: string,
449
- overwrite?: boolean,
456
+ overwrite?: boolean | 'error',
450
457
  progressCallback?: Function,
451
458
  sessionId: string,
452
459
  successCallback?: Function,
@@ -598,9 +605,7 @@ class MultiputUpload extends BaseMultiput {
598
605
 
599
606
  await retryNumOfTimes(
600
607
  (resolve: Function, reject: Function): void => {
601
- this.logEvent(logEventType, logMessage)
602
- .then(resolve)
603
- .catch(reject);
608
+ this.logEvent(logEventType, logMessage).then(resolve).catch(reject);
604
609
  },
605
610
  this.config.retries,
606
611
  this.config.initialRetryDelayMs,
@@ -116,7 +116,7 @@ class PlainUpload extends BaseUpload {
116
116
  * @param {Function} [options.errorCallback] - Function to call with errors
117
117
  * @param {Function} [options.progressCallback] - Function to call with progress
118
118
  * @param {Function} [options.conflictCallback] - Function to call on conflicting file names
119
- * @param {boolean} [overwrite] - Should upload overwrite file with same name
119
+ * @param {boolean|'error'} [overwrite] - Should upload overwrite file with same name, throw error, or call conflictCallback to rename
120
120
  * @return {void}
121
121
  */
122
122
  upload({
@@ -128,6 +128,7 @@ class PlainUpload extends BaseUpload {
128
128
  errorCallback = noop,
129
129
  progressCallback = noop,
130
130
  conflictCallback,
131
+ // $FlowFixMe
131
132
  overwrite = true,
132
133
  }: {
133
134
  conflictCallback?: Function,
@@ -136,7 +137,7 @@ class PlainUpload extends BaseUpload {
136
137
  fileDescription: ?string,
137
138
  fileId: ?string,
138
139
  folderId: string,
139
- overwrite: boolean,
140
+ overwrite: boolean | 'error',
140
141
  progressCallback: Function,
141
142
  successCallback: Function,
142
143
  }): void {
@@ -296,6 +296,20 @@ describe('api/uploads/BaseUpload', () => {
296
296
  expect(upload.makePreflightRequest).not.toHaveBeenCalled();
297
297
  });
298
298
 
299
+ test('should call error callback on file on 409 if overwrite property is "error"', () => {
300
+ const error = new Error();
301
+ error.status = 409;
302
+
303
+ upload.fileId = '123';
304
+ upload.overwrite = 'error';
305
+ upload.makePreflightRequest = jest.fn();
306
+ upload.errorCallback = jest.fn();
307
+
308
+ upload.preflightErrorHandler(error, () => {});
309
+
310
+ expect(upload.errorCallback).toHaveBeenCalledWith(error);
311
+ });
312
+
299
313
  test('should overwrite file on 409 if overwrite property is true', () => {
300
314
  upload.fileId = '123';
301
315
  upload.overwrite = true;
@@ -34,6 +34,7 @@ import {
34
34
  CLIENT_NAME_CONTENT_UPLOADER,
35
35
  DEFAULT_HOSTNAME_API,
36
36
  DEFAULT_HOSTNAME_UPLOAD,
37
+ ERROR_CODE_ITEM_NAME_IN_USE,
37
38
  ERROR_CODE_UPLOAD_FILE_LIMIT,
38
39
  STATUS_COMPLETE,
39
40
  STATUS_ERROR,
@@ -90,7 +91,7 @@ export interface ContentUploaderProps {
90
91
  onResume: (item: UploadItem) => void;
91
92
  onUpgradeCTAClick?: () => void;
92
93
  onUpload: (item?: UploadItem | BoxItem) => void;
93
- overwrite: boolean;
94
+ overwrite: boolean | 'error';
94
95
  requestInterceptor?: (response: AxiosResponse) => void;
95
96
  responseInterceptor?: (config: AxiosRequestConfig) => void;
96
97
  rootFolderId: string;
@@ -1083,7 +1084,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
1083
1084
  */
1084
1085
  onClick = (item: UploadItem) => {
1085
1086
  const { chunked, isResumableUploadsEnabled, onClickCancel, onClickResume, onClickRetry } = this.props;
1086
- const { file, status } = item;
1087
+ const { file, status, error } = item;
1087
1088
  const isChunkedUpload =
1088
1089
  chunked && !item.isFolder && file.size > CHUNKED_UPLOAD_MIN_SIZE_BYTES && isMultiputSupported();
1089
1090
  const isResumable = isResumableUploadsEnabled && isChunkedUpload && item.api.sessionId;
@@ -1097,7 +1098,10 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
1097
1098
  onClickCancel(item);
1098
1099
  break;
1099
1100
  case STATUS_ERROR:
1100
- if (isResumable) {
1101
+ if (error?.code === ERROR_CODE_ITEM_NAME_IN_USE) {
1102
+ this.removeFileFromUploadQueue(item);
1103
+ onClickCancel(item);
1104
+ } else if (isResumable) {
1101
1105
  item.bytesUploadedOnLastResume = item.api.totalUploadedBytes;
1102
1106
  this.resumeFile(item);
1103
1107
  onClickResume(item);
@@ -8,6 +8,7 @@ import { Size5, SurfaceStatusSurfaceSuccess } from '@box/blueprint-web-assets/to
8
8
  import IconInProgress from './IconInProgress';
9
9
 
10
10
  import {
11
+ ERROR_CODE_ITEM_NAME_IN_USE,
11
12
  ERROR_CODE_UPLOAD_FILE_SIZE_LIMIT_EXCEEDED,
12
13
  STATUS_COMPLETE,
13
14
  STATUS_ERROR,
@@ -70,8 +71,13 @@ const ItemAction = ({
70
71
  }
71
72
  break;
72
73
  case STATUS_ERROR:
73
- Icon = ArrowCurveForward;
74
- tooltip = isResumableUploadsEnabled ? messages.resume : messages.retry;
74
+ if (code === ERROR_CODE_ITEM_NAME_IN_USE) {
75
+ Icon = XMark;
76
+ tooltip = messages.uploadsCancelButtonTooltip;
77
+ } else {
78
+ Icon = ArrowCurveForward;
79
+ tooltip = isResumableUploadsEnabled ? messages.resume : messages.retry;
80
+ }
75
81
  break;
76
82
  case STATUS_IN_PROGRESS:
77
83
  case STATUS_STAGED: