1 import { useMemo } from 'react';
3 import { ContextSeparator } from '@proton/components';
4 import type { SHARE_MEMBER_PERMISSIONS} from '@proton/shared/lib/drive/permissions';
5 import { getCanAdmin, getCanWrite } from '@proton/shared/lib/drive/permissions';
6 import { isPreviewAvailable } from '@proton/shared/lib/helpers/preview';
8 import type { DecryptedLink } from '../../../store';
9 import { useDriveSharingFlags } from '../../../store';
10 import { useOpenInDocs } from '../../../store/_documents';
11 import type { ContextMenuProps } from '../../FileBrowser/interface';
12 import { useDetailsModal } from '../../modals/DetailsModal';
13 import { useFilesDetailsModal } from '../../modals/FilesDetailsModal';
14 import { useMoveToFolderModal } from '../../modals/MoveToFolderModal/MoveToFolderModal';
15 import { useRenameModal } from '../../modals/RenameModal';
16 import { useRevisionsModal } from '../../modals/RevisionsModal/RevisionsModal';
17 import { useLinkSharingModal } from '../../modals/ShareLinkModal/ShareLinkModal';
27 } from '../ContextMenu';
28 import { ItemContextMenu } from '../ContextMenu/ItemContextMenu';
29 import ShareLinkButtonLEGACY from '../ContextMenu/buttons/_legacy/ShareLinkButtonLEGACY';
30 import { MoveToFolderButton, MoveToTrashButton } from './ContextMenuButtons';
32 export function DriveItemContextMenu({
43 }: ContextMenuProps & {
44 permissions: SHARE_MEMBER_PERMISSIONS;
46 selectedLinks: DecryptedLink[];
47 isActiveLinkReadOnly?: boolean;
49 const selectedLink = selectedLinks.length > 0 ? selectedLinks[0] : undefined;
50 const isOnlyOneItem = selectedLinks.length === 1 && !!selectedLink;
51 const isOnlyOneFileItem = isOnlyOneItem && selectedLink.isFile;
53 const isEditor = useMemo(() => getCanWrite(permissions), [permissions]);
54 const isAdmin = useMemo(() => getCanAdmin(permissions), [permissions]);
56 const hasPreviewAvailable =
57 isOnlyOneFileItem && selectedLink.mimeType && isPreviewAvailable(selectedLink.mimeType, selectedLink.size);
58 const hasLink = isOnlyOneItem && selectedLink.shareUrl && !selectedLink.shareUrl.isExpired && !selectedLink.trashed;
59 const [detailsModal, showDetailsModal] = useDetailsModal();
60 const [filesDetailsModal, showFilesDetailsModal] = useFilesDetailsModal();
61 const [moveToFolderModal, showMoveToFolderModal] = useMoveToFolderModal();
62 const [renameModal, showRenameModal] = useRenameModal();
63 const [linkSharingModal, showLinkSharingModal] = useLinkSharingModal();
65 const [revisionsModal, showRevisionsModal] = useRevisionsModal();
66 const { isSharingInviteAvailable } = useDriveSharingFlags();
68 const { showOpenInDocs } = useOpenInDocs(selectedLink);
70 const ShareLinkButtonComponent = isSharingInviteAvailable ? ShareLinkButton : ShareLinkButtonLEGACY;
74 <ItemContextMenu isOpen={isOpen} open={open} close={close} position={position} anchorRef={anchorRef}>
75 {hasPreviewAvailable && (
76 <PreviewButton shareId={selectedLink.rootShareId} linkId={selectedLink.linkId} close={close} />
78 {isOnlyOneFileItem && showOpenInDocs && (
79 <OpenInDocsButton selectedBrowserItem={selectedLink} close={close} />
81 {(hasPreviewAvailable || (isOnlyOneFileItem && showOpenInDocs)) && <ContextSeparator />}
82 <DownloadButton selectedBrowserItems={selectedLinks} close={close} />
83 {isAdmin && hasLink && (
84 <CopyLinkButton shareId={selectedLink.rootShareId} linkId={selectedLink.linkId} close={close} />
86 {isAdmin && isOnlyOneItem && (
87 <ShareLinkButtonComponent
89 showLinkSharingModal={showLinkSharingModal}
95 {isEditor && !isActiveLinkReadOnly ? (
98 selectedLinks={selectedLinks}
99 showMoveToFolderModal={showMoveToFolderModal}
103 {isEditor && isOnlyOneItem && !isActiveLinkReadOnly && (
104 <RenameButton showRenameModal={showRenameModal} link={selectedLink} close={close} />
107 selectedBrowserItems={selectedLinks}
108 showDetailsModal={showDetailsModal}
109 showFilesDetailsModal={showFilesDetailsModal}
112 {isEditor && <ContextSeparator />}
113 {isEditor && isOnlyOneFileItem && (
116 selectedLink={selectedLink}
117 showRevisionsModal={showRevisionsModal}
123 {isEditor && <MoveToTrashButton selectedLinks={selectedLinks} close={close} />}