1 import { ContextSeparator } from '@proton/components';
2 import { isProtonDocument } from '@proton/shared/lib/helpers/mimetype';
3 import { isPreviewAvailable } from '@proton/shared/lib/helpers/preview';
5 import type { DecryptedLink } from '../../../store';
6 import type { ContextMenuProps } from '../../FileBrowser/interface';
7 import { useRenameModal } from '../../modals/RenameModal';
8 import { ItemContextMenu } from '../ContextMenu/ItemContextMenu';
9 import { DownloadButton, MoveToTrashButton, OpenInDocsButton, PreviewButton, RenameButton } from './ContextMenuButtons';
10 import { usePublicLinkOwnerInfo } from './utils/usePublicLinkOwnerInfo';
12 export function DrivePublicContextMenu({
23 }: ContextMenuProps & {
25 selectedLinks: DecryptedLink[];
26 isActiveLinkReadOnly?: boolean;
27 openPreview: (item: DecryptedLink) => void;
28 openInDocs?: (linkId: string) => void;
30 const { isCreator, isLastEditor } = usePublicLinkOwnerInfo(selectedLinks);
31 const selectedLink = selectedLinks.length > 0 ? selectedLinks[0] : undefined;
32 const isOnlyOneItem = selectedLinks.length === 1 && !!selectedLink;
33 const isOnlyOneFileItem = isOnlyOneItem && selectedLink.isFile;
34 const hasPreviewAvailable =
35 isOnlyOneFileItem && selectedLink.mimeType && isPreviewAvailable(selectedLink.mimeType, selectedLink.size);
36 const [publicRenameModal, showPublicRenameModal] = useRenameModal();
37 const isDocument = isProtonDocument(selectedLink?.mimeType || '');
39 const showPreviewButton = hasPreviewAvailable;
40 const showOpenInDocsButton = isOnlyOneFileItem && isDocument && openInDocs;
44 <ItemContextMenu isOpen={isOpen} open={open} close={close} position={position} anchorRef={anchorRef}>
45 {showPreviewButton && <PreviewButton link={selectedLink} openPreview={openPreview} close={close} />}
46 {showOpenInDocsButton && (
48 openInDocs={openInDocs}
49 linkId={selectedLink.linkId}
50 mimeType={selectedLink.mimeType}
54 {(showPreviewButton || showOpenInDocsButton) && <ContextSeparator />}
55 <DownloadButton selectedBrowserItems={selectedLinks} close={close} />
56 {isOnlyOneItem && !isActiveLinkReadOnly && isLastEditor && (
59 <RenameButton showRenameModal={showPublicRenameModal} link={selectedLink} close={close} />
63 {isCreator && isLastEditor && (
66 <MoveToTrashButton selectedLinks={selectedLinks} close={close} />