2024-05-07 10:38:39 -04:00
|
|
|
import { useCallback } from 'react'
|
2020-11-26 09:22:30 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2023-08-22 09:33:19 -04:00
|
|
|
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
2024-04-23 12:49:11 -04:00
|
|
|
import { useProjectContext } from '@/shared/context/project-context'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
import { MenuItem } from 'react-bootstrap'
|
2024-09-25 09:46:02 -04:00
|
|
|
import {
|
|
|
|
DropdownDivider,
|
|
|
|
DropdownItem,
|
|
|
|
} from '@/features/ui/components/bootstrap-5/dropdown-menu'
|
2020-11-26 09:22:30 -05:00
|
|
|
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
2024-09-25 09:46:02 -04:00
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeItemMenuItems() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const {
|
|
|
|
canRename,
|
|
|
|
canDelete,
|
|
|
|
canCreate,
|
|
|
|
startRenaming,
|
|
|
|
startDeleting,
|
|
|
|
startCreatingFolder,
|
|
|
|
startCreatingDocOrFile,
|
2021-04-27 03:52:58 -04:00
|
|
|
startUploadingDocOrFile,
|
2022-08-12 05:54:32 -04:00
|
|
|
downloadPath,
|
2024-05-07 10:38:39 -04:00
|
|
|
selectedFileName,
|
2020-11-26 09:22:30 -05:00
|
|
|
} = useFileTreeActionable()
|
|
|
|
|
2024-04-23 12:49:11 -04:00
|
|
|
const { owner } = useProjectContext()
|
|
|
|
|
|
|
|
const downloadWithAnalytics = useCallback(() => {
|
|
|
|
// we are only interested in downloads of bib files WRT analytics, for the purposes of promoting the tpr integrations
|
|
|
|
if (selectedFileName?.endsWith('.bib')) {
|
|
|
|
eventTracking.sendMB('download-bib-file', { projectOwner: owner._id })
|
|
|
|
}
|
|
|
|
}, [selectedFileName, owner])
|
|
|
|
|
|
|
|
const createWithAnalytics = useCallback(() => {
|
2023-08-22 09:33:19 -04:00
|
|
|
eventTracking.sendMB('new-file-click', { location: 'file-menu' })
|
|
|
|
startCreatingDocOrFile()
|
2024-04-23 12:49:11 -04:00
|
|
|
}, [startCreatingDocOrFile])
|
2023-08-22 09:33:19 -04:00
|
|
|
|
2024-04-23 12:49:11 -04:00
|
|
|
const uploadWithAnalytics = useCallback(() => {
|
2023-08-22 09:33:19 -04:00
|
|
|
eventTracking.sendMB('upload-click', { location: 'file-menu' })
|
|
|
|
startUploadingDocOrFile()
|
2024-04-23 12:49:11 -04:00
|
|
|
}, [startUploadingDocOrFile])
|
2023-08-22 09:33:19 -04:00
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
return (
|
2024-09-25 09:46:02 -04:00
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={
|
2020-11-26 09:22:30 -05:00
|
|
|
<>
|
2024-09-25 09:46:02 -04:00
|
|
|
{canRename ? (
|
|
|
|
<MenuItem onClick={startRenaming}>{t('rename')}</MenuItem>
|
|
|
|
) : null}
|
|
|
|
{downloadPath ? (
|
|
|
|
<MenuItem
|
|
|
|
href={downloadPath}
|
|
|
|
onClick={downloadWithAnalytics}
|
|
|
|
download={selectedFileName}
|
|
|
|
>
|
|
|
|
{t('download')}
|
|
|
|
</MenuItem>
|
|
|
|
) : null}
|
|
|
|
{canDelete ? (
|
|
|
|
<MenuItem onClick={startDeleting}>{t('delete')}</MenuItem>
|
|
|
|
) : null}
|
|
|
|
{canCreate ? (
|
|
|
|
<>
|
|
|
|
<li role="none" className="divider" />
|
|
|
|
<MenuItem onClick={createWithAnalytics}>{t('new_file')}</MenuItem>
|
|
|
|
<MenuItem onClick={startCreatingFolder}>
|
|
|
|
{t('new_folder')}
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onClick={uploadWithAnalytics}>{t('upload')}</MenuItem>
|
|
|
|
</>
|
|
|
|
) : null}
|
2020-11-26 09:22:30 -05:00
|
|
|
</>
|
2024-09-25 09:46:02 -04:00
|
|
|
}
|
|
|
|
bs5={
|
|
|
|
<>
|
|
|
|
{canRename ? (
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem onClick={startRenaming}>{t('rename')}</DropdownItem>
|
|
|
|
</li>
|
|
|
|
) : null}
|
|
|
|
{downloadPath ? (
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem
|
|
|
|
href={downloadPath}
|
|
|
|
onClick={downloadWithAnalytics}
|
|
|
|
download={selectedFileName}
|
|
|
|
>
|
|
|
|
{t('download')}
|
|
|
|
</DropdownItem>
|
|
|
|
</li>
|
|
|
|
) : null}
|
|
|
|
{canDelete ? (
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem onClick={startDeleting}>{t('delete')}</DropdownItem>
|
|
|
|
</li>
|
|
|
|
) : null}
|
|
|
|
{canCreate ? (
|
|
|
|
<>
|
|
|
|
<DropdownDivider role="none" />
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem onClick={createWithAnalytics}>
|
|
|
|
{t('new_file')}
|
|
|
|
</DropdownItem>
|
|
|
|
</li>
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem onClick={startCreatingFolder}>
|
|
|
|
{t('new_folder')}
|
|
|
|
</DropdownItem>
|
|
|
|
</li>
|
|
|
|
<li role="none">
|
|
|
|
<DropdownItem onClick={uploadWithAnalytics}>
|
|
|
|
{t('upload')}
|
|
|
|
</DropdownItem>
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeItemMenuItems
|