Add "Download" item to file tree context menu (#9190)

GitOrigin-RevId: af55d782aeaab3acd516a1581d59dd3332109cb8
This commit is contained in:
Alf Eaton
2022-08-12 10:54:32 +01:00
committed by Copybot
parent 0f1163e876
commit ec13ebdc7c
2 changed files with 16 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ function FileTreeItemMenuItems() {
startCreatingFolder,
startCreatingDocOrFile,
startUploadingDocOrFile,
downloadPath,
} = useFileTreeActionable()
return (
@@ -22,6 +23,9 @@ function FileTreeItemMenuItems() {
{canRename ? (
<MenuItem onClick={startRenaming}>{t('rename')}</MenuItem>
) : null}
{downloadPath ? (
<MenuItem href={downloadPath}>{t('download')}</MenuItem>
) : null}
{canDelete ? (
<MenuItem onClick={startDeleting}>{t('delete')}</MenuItem>
) : null}

View File

@@ -346,6 +346,17 @@ export function FileTreeActionableProvider({ children }) {
}
}, [])
// build the path for downloading a single file
const downloadPath = useMemo(() => {
if (selectedEntityIds.size === 1) {
const [selectedEntityId] = selectedEntityIds
const selectedEntity = findInTree(fileTreeData, selectedEntityId)
if (selectedEntity?.type === 'fileRef') {
return `/project/${projectId}/file/${selectedEntityId}`
}
}
}, [fileTreeData, projectId, selectedEntityIds])
const value = {
canDelete: selectedEntityIds.size > 0,
canRename: selectedEntityIds.size === 1,
@@ -368,6 +379,7 @@ export function FileTreeActionableProvider({ children }) {
cancel,
droppedFiles,
setDroppedFiles,
downloadPath,
}
return (