file-tree-item-menu-items.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { useTranslation } from 'react-i18next'
  2. import * as eventTracking from '../../../../infrastructure/event-tracking'
  3. import { MenuItem } from 'react-bootstrap'
  4. import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
  5. function FileTreeItemMenuItems() {
  6. const { t } = useTranslation()
  7. const {
  8. canRename,
  9. canDelete,
  10. canCreate,
  11. startRenaming,
  12. startDeleting,
  13. startCreatingFolder,
  14. startCreatingDocOrFile,
  15. startUploadingDocOrFile,
  16. downloadPath,
  17. } = useFileTreeActionable()
  18. const createWithAnalytics = () => {
  19. eventTracking.sendMB('new-file-click', { location: 'file-menu' })
  20. startCreatingDocOrFile()
  21. }
  22. const uploadWithAnalytics = () => {
  23. eventTracking.sendMB('upload-click', { location: 'file-menu' })
  24. startUploadingDocOrFile()
  25. }
  26. return (
  27. <>
  28. {canRename ? (
  29. <MenuItem onClick={startRenaming}>{t('rename')}</MenuItem>
  30. ) : null}
  31. {downloadPath ? (
  32. <MenuItem href={downloadPath} download>
  33. {t('download')}
  34. </MenuItem>
  35. ) : null}
  36. {canDelete ? (
  37. <MenuItem onClick={startDeleting}>{t('delete')}</MenuItem>
  38. ) : null}
  39. {canCreate ? (
  40. <>
  41. <MenuItem divider />
  42. <MenuItem onClick={createWithAnalytics}>{t('new_file')}</MenuItem>
  43. <MenuItem onClick={startCreatingFolder}>{t('new_folder')}</MenuItem>
  44. <MenuItem onClick={uploadWithAnalytics}>{t('upload')}</MenuItem>
  45. </>
  46. ) : null}
  47. </>
  48. )
  49. }
  50. export default FileTreeItemMenuItems