Skip to content

Commit

Permalink
feat(unified-share-modal): add custom avatars click handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tnastula committed Oct 1, 2024
1 parent c521c11 commit af4560e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/features/unified-share-modal/UnifiedShareForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,8 @@ class UnifiedShareForm extends React.Component<USFProps, State> {

onToggleSharedLink = (event: SyntheticInputEvent<HTMLInputElement>) => {
const { target } = event;
const {
handleFtuxCloseClick,
onAddLink,
openConfirmModal,
shouldRenderFTUXTooltip,
trackingProps,
} = this.props;
const { handleFtuxCloseClick, onAddLink, openConfirmModal, shouldRenderFTUXTooltip, trackingProps } =
this.props;
const { sharedLinkTracking } = trackingProps;
const { onToggleLink } = sharedLinkTracking;

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

showCollaboratorList = () => {
this.setState({ showCollaboratorList: true });
const { onCollaboratorAvatarsClick } = this.props;

if (onCollaboratorAvatarsClick) {
onCollaboratorAvatarsClick();
} else {
this.setState({ showCollaboratorList: true });
}
};

closeCollaboratorList = () => {
Expand Down
4 changes: 3 additions & 1 deletion src/features/unified-share-modal/UnifiedShareModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ class UnifiedShareModal extends React.Component<USMProps, State> {
};

renderUSF = () => {
const { sharedLinkEditTagTargetingApi, sharedLinkEditTooltipTargetingApi } = this.props;
const { onCollaboratorAvatarsClick, sharedLinkEditTagTargetingApi, sharedLinkEditTooltipTargetingApi } =
this.props;
const { isFetching, sharedLinkLoaded, shouldRenderFTUXTooltip } = this.state;

return (
<UnifiedShareForm
{...this.props}
onCollaboratorAvatarsClick={onCollaboratorAvatarsClick}
handleFtuxCloseClick={this.handleFtuxCloseClick}
isFetching={isFetching}
openConfirmModal={this.openConfirmModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,61 @@ describe('features/unified-share-modal/UnifiedShareForm', () => {
expect(wrapper).toMatchSnapshot();
});

test('should render a collaborator list when onCollaboratorAvatarsClick prop is undefined and showCollaboratorList is invoked', () => {
const collaborators = [
{
name: 'test a',
hasCustomAvatar: false,
},
{
name: 'test b',
hasCustomAvatar: false,
},
];

const wrapper = getWrapper({
collaboratorsList: {
...collaboratorsList,
collaborators,
},
onCollaboratorAvatarsClick: undefined,
});

wrapper.setState({ showCollaboratorList: false });
wrapper.instance().showCollaboratorList();

expect(wrapper.exists('CollaboratorList')).toBe(true);
});

test('should not render a collaborator list and invoke onCollaboratorAvatarsClick prop when onCollaboratorAvatarsClick prop is defined and showCollaboratorList is invoked', () => {
const collaborators = [
{
name: 'test a',
hasCustomAvatar: false,
},
{
name: 'test b',
hasCustomAvatar: false,
},
];

const onCollaboratorAvatarsClickMock = jest.fn();

const wrapper = getWrapper({
collaboratorsList: {
...collaboratorsList,
collaborators,
},
onCollaboratorAvatarsClick: onCollaboratorAvatarsClickMock,
});

wrapper.setState({ showCollaboratorList: false });
wrapper.instance().showCollaboratorList();

expect(wrapper.exists('CollaboratorList')).toBe(false);
expect(onCollaboratorAvatarsClickMock).toHaveBeenCalledTimes(1);
});

test('should render a default component with ACI toggle if enabled ', () => {
const wrapper = getWrapper({ onAdvancedContentInsightsToggle: jest.fn() });
expect(wrapper.exists('AdvancedContentInsightsToggle')).toBe(true);
Expand Down
4 changes: 4 additions & 0 deletions src/features/unified-share-modal/flowTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ export type USMProps = BaseUnifiedShareProps & {
isAllowEditSharedLinkForFileEnabled?: boolean,
/** Whether the USM is open */
isOpen?: boolean,
/** A custom action to be invoked instead of default behavior when collaborators avatars are clicked */
onCollaboratorAvatarsClick?: () => void,
/** Handler function that removes the shared link, used in the Remove Link Confirm Modal */
onRemoveLink: () => void,
/** Handler function for when the USM is closed */
Expand All @@ -397,6 +399,8 @@ export type USFProps = BaseUnifiedShareProps & {
isAllowEditSharedLinkForFileEnabled: boolean,
/** Whether the data for the USM/USF is being fetched */
isFetching: boolean,
/** A custom action to be invoked instead of default behavior when collaborators avatars are clicked */
onCollaboratorAvatarsClick?: () => void,
/** Function for opening the Remove Link Confirm Modal */
openConfirmModal: () => void,
/** Function for opening the Upgrade Plan Modal */
Expand Down

0 comments on commit af4560e

Please sign in to comment.