Skip to content

Commit 742ba58

Browse files
chore(metadata-view): streamline storybook (#4212)
* chore(metadata-view): streamline storybook * feat(metadata-view): streamline storybook --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent bee412f commit 742ba58

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,61 @@ import ContentExplorer from '../../ContentExplorer';
55
import { DEFAULT_HOSTNAME_API } from '../../../../constants';
66
import { mockMetadata, mockSchema } from '../../../common/__mocks__/mockMetadata';
77

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;
1210

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}`;
2113

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+
],
2325
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',
2829
],
2930
};
3031

32+
// Used for metadata view v1
3133
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+
})),
3659
];
3760

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';
4763

4864
type Story = StoryObj<typeof ContentExplorer>;
4965

@@ -55,7 +71,7 @@ export const metadataView: Story = {
5571
},
5672
};
5773

58-
export const withNewMetadataView: Story = {
74+
export const metadataViewV2: Story = {
5975
args: {
6076
metadataViewProps: {
6177
columns,

0 commit comments

Comments
 (0)