@@ -5,45 +5,61 @@ import ContentExplorer from '../../ContentExplorer';
5
5
import { DEFAULT_HOSTNAME_API } from '../../../../constants' ;
6
6
import { mockMetadata , mockSchema } from '../../../common/__mocks__/mockMetadata' ;
7
7
8
- const EID = '0' ;
9
- const templateName = 'templateName' ;
10
- const metadataSource = `enterprise_${ EID } .${ templateName } ` ;
11
- const metadataSourceFieldName = `metadata.${ metadataSource } ` ;
8
+ // The intent behind relying on mockMetadata is to allow a developer to paste in their own metadata template schema for use with live API calls.
9
+ const { scope : templateScope , templateKey } = mockSchema ;
12
10
13
- const metadataQuery = {
14
- from : metadataSource ,
15
-
16
- // // Filter items in the folder by existing metadata key
17
- // query: 'key = :arg1',
18
- //
19
- // // Display items with value
20
- // query_params: { arg1: 'value' },
11
+ const metadataScopeAndKey = `${ templateScope } .${ templateKey } ` ;
12
+ const metadataFieldNamePrefix = `metadata.${ metadataScopeAndKey } ` ;
21
13
22
- ancestor_folder_id : '313259567207' ,
14
+ // This is the body of the metadata query API call.
15
+ // https://developer.box.com/guides/metadata/queries/syntax/
16
+ const metadataQuery = {
17
+ from : metadataScopeAndKey ,
18
+ ancestor_folder_id : '0' ,
19
+ sort_by : [
20
+ {
21
+ field_key : `${ metadataFieldNamePrefix } .${ mockSchema . fields [ 0 ] . key } ` , // Default to sorting by the first field in the schema
22
+ direction : 'asc' ,
23
+ } ,
24
+ ] ,
23
25
fields : [
24
- `${ metadataSourceFieldName } .name` ,
25
- `${ metadataSourceFieldName } .industry` ,
26
- `${ metadataSourceFieldName } .last_contacted_at` ,
27
- `${ metadataSourceFieldName } .role` ,
26
+ // Default to returning all fields in the metadata template schema, and name as a standalone (non-metadata) field
27
+ ...mockSchema . fields . map ( field => `${ metadataFieldNamePrefix } .${ field . key } ` ) ,
28
+ 'name' ,
28
29
] ,
29
30
} ;
30
31
32
+ // Used for metadata view v1
31
33
const fieldsToShow = [
32
- { key : `${ metadataSourceFieldName } .name` , canEdit : false , displayName : 'Alias' } ,
33
- { key : `${ metadataSourceFieldName } .industry` , canEdit : true } ,
34
- { key : `${ metadataSourceFieldName } .last_contacted_at` , canEdit : true } ,
35
- { key : `${ metadataSourceFieldName } .role` , canEdit : true } ,
34
+ { key : `${ metadataFieldNamePrefix } .name` , canEdit : false , displayName : 'Alias' } ,
35
+ { key : `${ metadataFieldNamePrefix } .industry` , canEdit : true } ,
36
+ { key : `${ metadataFieldNamePrefix } .last_contacted_at` , canEdit : true } ,
37
+ { key : `${ metadataFieldNamePrefix } .role` , canEdit : true } ,
38
+ ] ;
39
+
40
+ // Used for metadata view v2
41
+ const columns = [
42
+ {
43
+ // Always include the name column
44
+ textValue : 'Name' ,
45
+ id : 'name' ,
46
+ type : 'string' ,
47
+ allowSorting : true ,
48
+ minWidth : 150 ,
49
+ maxWidth : 150 ,
50
+ } ,
51
+ ...mockSchema . fields . map ( field => ( {
52
+ textValue : field . displayName ,
53
+ id : `${ metadataFieldNamePrefix } .${ field . key } ` ,
54
+ type : field . type ,
55
+ allowSorting : true ,
56
+ minWidth : 150 ,
57
+ maxWidth : 150 ,
58
+ } ) ) ,
36
59
] ;
37
60
38
- const columns = mockSchema . fields . map ( field => ( {
39
- textValue : field . displayName ,
40
- id : `${ metadataSourceFieldName } .${ field . key } ` ,
41
- type : field . type ,
42
- allowSorting : true ,
43
- minWidth : 150 ,
44
- maxWidth : 150 ,
45
- } ) ) ;
46
- const defaultView = 'metadata' ; // Required prop to paint the metadata view. If not provided, you'll get regular folder view.
61
+ // Switches ContentExplorer to use Metadata View over standard, folder-based view.
62
+ const defaultView = 'metadata' ;
47
63
48
64
type Story = StoryObj < typeof ContentExplorer > ;
49
65
@@ -55,7 +71,7 @@ export const metadataView: Story = {
55
71
} ,
56
72
} ;
57
73
58
- export const withNewMetadataView : Story = {
74
+ export const metadataViewV2 : Story = {
59
75
args : {
60
76
metadataViewProps : {
61
77
columns,
0 commit comments