1 import { useMemo } from 'react';
3 import { Vr } from '@proton/atoms';
4 import { Toolbar, useActiveBreakpoint } from '@proton/components';
5 import type { SHARE_MEMBER_PERMISSIONS} from '@proton/shared/lib/drive/permissions';
6 import { getCanAdmin, getCanWrite } from '@proton/shared/lib/drive/permissions';
7 import { getDevice } from '@proton/shared/lib/helpers/browser';
9 import type { DecryptedLink } from '../../../store';
10 import { useDriveSharingFlags } from '../../../store';
11 import { useSelection } from '../../FileBrowser';
21 } from '../ToolbarButtons';
22 import ShareButtonLEGACY from '../ToolbarButtons/_legacy/ShareButtonLEGACY';
23 import ShareLinkButtonLEGACY from '../ToolbarButtons/_legacy/ShareLinkButtonLEGACY';
24 import { getSelectedItems } from '../helpers';
25 import useIsEditEnabled from '../useIsEditEnabled';
29 CreateNewFolderButton,
34 } from './ToolbarButtons';
39 items: DecryptedLink[];
40 permissions: SHARE_MEMBER_PERMISSIONS;
41 showOptionsForNoSelection?: boolean;
42 isLinkReadOnly?: boolean;
45 const DriveToolbar = ({ shareId, items, showOptionsForNoSelection = true, isLinkReadOnly, permissions }: Props) => {
46 const isDesktop = !getDevice()?.type;
47 const { viewportWidth } = useActiveBreakpoint();
48 const selectionControls = useSelection()!;
49 const isEditEnabled = useIsEditEnabled();
50 const { isSharingInviteAvailable } = useDriveSharingFlags();
52 const isEditor = useMemo(() => getCanWrite(permissions), [permissions]);
53 const isAdmin = useMemo(() => getCanAdmin(permissions), [permissions]);
55 const selectedItems = useMemo(
56 () => getSelectedItems(items, selectionControls!.selectedItemIds),
57 [items, selectionControls!.selectedItemIds]
60 const shouldShowShareButton = !isLinkReadOnly || items.length > 0;
61 const ShareButtonComponent = isSharingInviteAvailable ? ShareButton : ShareButtonLEGACY;
63 const renderSelectionActions = () => {
64 if (!selectedItems.length) {
65 if (!showOptionsForNoSelection) {
70 {isEditor && !isLinkReadOnly ? (
72 <CreateNewFolderButton />
73 {isEditEnabled && <CreateNewFileButton />}
75 {isDesktop && <UploadFolderButton />}
81 {isAdmin && shouldShowShareButton && <ShareButtonComponent shareId={shareId} />}
88 <PreviewButton selectedBrowserItems={selectedItems} />
89 <OpenInDocsButton selectedBrowserItems={selectedItems} />
90 <DownloadButton selectedBrowserItems={selectedItems} />
91 {viewportWidth['<=small'] ? (
92 <ActionsDropdown shareId={shareId} selectedLinks={selectedItems} permissions={permissions} />
97 {isSharingInviteAvailable ? (
98 <ShareLinkButton selectedLinks={selectedItems} />
100 <ShareLinkButtonLEGACY selectedLinks={selectedItems} />
105 {isEditor && !isLinkReadOnly ? (
107 <MoveToFolderButton shareId={shareId} selectedLinks={selectedItems} />
108 <RenameButton selectedLinks={selectedItems} />
111 <DetailsButton selectedBrowserItems={selectedItems} />
116 <MoveToTrashButton selectedLinks={selectedItems} />
126 <Toolbar className="py-1 px-2 toolbar--heavy toolbar--in-container">
127 <div className="gap-2 flex flex-nowrap shrink-0">{renderSelectionActions()}</div>
128 <span className="ml-auto flex flex-nowrap shrink-0">
129 {selectedItems.length > 0 && <Vr className="hidden md:flex mx-2" />}
136 export default DriveToolbar;