box-ui-elements 24.0.0-beta.6 → 24.0.0-beta.7

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.
@@ -228,19 +228,6 @@ describe('elements/content-explorer/MetadataQueryBuilder', () => {
228
228
  });
229
229
  });
230
230
 
231
- test('should handle mimetype-filter field key specially', () => {
232
- const filterValue = ['pdf', 'doc'];
233
- const result = getSelectFilter(filterValue, 'mimetype-filter', 0);
234
- expect(result).toEqual({
235
- queryParams: {
236
- arg_mimetype_filter_1: 'pdf',
237
- arg_mimetype_filter_2: 'doc',
238
- },
239
- queries: ['(item.extension HASANY (:arg_mimetype_filter_1, :arg_mimetype_filter_2))'],
240
- keysGenerated: 2,
241
- });
242
- });
243
-
244
231
  test('should handle single value array', () => {
245
232
  const filterValue = ['single_value'];
246
233
  const result = getSelectFilter(filterValue, 'field_name', 0);
@@ -309,44 +296,51 @@ describe('elements/content-explorer/MetadataQueryBuilder', () => {
309
296
  });
310
297
 
311
298
  describe('getMimeTypeFilter', () => {
312
- test('should generate mime type filter and remove "Type" suffix', () => {
313
- const filterValue = ['pdfType', 'docType', 'txtType'];
299
+ test('should generate mime type filter using mapFileTypes', () => {
300
+ const filterValue = ['pdfType', 'documentType'];
314
301
  const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
315
302
  expect(result).toEqual({
316
303
  queryParams: {
317
304
  arg_mimetype_1: 'pdf',
318
305
  arg_mimetype_2: 'doc',
319
- arg_mimetype_3: 'txt',
306
+ arg_mimetype_3: 'docx',
307
+ arg_mimetype_4: 'gdoc',
308
+ arg_mimetype_5: 'rtf',
309
+ arg_mimetype_6: 'txt',
320
310
  },
321
- queries: ['(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3))'],
322
- keysGenerated: 3,
311
+ queries: [
312
+ '(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6))',
313
+ ],
314
+ keysGenerated: 6,
323
315
  });
324
316
  });
325
317
 
326
- test('should handle values without "Type" suffix', () => {
318
+ test('should handle values that are not in FILE_FOLDER_TYPES_MAP', () => {
327
319
  const filterValue = ['pdf', 'doc'];
328
320
  const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
329
321
  expect(result).toEqual({
330
- queryParams: {
331
- arg_mimetype_1: 'pdf',
332
- arg_mimetype_2: 'doc',
333
- },
334
- queries: ['(item.extension IN (:arg_mimetype_1, :arg_mimetype_2))'],
335
- keysGenerated: 2,
322
+ queryParams: {},
323
+ queries: [],
324
+ keysGenerated: 0,
336
325
  });
337
326
  });
338
327
 
339
- test('should handle mixed values with and without "Type" suffix', () => {
340
- const filterValue = ['pdfType', 'doc', 'txtType'];
328
+ test('should handle mixed valid and invalid values', () => {
329
+ const filterValue = ['pdfType', 'doc', 'documentType'];
341
330
  const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
342
331
  expect(result).toEqual({
343
332
  queryParams: {
344
333
  arg_mimetype_1: 'pdf',
345
334
  arg_mimetype_2: 'doc',
346
- arg_mimetype_3: 'txt',
335
+ arg_mimetype_3: 'docx',
336
+ arg_mimetype_4: 'gdoc',
337
+ arg_mimetype_5: 'rtf',
338
+ arg_mimetype_6: 'txt',
347
339
  },
348
- queries: ['(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3))'],
349
- keysGenerated: 3,
340
+ queries: [
341
+ '(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6))',
342
+ ],
343
+ keysGenerated: 6,
350
344
  });
351
345
  });
352
346
 
@@ -360,16 +354,13 @@ describe('elements/content-explorer/MetadataQueryBuilder', () => {
360
354
  });
361
355
  });
362
356
 
363
- test('should handle numeric values converted to strings', () => {
357
+ test('should handle numeric values that are not in FILE_FOLDER_TYPES_MAP', () => {
364
358
  const filterValue = ['123', '456'];
365
359
  const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
366
360
  expect(result).toEqual({
367
- queryParams: {
368
- arg_mimetype_1: '123',
369
- arg_mimetype_2: '456',
370
- },
371
- queries: ['(item.extension IN (:arg_mimetype_1, :arg_mimetype_2))'],
372
- keysGenerated: 2,
361
+ queryParams: {},
362
+ queries: [],
363
+ keysGenerated: 0,
373
364
  });
374
365
  });
375
366
 
@@ -402,15 +393,140 @@ describe('elements/content-explorer/MetadataQueryBuilder', () => {
402
393
  });
403
394
 
404
395
  test('should handle field names with special characters', () => {
405
- const filterValue = ['pdfType', 'docType'];
396
+ const filterValue = ['pdfType', 'documentType'];
406
397
  const result = getMimeTypeFilter(filterValue, 'mime-type.with/special_chars', 0);
407
398
  expect(result).toEqual({
408
399
  queryParams: {
409
400
  arg_mime_type_with_special_chars_1: 'pdf',
410
401
  arg_mime_type_with_special_chars_2: 'doc',
402
+ arg_mime_type_with_special_chars_3: 'docx',
403
+ arg_mime_type_with_special_chars_4: 'gdoc',
404
+ arg_mime_type_with_special_chars_5: 'rtf',
405
+ arg_mime_type_with_special_chars_6: 'txt',
406
+ },
407
+ queries: [
408
+ '(item.extension IN (:arg_mime_type_with_special_chars_1, :arg_mime_type_with_special_chars_2, :arg_mime_type_with_special_chars_3, :arg_mime_type_with_special_chars_4, :arg_mime_type_with_special_chars_5, :arg_mime_type_with_special_chars_6))',
409
+ ],
410
+ keysGenerated: 6,
411
+ });
412
+ });
413
+
414
+ // New tests for folderType functionality
415
+ test('should handle folderType only', () => {
416
+ const filterValue = ['folderType'];
417
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
418
+ expect(result).toEqual({
419
+ queryParams: {
420
+ arg_mime_folderType_1: 'folder',
421
+ },
422
+ queries: ['(item.type = :arg_mime_folderType_1)'],
423
+ keysGenerated: 1,
424
+ });
425
+ });
426
+
427
+ test('should handle folderType with file types', () => {
428
+ const filterValue = ['folderType', 'pdfType', 'documentType'];
429
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
430
+ expect(result).toEqual({
431
+ queryParams: {
432
+ arg_mime_folderType_1: 'folder',
433
+ arg_mimetype_2: 'pdf',
434
+ arg_mimetype_3: 'doc',
435
+ arg_mimetype_4: 'docx',
436
+ arg_mimetype_5: 'gdoc',
437
+ arg_mimetype_6: 'rtf',
438
+ arg_mimetype_7: 'txt',
439
+ },
440
+ queries: [
441
+ '((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
442
+ ],
443
+ keysGenerated: 7,
444
+ });
445
+ });
446
+
447
+ test('should handle folderType with mixed valid and invalid file types', () => {
448
+ const filterValue = ['folderType', 'pdfType', 'doc', 'documentType'];
449
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
450
+ expect(result).toEqual({
451
+ queryParams: {
452
+ arg_mime_folderType_1: 'folder',
453
+ arg_mimetype_2: 'pdf',
454
+ arg_mimetype_3: 'doc',
455
+ arg_mimetype_4: 'docx',
456
+ arg_mimetype_5: 'gdoc',
457
+ arg_mimetype_6: 'rtf',
458
+ arg_mimetype_7: 'txt',
459
+ },
460
+ queries: [
461
+ '((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
462
+ ],
463
+ keysGenerated: 7,
464
+ });
465
+ });
466
+
467
+ test('should handle folderType with single file type', () => {
468
+ const filterValue = ['folderType', 'pdfType'];
469
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
470
+ expect(result).toEqual({
471
+ queryParams: {
472
+ arg_mime_folderType_1: 'folder',
473
+ arg_mimetype_2: 'pdf',
474
+ },
475
+ queries: ['((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2)))'],
476
+ keysGenerated: 2,
477
+ });
478
+ });
479
+
480
+ test('should handle folderType with file types using correct arg index', () => {
481
+ const filterValue = ['folderType', 'pdfType', 'documentType'];
482
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 5);
483
+ expect(result).toEqual({
484
+ queryParams: {
485
+ arg_mime_folderType_6: 'folder',
486
+ arg_mimetype_7: 'pdf',
487
+ arg_mimetype_8: 'doc',
488
+ arg_mimetype_9: 'docx',
489
+ arg_mimetype_10: 'gdoc',
490
+ arg_mimetype_11: 'rtf',
491
+ arg_mimetype_12: 'txt',
492
+ },
493
+ queries: [
494
+ '((item.type = :arg_mime_folderType_6) OR (item.extension IN (:arg_mimetype_7, :arg_mimetype_8, :arg_mimetype_9, :arg_mimetype_10, :arg_mimetype_11, :arg_mimetype_12)))',
495
+ ],
496
+ keysGenerated: 7,
497
+ });
498
+ });
499
+
500
+ test('should handle multiple folderType entries (should only process one)', () => {
501
+ const filterValue = ['folderType', 'pdfType', 'folderType', 'documentType'];
502
+ const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
503
+ expect(result).toEqual({
504
+ queryParams: {
505
+ arg_mime_folderType_1: 'folder',
506
+ arg_mimetype_2: 'pdf',
507
+ arg_mimetype_3: 'doc',
508
+ arg_mimetype_4: 'docx',
509
+ arg_mimetype_5: 'gdoc',
510
+ arg_mimetype_6: 'rtf',
511
+ arg_mimetype_7: 'txt',
512
+ },
513
+ queries: [
514
+ '((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
515
+ ],
516
+ keysGenerated: 7,
517
+ });
518
+ });
519
+
520
+ test('should handle folderType with field names containing special characters', () => {
521
+ const filterValue = ['folderType', 'pdfType'];
522
+ const result = getMimeTypeFilter(filterValue, 'mime-type.with/special_chars', 0);
523
+ expect(result).toEqual({
524
+ queryParams: {
525
+ arg_mime_folderType_1: 'folder',
526
+ arg_mime_type_with_special_chars_2: 'pdf',
411
527
  },
412
528
  queries: [
413
- '(item.extension IN (:arg_mime_type_with_special_chars_1, :arg_mime_type_with_special_chars_2))',
529
+ '((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mime_type_with_special_chars_2)))',
414
530
  ],
415
531
  keysGenerated: 2,
416
532
  });
@@ -2,7 +2,7 @@ import { FIELD_FILE_VERSION, FIELD_SHA1, FIELD_SHARED_LINK, FIELD_WATERMARK_INFO
2
2
  import { FOLDER_FIELDS_TO_FETCH } from '../../utils/fields';
3
3
 
4
4
  // Fields needed for Content Explorer folder requests
5
- const CONTENT_EXPLORER_FOLDER_FIELDS_TO_FETCH = [
5
+ export const CONTENT_EXPLORER_FOLDER_FIELDS_TO_FETCH = [
6
6
  ...FOLDER_FIELDS_TO_FETCH,
7
7
  FIELD_FILE_VERSION,
8
8
  FIELD_SHA1,
@@ -10,4 +10,41 @@ const CONTENT_EXPLORER_FOLDER_FIELDS_TO_FETCH = [
10
10
  FIELD_WATERMARK_INFO,
11
11
  ];
12
12
 
13
- export default CONTENT_EXPLORER_FOLDER_FIELDS_TO_FETCH;
13
+ export const NON_FOLDER_FILE_TYPES_MAP = new Map([
14
+ ['boxnoteType', ['boxnote']],
15
+ ['boxcanvasType', ['boxcanvas']],
16
+ ['pdfType', ['pdf']],
17
+ ['documentType', ['doc', 'docx', 'gdoc', 'rtf', 'txt']],
18
+ ['spreadsheetType', ['xls', 'xlsx', 'xlsm', 'csv', 'gsheet']],
19
+ ['presentationType', ['ppt', 'pptx', 'odp']],
20
+ ['imageType', ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'tif', 'tiff']],
21
+ ['audioType', ['mp3', 'm4a', 'm4p', 'wav', 'mid', 'wma']],
22
+ [
23
+ 'videoType',
24
+ [
25
+ 'mp4',
26
+ 'mpeg',
27
+ 'mpg',
28
+ 'wmv',
29
+ '3g2',
30
+ '3gp',
31
+ 'avi',
32
+ 'm2v',
33
+ 'm4v',
34
+ 'mkv',
35
+ 'mov',
36
+ 'ogg',
37
+ 'mts',
38
+ 'qt',
39
+ 'ts',
40
+ 'flv',
41
+ 'rm',
42
+ ],
43
+ ],
44
+ ['drawingType', ['dwg', 'dxf']],
45
+ ['threedType', ['obj', 'fbx', 'stl', 'amf', 'iges']],
46
+ ]);
47
+
48
+ export const FILE_FOLDER_TYPES_MAP = new Map(NON_FOLDER_FILE_TYPES_MAP).set('folderType', ['folder']);
49
+
50
+ export const NON_FOLDER_FILE_TYPES = Array.from(NON_FOLDER_FILE_TYPES_MAP.keys());
@@ -11,9 +11,11 @@ import {
11
11
  } from '@box/metadata-editor';
12
12
  import type { MetadataFieldType } from '@box/metadata-view';
13
13
  import type { Selection } from 'react-aria-components';
14
+ import { BoxItemSelection } from '@box/box-item-type-selector';
14
15
  import type { BoxItem, Collection } from '../../common/types/core';
15
16
 
16
17
  import messages from '../common/messages';
18
+ import { FILE_FOLDER_TYPES_MAP, NON_FOLDER_FILE_TYPES } from './constants';
17
19
 
18
20
  // Specific type for metadata field value in the item
19
21
  // Note: Item doesn't have field value in metadata object if that field is not set, so the value will be undefined in this case
@@ -193,3 +195,18 @@ export function useTemplateInstance(metadataTemplate: MetadataTemplate, selected
193
195
  type,
194
196
  };
195
197
  }
198
+
199
+ export const mapFileTypes = (selectedFileTypes: BoxItemSelection) => {
200
+ const selectedFileTypesSet = new Set(selectedFileTypes);
201
+
202
+ const areAllNonFolderFileTypesSelected = NON_FOLDER_FILE_TYPES.every(key => selectedFileTypesSet.has(key));
203
+
204
+ if (areAllNonFolderFileTypesSelected) {
205
+ if (selectedFileTypes.includes('folderType')) {
206
+ return [];
207
+ }
208
+ return ['file'];
209
+ }
210
+
211
+ return selectedFileTypes.map(fileType => FILE_FOLDER_TYPES_MAP.get(fileType as string) || []).flat();
212
+ };