Skip to content

Commit c034de4

Browse files
authored
feat(unified-share-modal): add custom avatars click handler (#3688)
1 parent 6ad083b commit c034de4

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,8 @@ class UnifiedShareForm extends React.Component<USFProps, State> {
150150

151151
onToggleSharedLink = (event: SyntheticInputEvent<HTMLInputElement>) => {
152152
const { target } = event;
153-
const {
154-
handleFtuxCloseClick,
155-
onAddLink,
156-
openConfirmModal,
157-
shouldRenderFTUXTooltip,
158-
trackingProps,
159-
} = this.props;
153+
const { handleFtuxCloseClick, onAddLink, openConfirmModal, shouldRenderFTUXTooltip, trackingProps } =
154+
this.props;
160155
const { sharedLinkTracking } = trackingProps;
161156
const { onToggleLink } = sharedLinkTracking;
162157

@@ -178,7 +173,13 @@ class UnifiedShareForm extends React.Component<USFProps, State> {
178173
};
179174

180175
showCollaboratorList = () => {
181-
this.setState({ showCollaboratorList: true });
176+
const { onCollaboratorAvatarsClick } = this.props;
177+
178+
if (onCollaboratorAvatarsClick) {
179+
onCollaboratorAvatarsClick();
180+
} else {
181+
this.setState({ showCollaboratorList: true });
182+
}
182183
};
183184

184185
closeCollaboratorList = () => {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ class UnifiedShareModal extends React.Component<USMProps, State> {
137137
};
138138

139139
renderUSF = () => {
140-
const { sharedLinkEditTagTargetingApi, sharedLinkEditTooltipTargetingApi } = this.props;
140+
const { onCollaboratorAvatarsClick, sharedLinkEditTagTargetingApi, sharedLinkEditTooltipTargetingApi } =
141+
this.props;
141142
const { isFetching, sharedLinkLoaded, shouldRenderFTUXTooltip } = this.state;
142143

143144
return (
144145
<UnifiedShareForm
145146
{...this.props}
147+
onCollaboratorAvatarsClick={onCollaboratorAvatarsClick}
146148
handleFtuxCloseClick={this.handleFtuxCloseClick}
147149
isFetching={isFetching}
148150
openConfirmModal={this.openConfirmModal}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,61 @@ describe('features/unified-share-modal/UnifiedShareForm', () => {
312312
expect(wrapper).toMatchSnapshot();
313313
});
314314

315+
test('should render a collaborator list when onCollaboratorAvatarsClick prop is undefined and showCollaboratorList is invoked', () => {
316+
const collaborators = [
317+
{
318+
name: 'test a',
319+
hasCustomAvatar: false,
320+
},
321+
{
322+
name: 'test b',
323+
hasCustomAvatar: false,
324+
},
325+
];
326+
327+
const wrapper = getWrapper({
328+
collaboratorsList: {
329+
...collaboratorsList,
330+
collaborators,
331+
},
332+
onCollaboratorAvatarsClick: undefined,
333+
});
334+
335+
wrapper.setState({ showCollaboratorList: false });
336+
wrapper.instance().showCollaboratorList();
337+
338+
expect(wrapper.exists('CollaboratorList')).toBe(true);
339+
});
340+
341+
test('should not render a collaborator list and invoke onCollaboratorAvatarsClick prop when onCollaboratorAvatarsClick prop is defined and showCollaboratorList is invoked', () => {
342+
const collaborators = [
343+
{
344+
name: 'test a',
345+
hasCustomAvatar: false,
346+
},
347+
{
348+
name: 'test b',
349+
hasCustomAvatar: false,
350+
},
351+
];
352+
353+
const onCollaboratorAvatarsClickMock = jest.fn();
354+
355+
const wrapper = getWrapper({
356+
collaboratorsList: {
357+
...collaboratorsList,
358+
collaborators,
359+
},
360+
onCollaboratorAvatarsClick: onCollaboratorAvatarsClickMock,
361+
});
362+
363+
wrapper.setState({ showCollaboratorList: false });
364+
wrapper.instance().showCollaboratorList();
365+
366+
expect(wrapper.exists('CollaboratorList')).toBe(false);
367+
expect(onCollaboratorAvatarsClickMock).toHaveBeenCalledTimes(1);
368+
});
369+
315370
test('should render a default component with ACI toggle if enabled ', () => {
316371
const wrapper = getWrapper({ onAdvancedContentInsightsToggle: jest.fn() });
317372
expect(wrapper.exists('AdvancedContentInsightsToggle')).toBe(true);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ export type USMProps = BaseUnifiedShareProps & {
379379
isAllowEditSharedLinkForFileEnabled?: boolean,
380380
/** Whether the USM is open */
381381
isOpen?: boolean,
382+
/** A custom action to be invoked instead of default behavior when collaborators avatars are clicked */
383+
onCollaboratorAvatarsClick?: () => void,
382384
/** Handler function that removes the shared link, used in the Remove Link Confirm Modal */
383385
onRemoveLink: () => void,
384386
/** Handler function for when the USM is closed */
@@ -397,6 +399,8 @@ export type USFProps = BaseUnifiedShareProps & {
397399
isAllowEditSharedLinkForFileEnabled: boolean,
398400
/** Whether the data for the USM/USF is being fetched */
399401
isFetching: boolean,
402+
/** A custom action to be invoked instead of default behavior when collaborators avatars are clicked */
403+
onCollaboratorAvatarsClick?: () => void,
400404
/** Function for opening the Remove Link Confirm Modal */
401405
openConfirmModal: () => void,
402406
/** Function for opening the Upgrade Plan Modal */

0 commit comments

Comments
 (0)