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'
|
2020-11-26 09:22:30 -05:00
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import { useFileTreeActionable } from '../contexts/file-tree-actionable'
|
2024-08-22 11:00:07 -04:00
|
|
|
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
2024-09-25 09:46:17 -04:00
|
|
|
import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
|
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
import OLButtonToolbar from '@/features/ui/components/ol/ol-button-toolbar'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
function FileTreeToolbar() {
|
2024-08-22 11:00:07 -04:00
|
|
|
const { fileTreeReadOnly } = useFileTreeData()
|
2024-09-25 09:46:17 -04:00
|
|
|
const { t } = useTranslation()
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2024-08-22 11:00:07 -04:00
|
|
|
if (fileTreeReadOnly) return null
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
return (
|
2024-09-25 09:46:17 -04:00
|
|
|
<OLButtonToolbar
|
|
|
|
className="toolbar toolbar-filetree"
|
|
|
|
aria-label={t('project_files')}
|
|
|
|
>
|
2020-11-26 09:22:30 -05:00
|
|
|
<FileTreeToolbarLeft />
|
|
|
|
<FileTreeToolbarRight />
|
2024-09-25 09:46:17 -04:00
|
|
|
</OLButtonToolbar>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileTreeToolbarLeft() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
canCreate,
|
|
|
|
startCreatingFolder,
|
|
|
|
startCreatingDocOrFile,
|
2021-04-27 03:52:58 -04:00
|
|
|
startUploadingDocOrFile,
|
2020-11-26 09:22:30 -05:00
|
|
|
} = useFileTreeActionable()
|
|
|
|
|
2023-08-22 09:33:19 -04:00
|
|
|
const createWithAnalytics = () => {
|
|
|
|
eventTracking.sendMB('new-file-click', { location: 'toolbar' })
|
|
|
|
startCreatingDocOrFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
const uploadWithAnalytics = () => {
|
|
|
|
eventTracking.sendMB('upload-click', { location: 'toolbar' })
|
|
|
|
startUploadingDocOrFile()
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
if (!canCreate) return null
|
|
|
|
|
|
|
|
return (
|
2021-03-18 05:52:36 -04:00
|
|
|
<div className="toolbar-left">
|
2024-09-25 09:46:17 -04:00
|
|
|
<OLTooltip
|
2022-05-18 09:46:10 -04:00
|
|
|
id="new-file"
|
2020-11-26 09:22:30 -05:00
|
|
|
description={t('new_file')}
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:17 -04:00
|
|
|
<button className="btn" onClick={createWithAnalytics}>
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs5={
|
|
|
|
<MaterialIcon
|
|
|
|
type="description"
|
|
|
|
accessibilityLabel={t('new_file')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
bs3={<Icon type="file" fw accessibilityLabel={t('new_file')} />}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</OLTooltip>
|
|
|
|
<OLTooltip
|
2022-05-18 09:46:10 -04:00
|
|
|
id="new-folder"
|
2020-11-26 09:22:30 -05:00
|
|
|
description={t('new_folder')}
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:17 -04:00
|
|
|
<button className="btn" onClick={startCreatingFolder} tabIndex={-1}>
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs5={
|
|
|
|
<MaterialIcon
|
|
|
|
type="folder"
|
|
|
|
accessibilityLabel={t('new_folder')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
bs3={<Icon type="folder" fw accessibilityLabel={t('new_folder')} />}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</OLTooltip>
|
|
|
|
<OLTooltip
|
2020-11-26 09:22:30 -05:00
|
|
|
id="upload"
|
|
|
|
description={t('upload')}
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:17 -04:00
|
|
|
<button className="btn" onClick={uploadWithAnalytics} tabIndex={-1}>
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs5={
|
|
|
|
<MaterialIcon type="upload" accessibilityLabel={t('upload')} />
|
|
|
|
}
|
|
|
|
bs3={<Icon type="upload" fw accessibilityLabel={t('upload')} />}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</OLTooltip>
|
2021-03-18 05:52:36 -04:00
|
|
|
</div>
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileTreeToolbarRight() {
|
|
|
|
const { t } = useTranslation()
|
2022-01-10 05:23:05 -05:00
|
|
|
const { canRename, canDelete, startRenaming, startDeleting } =
|
|
|
|
useFileTreeActionable()
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-01-07 09:23:02 -05:00
|
|
|
if (!canRename && !canDelete) {
|
2021-02-09 04:50:34 -05:00
|
|
|
return null
|
2021-01-07 09:23:02 -05:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="toolbar-right">
|
|
|
|
{canRename ? (
|
2024-09-25 09:46:17 -04:00
|
|
|
<OLTooltip
|
2020-11-26 09:22:30 -05:00
|
|
|
id="rename"
|
|
|
|
description={t('rename')}
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:17 -04:00
|
|
|
<button className="btn" onClick={startRenaming} tabIndex={-1}>
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="pencil" fw accessibilityLabel={t('rename')} />}
|
|
|
|
bs5={
|
|
|
|
<MaterialIcon type="edit" accessibilityLabel={t('rename')} />
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</OLTooltip>
|
2020-11-26 09:22:30 -05:00
|
|
|
) : null}
|
|
|
|
{canDelete ? (
|
2024-09-25 09:46:17 -04:00
|
|
|
<OLTooltip
|
2020-11-26 09:22:30 -05:00
|
|
|
id="delete"
|
|
|
|
description={t('delete')}
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom' }}
|
2020-11-26 09:22:30 -05:00
|
|
|
>
|
2024-09-25 09:46:17 -04:00
|
|
|
<button className="btn" onClick={startDeleting} tabIndex={-1}>
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type="trash-o" fw accessibilityLabel={t('delete')} />}
|
|
|
|
bs5={
|
|
|
|
<MaterialIcon type="delete" accessibilityLabel={t('delete')} />
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</OLTooltip>
|
2020-11-26 09:22:30 -05:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeToolbar
|