Skip to content

Commit

Permalink
DRYDOCK-367: content share changes for crooze
Browse files Browse the repository at this point in the history
  • Loading branch information
arudzko committed Oct 31, 2024
1 parent 0427112 commit 47dc484
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 83 deletions.
Binary file added box-ui-elements-v0.0.0-semantically-released.tgz
Binary file not shown.
3 changes: 3 additions & 0 deletions src/components/guide-tooltip/GuideTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Props = TooltipProps & {
steps?: [number, number];
primaryButtonProps?: JSX.LibraryManagedAttributes<typeof Button, Button['props']>;
secondaryButtonProps?: JSX.LibraryManagedAttributes<typeof Button, Button['props']>;
container?: HTMLElement;
};

function GuideTooltip({
Expand All @@ -36,6 +37,7 @@ function GuideTooltip({
secondaryButtonProps,
showCloseButton = true,
title,
container,
...rest
}: Props) {
return (
Expand All @@ -44,6 +46,7 @@ function GuideTooltip({
className={`bdl-GuideTooltip ${className}`}
isShown={isShown}
showCloseButton={showCloseButton}
bodyElement={container}
text={
<>
{icon && <div className="bdl-GuideTooltip-icon">{icon}</div>}
Expand Down
11 changes: 9 additions & 2 deletions src/components/modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
children: React.Node,
/** Additional CSS classname of the `.modal` element */
className?: string,
container?: HTMLElement,
focusElementSelector?: string,
isLoading?: boolean,
isOpen?: boolean,
Expand Down Expand Up @@ -130,7 +131,8 @@ class Modal extends React.Component<Props> {
};

render() {
const { className, isLoading, isOpen, onRequestClose, shouldNotUsePortal, style, ...rest } = this.props;
const { className, isLoading, isOpen, onRequestClose, shouldNotUsePortal, style, container, ...rest } =
this.props;

if (!isOpen) {
return null;
Expand All @@ -148,7 +150,12 @@ class Modal extends React.Component<Props> {
const WrapperComponent = shouldNotUsePortal ? 'div' : Portal;
// Render a style tag to prevent body from scrolling as long as the Modal is open
return (
<WrapperComponent className={classNames('modal', className)} onKeyDown={this.onKeyDown} tabIndex="-1">
<WrapperComponent
className={classNames('modal', className)}
onKeyDown={this.onKeyDown}
tabIndex="-1"
container={container}
>
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}
<div className="modal-backdrop" onClick={this.onBackdropClick} style={style.backdrop} />
<FocusTrap className="modal-dialog-container">
Expand Down
5 changes: 3 additions & 2 deletions src/components/notification/NotificationsWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import Portal from '../portal';

type Props = {
children?: React.Node,
container?: HTMLElement,
};

const NotificationsWrapper = ({ children }: Props) => (
<Portal className="notifications-wrapper" aria-live="polite">
const NotificationsWrapper = ({ children, container }: Props) => (
<Portal className="notifications-wrapper" aria-live="polite" container={container}>
{children ? <FocusTrap>{children}</FocusTrap> : null}
</Portal>
);
Expand Down
6 changes: 6 additions & 0 deletions src/elements/content-sharing/ContentSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ContentSharingProps = {
apiHost: string,
/** config - Configuration object that shows/hides features in the USM */
config?: USMConfig,
container?: HTMLElement,
/**
* customButton - Clickable element for opening the SharingModal component.
* This property should always be used in conjunction with displayInModal.
Expand All @@ -35,6 +36,7 @@ type ContentSharingProps = {
* the modal will appear on page load. See ContentSharing.stories.js for examples.
*/
displayInModal: boolean,
dropdownMenuClassname?: string,
/** itemID - Box file or folder ID */
itemID: string,
/** itemType - "file" or "folder" */
Expand Down Expand Up @@ -68,6 +70,8 @@ function ContentSharing({
messages,
token,
uuid,
container,
dropdownMenuClassname,
}: ContentSharingProps) {
const [api, setAPI] = React.useState<API | null>(createAPI(apiHost, itemID, itemType, token));
const [launchButton, setLaunchButton] = React.useState<React.Element<any> | null>(null);
Expand Down Expand Up @@ -112,6 +116,8 @@ function ContentSharing({
messages={messages}
setIsVisible={setIsVisible}
uuid={uuid}
container={container}
dropdownMenuClassname={dropdownMenuClassname}
/>
)}
</>
Expand Down
20 changes: 12 additions & 8 deletions src/elements/content-sharing/SharingModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import type {
type SharingModalProps = {
api: API,
config?: USMConfig,
container?: HTMLElement,
displayInModal: boolean,
dropdownMenuClassname?: string,
isVisible: boolean,
itemID: string,
itemType: ItemType,
Expand All @@ -70,6 +72,8 @@ function SharingModal({
messages,
setIsVisible,
uuid,
container,
dropdownMenuClassname,
}: SharingModalProps) {
const [item, setItem] = React.useState<itemFlowType | null>(null);
const [sharedLink, setSharedLink] = React.useState<ContentSharingSharedLinkType | null>(null);
Expand All @@ -80,14 +84,10 @@ function SharingModal({
const [collaboratorsList, setCollaboratorsList] = React.useState<collaboratorsListType | null>(null);
const [onAddLink, setOnAddLink] = React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [onRemoveLink, setOnRemoveLink] = React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [
changeSharedLinkAccessLevel,
setChangeSharedLinkAccessLevel,
] = React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [
changeSharedLinkPermissionLevel,
setChangeSharedLinkPermissionLevel,
] = React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [changeSharedLinkAccessLevel, setChangeSharedLinkAccessLevel] =
React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [changeSharedLinkPermissionLevel, setChangeSharedLinkPermissionLevel] =
React.useState<null | SharedLinkUpdateLevelFnType>(null);
const [onSubmitSettings, setOnSubmitSettings] = React.useState<null | SharedLinkUpdateSettingsFnType>(null);
const [currentView, setCurrentView] = React.useState<string>(CONTENT_SHARING_VIEWS.UNIFIED_SHARE_MODAL);
const [getContacts, setGetContacts] = React.useState<null | GetContactsFnType>(null);
Expand Down Expand Up @@ -263,6 +263,7 @@ function SharingModal({
setOnSubmitSettings={setOnSubmitSettings}
setSendInvites={setSendInvites}
setSharedLink={setSharedLink}
container={container}
/>
{isVisible && currentView === CONTENT_SHARING_VIEWS.SHARED_LINK_SETTINGS && (
<SharedLinkSettingsModal
Expand All @@ -276,10 +277,12 @@ function SharingModal({
submitting={isLoading}
{...sharedLink}
canChangeExpiration={canChangeExpiration && !!currentUserEnterpriseName}
container={container}
/>
)}
{isVisible && currentView === CONTENT_SHARING_VIEWS.UNIFIED_SHARE_MODAL && (
<UnifiedShareModal
dropdownMenuClassname={dropdownMenuClassname}
canInvite={sharedLink.canInvite}
config={config}
changeSharedLinkAccessLevel={changeSharedLinkAccessLevel}
Expand All @@ -305,6 +308,7 @@ function SharingModal({
expirationTimestamp: expirationTimestamp ? expirationTimestamp / 1000 : null,
}} // the USM expects this value in seconds, while the SLSM expects this value in milliseconds
submitting={isLoading}
container={container}
/>
)}
</>
Expand Down
71 changes: 34 additions & 37 deletions src/elements/content-sharing/SharingNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type SharingNotificationProps = {
closeComponent: () => void,
closeSettings: () => void,
collaboratorsList: collaboratorsListType | null,
container?: HTMLElement,
currentUserID: string | null,
getContacts: GetContactsFnType | null,
isDownloadAvailable: boolean,
Expand Down Expand Up @@ -97,6 +98,7 @@ function SharingNotification({
setOnSubmitSettings,
setSendInvites,
setSharedLink,
container,
}: SharingNotificationProps) {
const [notifications, setNotifications] = React.useState<{ [string]: typeof Notification }>({});
const [notificationID, setNotificationID] = React.useState<number>(0);
Expand Down Expand Up @@ -170,42 +172,37 @@ function SharingNotification({
};

// Generate shared link CRUD functions for the item
const {
changeSharedLinkAccessLevel,
changeSharedLinkPermissionLevel,
onAddLink,
onRemoveLink,
onSubmitSettings,
} = useSharedLink(api, itemID, itemType, permissions, accessLevel, {
handleUpdateSharedLinkError: () => {
createNotification(TYPE_ERROR, contentSharingMessages.sharedLinkUpdateError);
setIsLoading(false);
closeSettings();
},
handleUpdateSharedLinkSuccess: itemData => {
createNotification(TYPE_INFO, contentSharingMessages.sharedLinkSettingsUpdateSuccess);
handleUpdateSharedLinkSuccess(itemData);
setIsLoading(false);
closeSettings();
},
handleRemoveSharedLinkError: () => {
createNotification(TYPE_ERROR, contentSharingMessages.sharedLinkUpdateError);
setIsLoading(false);
closeComponent(); // if this function is provided, it will close the modal
},
handleRemoveSharedLinkSuccess: itemData => {
createNotification(TYPE_INFO, contentSharingMessages.sharedLinkRemovalSuccess);
handleRemoveSharedLinkSuccess(itemData);
setIsLoading(false);
closeComponent();
},
setIsLoading,
transformAccess: newAccessLevel => USM_TO_API_ACCESS_LEVEL_MAP[newAccessLevel],
transformPermissions: newSharedLinkPermissionLevel =>
convertSharedLinkPermissions(newSharedLinkPermissionLevel),
transformSettings: (settings, access) =>
convertSharedLinkSettings(settings, access, isDownloadAvailable, serverURL),
});
const { changeSharedLinkAccessLevel, changeSharedLinkPermissionLevel, onAddLink, onRemoveLink, onSubmitSettings } =
useSharedLink(api, itemID, itemType, permissions, accessLevel, {
handleUpdateSharedLinkError: () => {
createNotification(TYPE_ERROR, contentSharingMessages.sharedLinkUpdateError);
setIsLoading(false);
closeSettings();
},
handleUpdateSharedLinkSuccess: itemData => {
createNotification(TYPE_INFO, contentSharingMessages.sharedLinkSettingsUpdateSuccess);
handleUpdateSharedLinkSuccess(itemData);
setIsLoading(false);
closeSettings();
},
handleRemoveSharedLinkError: () => {
createNotification(TYPE_ERROR, contentSharingMessages.sharedLinkUpdateError);
setIsLoading(false);
closeComponent(); // if this function is provided, it will close the modal
},
handleRemoveSharedLinkSuccess: itemData => {
createNotification(TYPE_INFO, contentSharingMessages.sharedLinkRemovalSuccess);
handleRemoveSharedLinkSuccess(itemData);
setIsLoading(false);
closeComponent();
},
setIsLoading,
transformAccess: newAccessLevel => USM_TO_API_ACCESS_LEVEL_MAP[newAccessLevel],
transformPermissions: newSharedLinkPermissionLevel =>
convertSharedLinkPermissions(newSharedLinkPermissionLevel),
transformSettings: (settings, access) =>
convertSharedLinkSettings(settings, access, isDownloadAvailable, serverURL),
});

setChangeSharedLinkAccessLevel(() => changeSharedLinkAccessLevel);
setChangeSharedLinkPermissionLevel(() => changeSharedLinkPermissionLevel);
Expand Down Expand Up @@ -267,7 +264,7 @@ function SharingNotification({
}

return (
<NotificationsWrapper>
<NotificationsWrapper container={container}>
<>{[...Object.values(notifications)]}</>
</NotificationsWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/content-uploader/Footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

.bcu-footer-right {
display: flex;
gap: tokens.$size-2;
// gap: tokens.$size-2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SharedLinkSettingsModal extends Component {
dateFormat: PropTypes.string,
hideVanityNameSection: PropTypes.bool,
isOpen: PropTypes.bool,
container: PropTypes.element,
onRequestClose: PropTypes.func,
submitting: PropTypes.bool,
warnOnPublic: PropTypes.bool,
Expand Down Expand Up @@ -293,13 +294,8 @@ class SharedLinkSettingsModal extends Component {
}

renderExpirationSection() {
const {
canChangeExpiration,
dateDisplayFormat,
dateFormat,
expirationCheckboxProps,
expirationInputProps,
} = this.props;
const { canChangeExpiration, dateDisplayFormat, dateFormat, expirationCheckboxProps, expirationInputProps } =
this.props;
const { expirationDate, isExpirationEnabled, expirationError } = this.state;

return (
Expand Down Expand Up @@ -404,6 +400,7 @@ class SharedLinkSettingsModal extends Component {
onRequestClose,
saveButtonProps,
submitting,
container,
} = this.props;

const showInaccessibleSettingsNotice = !(
Expand All @@ -420,6 +417,7 @@ class SharedLinkSettingsModal extends Component {
isOpen={isOpen}
onRequestClose={submitting ? undefined : onRequestClose}
title={this.renderModalTitle()}
container={container}
{...modalProps}
>
<form onSubmit={this.onSubmit}>
Expand Down
4 changes: 3 additions & 1 deletion src/features/unified-share-modal/InviteePermissionsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { inviteePermissionType } from './flowTypes';
type Props = {
changeInviteePermissionLevel: Function,
disabled: boolean,
dropdownMenuClassname?: string,
inviteePermissionLevel: string,
inviteePermissions: Array<inviteePermissionType>,
inviteePermissionsButtonProps?: Object,
Expand Down Expand Up @@ -76,6 +77,7 @@ class InviteePermissionsMenu extends Component<Props> {
inviteePermissionLevel,
disabled,
itemType,
dropdownMenuClassname,
} = this.props;
const defaultPermissionLevel = getDefaultPermissionLevel(inviteePermissions);
const selectedPermissionLevel = inviteePermissionLevel || defaultPermissionLevel;
Expand Down Expand Up @@ -121,7 +123,7 @@ class InviteePermissionsMenu extends Component<Props> {
// the available vertical space. cannot use the constraint props here in short windows.
return (
<div className="be invitee-menu-wrap">
<DropdownMenu>
<DropdownMenu className={dropdownMenuClassname}>
{plainButtonWrap}
{this.renderMenu()}
</DropdownMenu>
Expand Down
3 changes: 3 additions & 0 deletions src/features/unified-share-modal/RemoveLinkConfirmModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import messages from './messages';

type Props = {
cancelButtonProps?: Object,
container?: HTMLElement,
isOpen: boolean,
modalProps?: Object,
okayButtonProps?: Object,
Expand Down Expand Up @@ -38,6 +39,7 @@ class RemoveLinkConfirmModal extends Component<Props> {
okayButtonProps,
modalProps,
cancelButtonProps,
container,
} = this.props;

return (
Expand All @@ -48,6 +50,7 @@ class RemoveLinkConfirmModal extends Component<Props> {
onRequestClose={submitting ? undefined : onRequestClose}
title={<FormattedMessage {...messages.removeLinkConfirmationTitle} />}
type="alert"
container={container}
{...modalProps}
>
<FormattedMessage {...messages.removeLinkConfirmationDescription} />
Expand Down
8 changes: 7 additions & 1 deletion src/features/unified-share-modal/SharedLinkAccessMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Props = {
accessLevelsDisabledReason: accessLevelsDisabledReasonType,
allowedAccessLevels: allowedAccessLevelsType,
changeAccessLevel: (newAccessLevel: accessLevelType) => Promise<{ accessLevel: accessLevelType }>,
dropdownMenuClassname?: string,
enterpriseName?: string,
itemType: ItemType,
onDismissTooltip: () => void,
Expand Down Expand Up @@ -117,6 +118,7 @@ class SharedLinkAccessMenu extends React.Component<Props> {
submitting,
tooltipContent,
trackingProps,
dropdownMenuClassname,
} = this.props;
const { onSharedLinkAccessMenuOpen, sharedLinkAccessMenuButtonProps } = trackingProps;

Expand All @@ -130,7 +132,11 @@ class SharedLinkAccessMenu extends React.Component<Props> {
text={tooltipContent}
theme="callout"
>
<DropdownMenu onMenuOpen={onSharedLinkAccessMenuOpen} constrainToWindow>
<DropdownMenu
onMenuOpen={onSharedLinkAccessMenuOpen}
constrainToWindow
className={dropdownMenuClassname}
>
<PlainButton
className={classNames('lnk', {
'is-disabled': submitting,
Expand Down
Loading

0 comments on commit 47dc484

Please sign in to comment.