Skip to content

Commit ef49c77

Browse files
feat(content-sharing): Create ContentSharingV2 component (#4282)
* feat: Create ContentSharingV2 component * feat: Create ContentSharingV2 component * fix: flow * fix: remove not needed code * fix: remove not needed code * fix: address comments * fix: disable snapshot --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent cb04234 commit ef49c77

File tree

6 files changed

+131
-1
lines changed

6 files changed

+131
-1
lines changed

scripts/jest/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ module.exports = {
2626
testMatch: ['**/__tests__/**/*.test.+(js|jsx|ts|tsx)'],
2727
testPathIgnorePatterns: ['stories.test.js$', 'stories.test.tsx$', 'stories.test.d.ts'],
2828
transformIgnorePatterns: [
29-
'node_modules/(?!(@box/react-virtualized/dist/es|@box/cldr-data|@box/blueprint-web|@box/blueprint-web-assets|@box/metadata-editor|@box/box-ai-content-answers|@box/box-ai-agent-selector|@box/item-icon|@box/combobox-with-api|@box/tree|@box/metadata-filter|@box/metadata-view|@box/types|@box/box-item-type-selector)/)',
29+
'node_modules/(?!(@box/react-virtualized/dist/es|@box/cldr-data|@box/blueprint-web|@box/blueprint-web-assets|@box/metadata-editor|@box/box-ai-content-answers|@box/box-ai-agent-selector|@box/item-icon|@box/combobox-with-api|@box/tree|@box/metadata-filter|@box/metadata-view|@box/types|@box/box-item-type-selector|@box/unified-share-modal|@box/user-selector|@box/copy-input)/)',
3030
],
3131
};

src/elements/content-sharing/ContentSharing.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ import * as React from 'react';
1111
import API from '../../api';
1212
// $FlowFixMe
1313
import { withBlueprintModernization } from '../common/withBlueprintModernization';
14+
import { isFeatureEnabled } from '../common/feature-checking';
1415
import SharingModal from './SharingModal';
16+
// $FlowFixMe
17+
import ContentSharingV2 from './ContentSharingV2';
1518
import { CLIENT_NAME_CONTENT_SHARING, CLIENT_VERSION, DEFAULT_HOSTNAME_API } from '../../constants';
19+
1620
import type { ItemType, StringMap } from '../../common/types/core';
1721
import type { USMConfig } from '../../features/unified-share-modal/flowTypes';
22+
import type { FeatureConfig } from '../common/feature-checking';
1823

1924
import '../common/base.scss';
2025
import '../common/fonts.scss';
@@ -23,6 +28,8 @@ import '../common/modal.scss';
2328
type ContentSharingProps = {
2429
/** apiHost - API hostname. Defaults to https://api.box.com */
2530
apiHost: string,
31+
/** children - Children for the element to open the Unified Share Modal */
32+
children?: React.Element<any>,
2633
/** config - Configuration object that shows/hides features in the USM */
2734
config?: USMConfig,
2835
/**
@@ -37,6 +44,10 @@ type ContentSharingProps = {
3744
* the modal will appear on page load. See ContentSharing.stories.js for examples.
3845
*/
3946
displayInModal: boolean,
47+
/** features - Features for the element */
48+
features?: FeatureConfig,
49+
/** hasProviders - Whether the element has providers for USM already */
50+
hasProviders?: boolean,
4051
/** itemID - Box file or folder ID */
4152
itemID: string,
4253
/** itemType - "file" or "folder" */
@@ -62,9 +73,12 @@ const createAPI = (apiHost, itemID, itemType, token) =>
6273

6374
function ContentSharing({
6475
apiHost = DEFAULT_HOSTNAME_API,
76+
children,
6577
config,
6678
customButton,
6779
displayInModal,
80+
features = {},
81+
hasProviders = true,
6882
itemID,
6983
itemType,
7084
language,
@@ -100,6 +114,20 @@ function ContentSharing({
100114
}
101115
}, [config, customButton, displayInModal, itemID, itemType, language, launchButton, messages, isVisible]);
102116

117+
if (isFeatureEnabled(features, 'contentSharingV2')) {
118+
return (
119+
<ContentSharingV2
120+
itemID={itemID}
121+
itemType={itemType}
122+
hasProviders={hasProviders}
123+
language={language}
124+
messages={messages}
125+
>
126+
{children}
127+
</ContentSharingV2>
128+
);
129+
}
130+
103131
return (
104132
<>
105133
{launchButton}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as React from 'react';
2+
3+
import { UnifiedShareModal } from '@box/unified-share-modal';
4+
5+
import Internationalize from '../common/Internationalize';
6+
import Providers from '../common/Providers';
7+
8+
import type { ItemType, StringMap } from '../../common/types/core';
9+
10+
export interface ContentSharingV2Props {
11+
/** children - Children for the element to open the Unified Share Modal */
12+
children?: React.ReactElement;
13+
/** itemID - Box file or folder ID */
14+
itemID: string;
15+
/** itemType - "file" or "folder" */
16+
itemType: ItemType;
17+
/** hasProviders - Whether the element has providers for USM already */
18+
hasProviders: boolean;
19+
/** language - Language used for the element */
20+
language?: string;
21+
/** messages - Localized strings used by the element */
22+
messages?: StringMap;
23+
}
24+
25+
function ContentSharingV2({ children, itemID, itemType, hasProviders, language, messages }: ContentSharingV2Props) {
26+
// Retrieve item from API later
27+
const mockItem = {
28+
id: itemID,
29+
name: 'Box Development Guide.pdf',
30+
type: itemType,
31+
};
32+
33+
return (
34+
<Internationalize language={language} messages={messages}>
35+
<Providers hasProviders={hasProviders}>
36+
<UnifiedShareModal item={mockItem}>{children}</UnifiedShareModal>
37+
</Providers>
38+
</Internationalize>
39+
);
40+
}
41+
42+
export default ContentSharingV2;

src/elements/content-sharing/stories/ContentSharing.stories.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export const withCustomButton = {
1313
},
1414
};
1515

16+
export const withContentSharingV2Enabled = {
17+
args: {
18+
children: <button>Open Unified Share Modal</button>,
19+
features: {
20+
...global.FEATURE_FLAGS,
21+
contentSharingV2: true,
22+
},
23+
},
24+
};
25+
1626
export default {
1727
title: 'Elements/ContentSharing',
1828
component: ContentSharing,
@@ -21,11 +31,18 @@ export default {
2131
config: { showEmailSharedLinkForm: false, showInviteCollaboratorMessageSection: false },
2232
displayInModal: false,
2333
itemType: TYPE_FILE,
34+
itemID: global.FILE_ID,
35+
token: global.TOKEN,
2436
},
2537
argTypes: {
2638
itemType: {
2739
options: [TYPE_FILE, TYPE_FOLDER],
2840
control: { type: 'select' },
2941
},
3042
},
43+
parameters: {
44+
chromatic: {
45+
disableSnapshot: true,
46+
},
47+
},
3148
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react';
2+
import { TYPE_FILE, TYPE_FOLDER } from '../../../constants';
3+
import ContentSharingV2 from '../ContentSharingV2';
4+
5+
export const basic = {};
6+
7+
export default {
8+
title: 'Elements/ContentSharingV2',
9+
component: ContentSharingV2,
10+
args: {
11+
children: <button>Open Unified Share Modal</button>,
12+
itemType: TYPE_FILE,
13+
itemID: global.FILE_ID,
14+
},
15+
argTypes: {
16+
itemType: {
17+
options: [TYPE_FILE, TYPE_FOLDER],
18+
control: { type: 'select' },
19+
},
20+
},
21+
parameters: {
22+
chromatic: {
23+
disableSnapshot: true,
24+
},
25+
},
26+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TYPE_FILE } from '../../../../constants';
2+
import ContentSharingV2 from '../../ContentSharingV2';
3+
4+
export const withModernization = {
5+
args: {
6+
enableModernizedComponents: true,
7+
},
8+
};
9+
10+
export default {
11+
title: 'Elements/ContentSharingV2/tests/visual-regression-tests',
12+
component: ContentSharingV2,
13+
args: {
14+
itemType: TYPE_FILE,
15+
itemID: global.FILE_ID,
16+
},
17+
};

0 commit comments

Comments
 (0)