Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / drive-store / components / revisions / RevisionsItemContextMenu.tsx
blob656b53a58b470a30911c586b24d912e667cf4e86
1 import { useMemo } from 'react';
3 import { ContextSeparator } from '@proton/components';
4 import { getCanAdmin } from '@proton/shared/lib/drive/permissions';
6 import type { DriveFileRevision } from '../../store';
7 import type { ContextMenuProps } from '../FileBrowser';
8 import { ItemContextMenu } from '../sections/ContextMenu/ItemContextMenu';
9 import {
10     RevisionDeleteButton,
11     RevisionDetailsButton,
12     RevisionDownloadButton,
13     RevisionPreviewButton,
14     RevisionRestoreButton,
15 } from './ContextMenuButtons';
16 import { useRevisionsProvider } from './RevisionsProvider';
18 export function RevisionsItemContextMenu({
19     anchorRef,
20     isOpen,
21     position,
22     open,
23     close,
24     revision,
25     isCurrent,
26 }: ContextMenuProps & {
27     revision: DriveFileRevision;
28     isCurrent: boolean;
29 }) {
30     const {
31         permissions,
32         hasPreviewAvailable,
33         openRevisionPreview,
34         downloadRevision,
35         openRevisionDetails,
36         deleteRevision,
37         restoreRevision,
38     } = useRevisionsProvider();
39     const isAdmin = useMemo(() => getCanAdmin(permissions), [permissions]);
40     if (isCurrent) {
41         return (
42             <ItemContextMenu isOpen={isOpen} open={open} close={close} position={position} anchorRef={anchorRef}>
43                 {hasPreviewAvailable ? (
44                     <RevisionPreviewButton
45                         revision={revision}
46                         openRevisionPreview={openRevisionPreview}
47                         close={close}
48                     />
49                 ) : null}
50                 <RevisionDownloadButton revision={revision} downloadRevision={downloadRevision} close={close} />
51                 <RevisionDetailsButton revision={revision} openRevisionDetails={openRevisionDetails} close={close} />
52             </ItemContextMenu>
53         );
54     }
55     return (
56         <ItemContextMenu isOpen={isOpen} open={open} close={close} position={position} anchorRef={anchorRef}>
57             {hasPreviewAvailable && (
58                 <>
59                     <RevisionPreviewButton
60                         revision={revision}
61                         openRevisionPreview={openRevisionPreview}
62                         close={close}
63                     />
64                     <ContextSeparator />
65                 </>
66             )}
67             <RevisionRestoreButton restoreRevision={restoreRevision} revision={revision} close={close} />
68             <RevisionDownloadButton revision={revision} downloadRevision={downloadRevision} close={close} />
69             <ContextSeparator />
70             <RevisionDetailsButton revision={revision} openRevisionDetails={openRevisionDetails} close={close} />
72             {isAdmin && (
73                 <>
74                     <ContextSeparator />
75                     <RevisionDeleteButton deleteRevision={deleteRevision} revision={revision} close={close} />
76                 </>
77             )}
78         </ItemContextMenu>
79     );