Skip to content

Commit e3c7277

Browse files
feixuanlimergify[bot]
authored andcommitted
feat(unified-share-modal): show classification for the file (#1425)
* fix(usm): take in children elements * feat(unified-share-modal): address cr feedback * feat(unified-share-modal): title component
1 parent 5baeb5b commit e3c7277

File tree

7 files changed

+530
-229
lines changed

7 files changed

+530
-229
lines changed

src/features/unified-share-modal/UnifiedShareModal.js

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ITEM_TYPE_WEBLINK } from '../../common/constants';
1616
import Tooltip from '../../components/tooltip';
1717
import { CollaboratorAvatars, CollaboratorList } from '../collaborator-avatars';
1818

19+
import UnifiedShareModalTitle from './UnifiedShareModalTitle';
1920
import InviteePermissionsMenu from './InviteePermissionsMenu';
2021
import messages from './messages';
2122
import RemoveLinkConfirmModal from './RemoveLinkConfirmModal';
@@ -52,6 +53,7 @@ type Props = {
5253
changeSharedLinkPermissionLevel: (
5354
newPermissionLevel: permissionLevelType,
5455
) => Promise<{ permissionLevel: permissionLevelType }>,
56+
classification: ClassificationInfo,
5557
/** If item is classified this property contains the classification name */
5658
classificationName?: string,
5759
/** Message warning about restrictions regarding inviting collaborators to the item */
@@ -618,44 +620,6 @@ class UnifiedShareModal extends React.Component<Props, State> {
618620
);
619621
}
620622

621-
renderModalTitle() {
622-
const { isEmailLinkSectionExpanded, showCollaboratorList } = this.state;
623-
const { item } = this.props;
624-
const { name } = item;
625-
let title;
626-
627-
if (isEmailLinkSectionExpanded) {
628-
title = (
629-
<FormattedMessage
630-
{...messages.emailModalTitle}
631-
values={{
632-
itemName: name,
633-
}}
634-
/>
635-
);
636-
} else if (showCollaboratorList) {
637-
title = (
638-
<FormattedMessage
639-
{...messages.collaboratorListTitle}
640-
values={{
641-
itemName: name,
642-
}}
643-
/>
644-
);
645-
} else {
646-
title = (
647-
<FormattedMessage
648-
{...messages.modalTitle}
649-
values={{
650-
itemName: name,
651-
}}
652-
/>
653-
);
654-
}
655-
656-
return title;
657-
}
658-
659623
renderCollaboratorList() {
660624
const { item, collaboratorsList, trackingProps } = this.props;
661625
const { name, type } = item;
@@ -685,6 +649,7 @@ class UnifiedShareModal extends React.Component<Props, State> {
685649
const {
686650
changeSharedLinkAccessLevel,
687651
changeSharedLinkPermissionLevel,
652+
classification,
688653
classificationName,
689654
focusSharedLinkOnLoad,
690655
item,
@@ -736,7 +701,14 @@ class UnifiedShareModal extends React.Component<Props, State> {
736701
className="unified-share-modal"
737702
isOpen={isConfirmModalOpen ? false : isOpen}
738703
onRequestClose={submitting ? undefined : onRequestClose}
739-
title={<span>{this.renderModalTitle()}</span>}
704+
title={
705+
<UnifiedShareModalTitle
706+
classification={classification}
707+
isEmailLinkSectionExpanded={isEmailLinkSectionExpanded}
708+
showCollaboratorList={showCollaboratorList}
709+
item={item}
710+
/>
711+
}
740712
{...extendedModalProps}
741713
>
742714
<LoadingIndicatorWrapper isLoading={isFetching} hideContent>

src/features/unified-share-modal/UnifiedShareModal.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
}
5151

5252
.unified-share-modal {
53+
/** title and classifiction label */
54+
.bdl-UnifiedShareModalTitle {
55+
display: flex;
56+
flex-flow: row wrap;
57+
58+
.bdl-UnifiedShareModalTitle-classification {
59+
margin-left: 6px;
60+
}
61+
}
62+
5363
/** overrides for USM sub-components */
5464
.text-area-container {
5565
position: static;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// @flow
2+
import React from 'react';
3+
import { FormattedMessage } from 'react-intl';
4+
5+
import Classification from '../classification';
6+
import messages from './messages';
7+
import type { item as ItemType } from './flowTypes';
8+
9+
type Props = {
10+
classification: ClassificationInfo,
11+
isEmailLinkSectionExpanded: boolean,
12+
item: ItemType,
13+
showCollaboratorList: boolean,
14+
};
15+
16+
function getTitle(isEmailLinkSectionExpanded, showCollaboratorList, item) {
17+
const { name } = item;
18+
let title;
19+
20+
if (isEmailLinkSectionExpanded) {
21+
title = (
22+
<FormattedMessage
23+
{...messages.emailModalTitle}
24+
values={{
25+
itemName: name,
26+
}}
27+
/>
28+
);
29+
} else if (showCollaboratorList) {
30+
title = (
31+
<FormattedMessage
32+
{...messages.collaboratorListTitle}
33+
values={{
34+
itemName: name,
35+
}}
36+
/>
37+
);
38+
} else {
39+
title = (
40+
<FormattedMessage
41+
{...messages.modalTitle}
42+
values={{
43+
itemName: name,
44+
}}
45+
/>
46+
);
47+
}
48+
49+
return title;
50+
}
51+
52+
const UnifiedShareModalTitle = ({ classification, isEmailLinkSectionExpanded, showCollaboratorList, item }: Props) => {
53+
const title = getTitle(isEmailLinkSectionExpanded, showCollaboratorList, item);
54+
const { advisoryMessage, name } = classification;
55+
56+
return (
57+
<span className="bdl-UnifiedShareModalTitle">
58+
{title}
59+
<Classification
60+
advisoryMessage={advisoryMessage}
61+
messageStyle="tooltip"
62+
name={name}
63+
className="bdl-UnifiedShareModalTitle-classification"
64+
/>
65+
</span>
66+
);
67+
};
68+
69+
export default UnifiedShareModalTitle;

src/features/unified-share-modal/__tests__/UnifiedShareModal-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('features/unified-share-modal/UnifiedShareModal', () => {
3333
const getWrapper = (props = {}) =>
3434
shallow(
3535
<UnifiedShareModal
36+
classification={{ advisoryMessage: undefined, name: undefined }}
3637
collaborationRestrictionWarning=""
3738
getInitialData={jest.fn().mockImplementation(() => Promise.resolve('test'))}
3839
intl={intl}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @flow
2+
import React from 'react';
3+
import { shallow } from 'enzyme';
4+
5+
import UnifiedShareModalTitle from '../UnifiedShareModalTitle';
6+
7+
describe('features/unified-share-modal/HeaderTitle', () => {
8+
let wrapper;
9+
const defaultItem = {
10+
id: '111',
11+
name: 'test file',
12+
type: 'file',
13+
grantedPermissions: {
14+
itemShare: true,
15+
},
16+
hideCollaborators: false,
17+
};
18+
19+
const getWrapper = (props = {}) => {
20+
return shallow(
21+
<UnifiedShareModalTitle
22+
classification={{ advisoryMessage: 'Internal use only', name: 'TopSecret' }}
23+
item={defaultItem}
24+
{...props}
25+
/>,
26+
);
27+
};
28+
29+
beforeEach(() => {
30+
wrapper = getWrapper();
31+
});
32+
33+
test('should render classifiction label with title', () => {
34+
expect(wrapper).toMatchSnapshot();
35+
});
36+
});

0 commit comments

Comments
 (0)