2022-01-10 15:46:46 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2020-11-26 14:22:30 +00:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
import TooltipButton from '../../../shared/components/tooltip-button'
|
|
|
|
|
2022-01-10 15:46:46 +00:00
|
|
|
import { useEditorContext } from '../../../shared/context/editor-context'
|
2020-11-26 14:22:30 +00:00
|
|
|
import { useFileTreeActionable } from '../contexts/file-tree-actionable'
|
|
|
|
|
|
|
|
function FileTreeToolbar() {
|
2022-01-10 15:46:46 +00:00
|
|
|
const { permissionsLevel } = useEditorContext(editorContextPropTypes)
|
2020-11-26 14:22:30 +00:00
|
|
|
|
2022-01-10 15:46:46 +00:00
|
|
|
if (permissionsLevel === 'readOnly') return null
|
2020-11-26 14:22:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="toolbar toolbar-filetree">
|
|
|
|
<FileTreeToolbarLeft />
|
|
|
|
<FileTreeToolbarRight />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-10 15:46:46 +00:00
|
|
|
const editorContextPropTypes = {
|
|
|
|
permissionsLevel: PropTypes.oneOf(['readOnly', 'readAndWrite', 'owner']),
|
|
|
|
}
|
|
|
|
|
2020-11-26 14:22:30 +00:00
|
|
|
function FileTreeToolbarLeft() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
canCreate,
|
|
|
|
startCreatingFolder,
|
|
|
|
startCreatingDocOrFile,
|
2021-04-27 07:52:58 +00:00
|
|
|
startUploadingDocOrFile,
|
2020-11-26 14:22:30 +00:00
|
|
|
} = useFileTreeActionable()
|
|
|
|
|
|
|
|
if (!canCreate) return null
|
|
|
|
|
|
|
|
return (
|
2021-03-18 09:52:36 +00:00
|
|
|
<div className="toolbar-left">
|
2020-11-26 14:22:30 +00:00
|
|
|
<TooltipButton
|
|
|
|
id="new_file"
|
|
|
|
description={t('new_file')}
|
|
|
|
onClick={startCreatingDocOrFile}
|
|
|
|
>
|
2022-01-19 11:56:57 +00:00
|
|
|
<Icon type="file" fw accessibilityLabel={t('new_file')} />
|
2020-11-26 14:22:30 +00:00
|
|
|
</TooltipButton>
|
|
|
|
<TooltipButton
|
|
|
|
id="new_folder"
|
|
|
|
description={t('new_folder')}
|
|
|
|
onClick={startCreatingFolder}
|
|
|
|
>
|
2022-01-19 11:56:57 +00:00
|
|
|
<Icon type="folder" fw accessibilityLabel={t('new_folder')} />
|
2020-11-26 14:22:30 +00:00
|
|
|
</TooltipButton>
|
|
|
|
<TooltipButton
|
|
|
|
id="upload"
|
|
|
|
description={t('upload')}
|
|
|
|
onClick={startUploadingDocOrFile}
|
|
|
|
>
|
2022-01-19 11:56:57 +00:00
|
|
|
<Icon type="upload" fw accessibilityLabel={t('upload')} />
|
2020-11-26 14:22:30 +00:00
|
|
|
</TooltipButton>
|
2021-03-18 09:52:36 +00:00
|
|
|
</div>
|
2020-11-26 14:22:30 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileTreeToolbarRight() {
|
|
|
|
const { t } = useTranslation()
|
2022-01-10 10:23:05 +00:00
|
|
|
const { canRename, canDelete, startRenaming, startDeleting } =
|
|
|
|
useFileTreeActionable()
|
2020-11-26 14:22:30 +00:00
|
|
|
|
2021-01-07 14:23:02 +00:00
|
|
|
if (!canRename && !canDelete) {
|
2021-02-09 09:50:34 +00:00
|
|
|
return null
|
2021-01-07 14:23:02 +00:00
|
|
|
}
|
2020-11-26 14:22:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="toolbar-right">
|
|
|
|
{canRename ? (
|
|
|
|
<TooltipButton
|
|
|
|
id="rename"
|
|
|
|
description={t('rename')}
|
|
|
|
onClick={startRenaming}
|
|
|
|
>
|
2022-01-19 11:56:57 +00:00
|
|
|
<Icon type="pencil" fw accessibilityLabel={t('rename')} />
|
2020-11-26 14:22:30 +00:00
|
|
|
</TooltipButton>
|
|
|
|
) : null}
|
|
|
|
{canDelete ? (
|
|
|
|
<TooltipButton
|
|
|
|
id="delete"
|
|
|
|
description={t('delete')}
|
|
|
|
onClick={startDeleting}
|
|
|
|
>
|
2022-01-19 11:56:57 +00:00
|
|
|
<Icon type="trash-o" fw accessibilityLabel={t('delete')} />
|
2020-11-26 14:22:30 +00:00
|
|
|
</TooltipButton>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FileTreeToolbar
|