Skip to content

Commit 19a7978

Browse files
authored
feat(unified-share-modal): add custom permission descriptions (#4071)
* feat(unified-share-modal): add custom permission descriptions * feat(unified-share-modal): address review comments * feat(unified-share-modal): Add custom description to USM story
1 parent bcd2b86 commit 19a7978

7 files changed

+62
-13
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import { EDITOR, CO_OWNER, PREVIEWER, PREVIEWER_UPLOADER, VIEWER, VIEWER_UPLOADE
88
import messages from './messages';
99

1010
type Props = {
11+
description?: string,
1112
inviteePermissionLevel: string,
1213
itemType: ItemType,
1314
};
1415

15-
const InviteePermissionDescription = ({ inviteePermissionLevel, itemType }: Props) => {
16+
const InviteePermissionDescription = ({ description, inviteePermissionLevel, itemType }: Props) => {
17+
if (description) {
18+
return <small className="usm-menu-description">{description}</small>;
19+
}
20+
1621
const permissionDescriptions = {
1722
[EDITOR]: itemType === 'folder' ? messages.editorLevelDescription : messages.editorLevelFileDescription,
1823
[CO_OWNER]: messages.coownerLevelDescription,
@@ -23,11 +28,11 @@ const InviteePermissionDescription = ({ inviteePermissionLevel, itemType }: Prop
2328
[UPLOADER]: messages.uploaderLevelDescription,
2429
};
2530

26-
const description = permissionDescriptions[inviteePermissionLevel];
31+
const defaultDescription = permissionDescriptions[inviteePermissionLevel];
2732

2833
return (
2934
<small className="usm-menu-description">
30-
<FormattedMessage {...description} />
35+
<FormattedMessage {...defaultDescription} />
3136
</small>
3237
);
3338
};

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import messages from './messages';
1010

1111
type Props = {
1212
hasDescription?: boolean,
13+
inviteePermissionDescription?: string,
1314
inviteePermissionLevel: string,
1415
itemType: ItemType,
1516
};
1617

17-
const InviteePermissionsLabel = ({ hasDescription, inviteePermissionLevel, itemType }: Props) => {
18+
const InviteePermissionsLabel = ({
19+
hasDescription,
20+
inviteePermissionDescription,
21+
inviteePermissionLevel,
22+
itemType,
23+
}: Props) => {
1824
const permissionOptionsTexts = {
1925
[EDITOR]: messages.editorLevelText,
2026
[CO_OWNER]: messages.coownerLevelText,
@@ -40,7 +46,11 @@ const InviteePermissionsLabel = ({ hasDescription, inviteePermissionLevel, itemT
4046
<strong>
4147
<FormattedMessage {...permissionOptionsTexts[inviteePermissionLevel]} />{' '}
4248
</strong>
43-
<InviteePermissionsDescription inviteePermissionLevel={inviteePermissionLevel} itemType={itemType} />
49+
<InviteePermissionsDescription
50+
description={inviteePermissionDescription}
51+
inviteePermissionLevel={inviteePermissionLevel}
52+
itemType={itemType}
53+
/>
4454
</span>
4555
) : (
4656
<FormattedMessage {...permissionLabelTexts[inviteePermissionLevel]} />

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class InviteePermissionsMenu extends Component<Props> {
5858
>
5959
<InviteePermissionsLabel
6060
hasDescription
61+
inviteePermissionDescription={level.description}
6162
inviteePermissionLevel={level.value}
6263
inviteePermissions
6364
itemType={itemType}
@@ -70,13 +71,8 @@ class InviteePermissionsMenu extends Component<Props> {
7071
}
7172

7273
render() {
73-
const {
74-
inviteePermissions,
75-
inviteePermissionsButtonProps,
76-
inviteePermissionLevel,
77-
disabled,
78-
itemType,
79-
} = this.props;
74+
const { inviteePermissions, inviteePermissionsButtonProps, inviteePermissionLevel, disabled, itemType } =
75+
this.props;
8076
const defaultPermissionLevel = getDefaultPermissionLevel(inviteePermissions);
8177
const selectedPermissionLevel = inviteePermissionLevel || defaultPermissionLevel;
8278
const disabledTooltip =

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

+15
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ describe('features/unified-share-modal/InviteePermissionsDescription', () => {
4545
'Upload, download, preview, share, and edit',
4646
);
4747
});
48+
49+
test('should render custom description when supplied', () => {
50+
const customDescription = 'Custom description for editor';
51+
const inviteePermissionDescription = shallow(
52+
<InviteePermissionsDescription
53+
inviteePermissionLevel={EDITOR}
54+
itemType="file"
55+
description={customDescription}
56+
/>,
57+
);
58+
59+
const description = inviteePermissionDescription.find('small').text();
60+
61+
expect(description).toBe(customDescription);
62+
});
4863
});

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

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22

33
import { EDITOR, CO_OWNER, PREVIEWER, PREVIEWER_UPLOADER, VIEWER, VIEWER_UPLOADER, UPLOADER } from '../constants';
44
import InviteePermissionsLabel from '../InviteePermissionsLabel';
5+
import InviteePermissionsDescription from '../InviteePermissionsDescription';
56

67
describe('features/unified-share-modal/InviteePermissionsLabel', () => {
78
[
@@ -73,4 +74,20 @@ describe('features/unified-share-modal/InviteePermissionsLabel', () => {
7374
expect(inviteePermissionLabel).toMatchSnapshot();
7475
});
7576
});
77+
78+
test('should render custom description when supplied', () => {
79+
const inviteePermissionDescription = 'Upload, download, preview, share, and edit';
80+
81+
const inviteePermissionLabel = shallow(
82+
<InviteePermissionsLabel
83+
hasDescription
84+
inviteePermissionDescription={inviteePermissionDescription}
85+
inviteePermissionLevel={EDITOR}
86+
/>,
87+
);
88+
89+
expect(inviteePermissionLabel.find(InviteePermissionsDescription).prop('description')).toBe(
90+
inviteePermissionDescription,
91+
);
92+
});
7693
});

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

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type SuggestedCollabLookup = {
6868

6969
export type inviteePermissionType = {
7070
default: boolean,
71+
description?: string,
7172
disabled?: boolean,
7273
text: string,
7374
value: string,

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,12 @@ export const withRemoveCollaborators = () => {
10171017
getInitialData={getInitialData}
10181018
inviteePermissions={[
10191019
{ default: false, text: 'Co-owner', value: 'Co-owner' },
1020-
{ default: true, text: 'Editor', value: 'Editor' },
1020+
{
1021+
default: true,
1022+
text: 'Editor',
1023+
value: 'Editor',
1024+
description: 'Custom description: Upload, download, preview, share and edit',
1025+
},
10211026
{ default: false, text: 'Viewer Uploader', value: 'Viewer Uploader' },
10221027
{ default: false, text: 'Previewer Uploader', value: 'Previewer Uploader' },
10231028
{ default: false, text: 'Viewer', value: 'Viewer' },

0 commit comments

Comments
 (0)