Skip to content

Commit 0da4950

Browse files
author
Conrad Chan
authored
feat(usm): Provide permissionLevel to send email and copy link callbacks (#2888)
1 parent f197ff5 commit 0da4950

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import * as React from 'react';
4+
import noop from 'lodash/noop';
45
import { FormattedMessage } from 'react-intl';
56

67
import PlainButton from '../../components/plain-button';
@@ -263,7 +264,7 @@ class SharedLinkSection extends React.Component<Props, State> {
263264
onChangeSharedLinkAccessLevel,
264265
onChangeSharedLinkPermissionLevel,
265266
onSharedLinkAccessMenuOpen,
266-
onSharedLinkCopy,
267+
onSharedLinkCopy = noop,
267268
sendSharedLinkButtonProps,
268269
sharedLinkAccessMenuButtonProps,
269270
sharedLinkPermissionsMenuButtonProps,
@@ -299,7 +300,7 @@ class SharedLinkSection extends React.Component<Props, State> {
299300
className="shared-link-field-container"
300301
disabled={submitting}
301302
label=""
302-
onCopySuccess={onSharedLinkCopy}
303+
onCopySuccess={() => onSharedLinkCopy(permissionLevel)}
303304
triggerCopyOnLoad={shouldTriggerCopyOnLoad}
304305
type="url"
305306
value={url}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ class UnifiedShareForm extends React.Component<USFProps, State> {
223223
};
224224

225225
handleSendSharedLink = (data: Object) => {
226-
const { sendSharedLink, trackingProps } = this.props;
226+
const { sendSharedLink, sharedLink, trackingProps } = this.props;
227227
const { sharedLinkEmailTracking } = trackingProps;
228+
const { permissionLevel } = sharedLink;
228229
const { onSendClick } = sharedLinkEmailTracking;
229230

230231
const { emails, groupIDs } = data;
@@ -234,6 +235,7 @@ class UnifiedShareForm extends React.Component<USFProps, State> {
234235
...data,
235236
numsOfRecipients: emails.length,
236237
numOfRecipientGroups: groupIDs.length,
238+
permissionLevel,
237239
};
238240
onSendClick(params);
239241
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,20 @@ describe('features/unified-share-modal/SharedLinkSection', () => {
493493
expect(onCopyErrorMock).toBeCalledTimes(0);
494494
});
495495

496+
test('should call onSharedLinkCopy with current permission level when copy button is clicked', () => {
497+
const onSharedLinkCopy = jest.fn();
498+
const sharedLink = { url: 'http://example.com/', isNewSharedLink: false, permissionLevel: CAN_EDIT };
499+
500+
const wrapper = getWrapper({
501+
sharedLink,
502+
trackingProps: { onSharedLinkCopy },
503+
});
504+
505+
wrapper.find('TextInputWithCopyButton').prop('onCopySuccess')();
506+
507+
expect(onSharedLinkCopy).toBeCalledWith(CAN_EDIT);
508+
});
509+
496510
test('should only initiate copy when we specifically request a copy to be triggered', () => {
497511
const sharedLink = { url: '', isNewSharedLink: false };
498512
const addSharedLink = jest.fn();

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
import { ITEM_TYPE_WEBLINK, ITEM_TYPE_FOLDER } from '../../../common/constants';
44

5-
import { JUSTIFICATION_CHECKPOINT_EXTERNAL_COLLAB } from '../constants';
5+
import { CAN_EDIT, JUSTIFICATION_CHECKPOINT_EXTERNAL_COLLAB } from '../constants';
66

77
import { UnifiedShareFormBase as UnifiedShareForm } from '../UnifiedShareForm';
88

@@ -437,6 +437,34 @@ describe('features/unified-share-modal/UnifiedShareForm', () => {
437437
});
438438
});
439439

440+
describe('handleSendSharedLink()', () => {
441+
test('should call onSendClick and sendSharedLink with the correct params', async () => {
442+
const data = {
443+
emails: ['dvader@example.com', 'fbar@example.com'],
444+
groupIDs: ['eng@example.com', 'product@example.com'],
445+
};
446+
const onSendClick = jest.fn();
447+
const sendSharedLink = jest.fn();
448+
const sharedLink = { permissionLevel: CAN_EDIT };
449+
const trackingProps = {
450+
...defaultTrackingProps,
451+
sharedLinkEmailTracking: { onSendClick },
452+
};
453+
const expectedParams = {
454+
...data,
455+
numsOfRecipients: 2,
456+
numOfRecipientGroups: 2,
457+
permissionLevel: CAN_EDIT,
458+
};
459+
const wrapper = getWrapper({ sendSharedLink, sharedLink, trackingProps });
460+
461+
await wrapper.instance().handleSendSharedLink(data);
462+
463+
expect(onSendClick).toBeCalledWith(expectedParams);
464+
expect(sendSharedLink).toBeCalledWith(data);
465+
});
466+
});
467+
440468
describe('handleInviteePermissionChange()', () => {
441469
test('should set the permission in the state', () => {
442470
const onInviteePermissionChange = jest.fn();

src/features/unified-share-modal/__tests__/__snapshots__/SharedLinkSection.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ exports[`features/unified-share-modal/SharedLinkSection should account for share
9696
className="shared-link-field-container"
9797
hideOptionalLabel={true}
9898
label=""
99+
onCopySuccess={[Function]}
99100
readOnly={true}
100101
successStateDuration={3000}
101102
triggerCopyOnLoad={false}
@@ -255,6 +256,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render a default
255256
className="shared-link-field-container"
256257
hideOptionalLabel={true}
257258
label=""
259+
onCopySuccess={[Function]}
258260
readOnly={true}
259261
successStateDuration={3000}
260262
triggerCopyOnLoad={false}
@@ -448,6 +450,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render default co
448450
className="shared-link-field-container"
449451
hideOptionalLabel={true}
450452
label=""
453+
onCopySuccess={[Function]}
451454
readOnly={true}
452455
successStateDuration={3000}
453456
triggerCopyOnLoad={false}
@@ -712,6 +715,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render proper dro
712715
className="shared-link-field-container"
713716
hideOptionalLabel={true}
714717
label=""
718+
onCopySuccess={[Function]}
715719
readOnly={true}
716720
successStateDuration={3000}
717721
triggerCopyOnLoad={false}
@@ -855,6 +859,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render proper lis
855859
className="shared-link-field-container"
856860
hideOptionalLabel={true}
857861
label=""
862+
onCopySuccess={[Function]}
858863
readOnly={true}
859864
successStateDuration={3000}
860865
triggerCopyOnLoad={false}
@@ -1000,6 +1005,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render proper lis
10001005
className="shared-link-field-container"
10011006
hideOptionalLabel={true}
10021007
label=""
1008+
onCopySuccess={[Function]}
10031009
readOnly={true}
10041010
successStateDuration={3000}
10051011
triggerCopyOnLoad={false}
@@ -1144,6 +1150,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render proper lis
11441150
className="shared-link-field-container"
11451151
hideOptionalLabel={true}
11461152
label=""
1153+
onCopySuccess={[Function]}
11471154
readOnly={true}
11481155
successStateDuration={3000}
11491156
triggerCopyOnLoad={false}
@@ -1288,6 +1295,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render proper lis
12881295
className="shared-link-field-container"
12891296
hideOptionalLabel={true}
12901297
label=""
1298+
onCopySuccess={[Function]}
12911299
readOnly={true}
12921300
successStateDuration={3000}
12931301
triggerCopyOnLoad={false}
@@ -1458,6 +1466,7 @@ exports[`features/unified-share-modal/SharedLinkSection should render without Sh
14581466
className="shared-link-field-container"
14591467
hideOptionalLabel={true}
14601468
label=""
1469+
onCopySuccess={[Function]}
14611470
readOnly={true}
14621471
successStateDuration={3000}
14631472
triggerCopyOnLoad={false}

0 commit comments

Comments
 (0)