Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Files] Download multiple files in a zip #1459

Merged
merged 49 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0f1b8d3
WIP
FSM1 Aug 12, 2021
617cd40
lingui extract
actions-user Aug 12, 2021
0e91972
fix path
FSM1 Aug 15, 2021
f4d1173
add transfer toast
FSM1 Aug 15, 2021
e427f1e
update toast message
FSM1 Aug 15, 2021
3c0e2ba
lingui extract
actions-user Aug 15, 2021
b090f67
fix create new shared folder
FSM1 Aug 15, 2021
64a11ac
lingui extract
actions-user Aug 15, 2021
d8d2fff
fix lint
FSM1 Aug 15, 2021
bd6d311
Merge branch 'feat/unblock-ui-while-sharing-1377' of https://github.c…
FSM1 Aug 15, 2021
d2bf55c
Merge branch 'dev' into feat/unblock-ui-while-sharing-1377
Tbaut Aug 17, 2021
909aa79
Update packages/files-ui/src/Components/Modules/FileBrowsers/ShareToS…
FSM1 Aug 17, 2021
d0d9378
Update packages/files-ui/src/Components/Modules/FileBrowsers/hooks/us…
FSM1 Aug 17, 2021
7cfda34
Update packages/files-ui/src/Contexts/FilesContext.tsx
FSM1 Aug 17, 2021
bd8deb3
Update packages/files-ui/src/Components/Modules/TransferProgressToast…
FSM1 Aug 17, 2021
4277c44
Update packages/files-ui/src/Components/Modules/TransferProgressToast…
FSM1 Aug 17, 2021
08f244b
update transfer toast
FSM1 Aug 17, 2021
92bae06
Update packages/files-ui/src/Contexts/FilesReducers.tsx
FSM1 Aug 17, 2021
14f2ceb
enable transfer toast for mobile
FSM1 Aug 17, 2021
5439442
Merge branch 'dev' into feat/unblock-ui-while-sharing-1377
FSM1 Aug 17, 2021
0d79420
Apply suggestions from code review
Tbaut Aug 17, 2021
ec84018
Merge branch 'dev' into feat/unblock-ui-while-sharing-1377
Tbaut Aug 17, 2021
3bf9a3e
lingui extract
actions-user Aug 17, 2021
a89a136
Merge branch 'feat/unblock-ui-while-sharing-1377' of https://github.c…
FSM1 Aug 17, 2021
bed62b9
fix error message and rendering
FSM1 Aug 17, 2021
c51ea39
lingui extract
actions-user Aug 17, 2021
c8163b4
fix lint
FSM1 Aug 17, 2021
0cc7e3f
ensure toasts remain while navigating
FSM1 Aug 18, 2021
69eb174
fix lint
FSM1 Aug 18, 2021
2c21267
Merge branch 'dev' into feat/unblock-ui-while-sharing-1377
FSM1 Aug 19, 2021
215b95d
get recursive structure
Tbaut Aug 19, 2021
24a34bc
Merge branch 'feat/unblock-ui-while-sharing-1377' of github.com:Chain…
Tbaut Aug 19, 2021
49c4611
lingui extract
actions-user Aug 19, 2021
9effbd7
download the zip
Tbaut Aug 19, 2021
234cbd3
download overview per file
Tbaut Aug 20, 2021
f96cb9a
show when 2 files are selected
Tbaut Aug 20, 2021
07993f8
resolve conflicts
Tbaut Aug 20, 2021
fef2bde
lingui extract
actions-user Aug 20, 2021
e36eea2
Merge branch 'dev' into feat/tbaut-download-all-1363
Tbaut Aug 20, 2021
35223db
Merge branch 'dev' of github.com:ChainSafe/ui-monorepo into feat/tbau…
Tbaut Aug 23, 2021
9dffabd
refactor selection form cid to items and allow dl for folders
Tbaut Aug 23, 2021
9b4e115
Merge branch 'feat/tbaut-download-all-1363' of github.com:ChainSafe/u…
Tbaut Aug 23, 2021
fed8d95
menu entry plus toast icon color
Tbaut Aug 23, 2021
7ae4a77
windows fix and relative path instead of whole path for nested dir
Tbaut Aug 23, 2021
53754eb
Merge branch 'dev' into feat/tbaut-download-all-1363
FSM1 Aug 24, 2021
2cfb13a
Merge branch 'dev' into feat/tbaut-download-all-1363
Tbaut Aug 24, 2021
155ecf1
lingui extract
actions-user Aug 24, 2021
fc832dd
error when no file to dl
Tbaut Aug 24, 2021
b8954e6
lingui extract
actions-user Aug 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/files-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dayjs": "^1.9.7",
"eth-crypto": "^1.8.0",
"ethers": "^5.4.3",
"fflate": "^0.7.1",
"formik": "^2.2.5",
"mime-matcher": "^1.0.5",
"react": "^16.14.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import React from "react"
import { createStyles, ITheme, makeStyles } from "@chainsafe/common-theme"
import { createStyles, makeStyles } from "@chainsafe/common-theme"
import { DownloadProgress } from "../../../Contexts/FilesContext"
import {
ProgressBar,
Typography,
CheckCircleIcon,
CloseCircleIcon
} from "@chainsafe/common-components"
import { ProgressBar, Typography, CheckCircleIcon, CloseCircleIcon } from "@chainsafe/common-components"
import clsx from "clsx"
import { Trans } from "@lingui/macro"
import { CSFTheme } from "../../../Themes/types"

const useStyles = makeStyles(
({ constants, palette, animation, breakpoints }: ITheme) => {
({ constants, palette, animation, breakpoints }: CSFTheme) => {
return createStyles({
boxContainer: {
backgroundColor: palette.additional["gray"][3],
Expand Down Expand Up @@ -41,8 +37,9 @@ const useStyles = makeStyles(
marginBottom: {
marginBottom: constants.generalUnit
},
marginRight: {
marginRight: constants.generalUnit * 2
icon: {
marginRight: constants.generalUnit * 2,
fill: constants.fileSystemItemRow.menuIcon
}
})
}
Expand All @@ -53,46 +50,43 @@ interface IDownloadToast {
}

const DownloadToast: React.FC<IDownloadToast> = ({ downloadInProgress }) => {
const {
fileName,
complete,
error,
progress,
errorMessage
} = downloadInProgress
const { fileName, complete, error, progress, errorMessage, currentFileNumber, totalFileNumber } = downloadInProgress
const classes = useStyles()
const fileProgress = totalFileNumber > 1 && `${currentFileNumber}/${totalFileNumber}`

return (
<>
<div className={clsx(classes.appearBox, classes.boxContainer)}>
{complete ? (
{!!complete && !error && (
<div className={classes.contentContainer}>
<CheckCircleIcon className={classes.marginRight} />
<CheckCircleIcon className={classes.icon} />
<Typography
variant="body1"
component="p"
>
<Trans>Download complete</Trans>
</Typography>
</div>
) : error ? (
)}
{error && (
<div className={classes.contentContainer}>
<CloseCircleIcon className={classes.marginRight} />
<CloseCircleIcon className={classes.icon} />
<Typography
variant="body1"
component="p"
>
{errorMessage}
</Typography>
</div>
) : (
)}
{!complete && !error && (
<div>
<Typography
variant="body2"
component="p"
className={classes.marginBottom}
>
Downloading {fileName}
<Trans>Downloading</Trans> {fileProgress} - {fileName}
</Typography>
<ProgressBar
progress={progress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
}, [currentPath, pathContents, redirect])

const bulkOperations: IBulkOperations = useMemo(() => ({
[CONTENT_TYPES.Directory]: ["move", "delete"],
[CONTENT_TYPES.File]: ["delete", "move"]
[CONTENT_TYPES.Directory]: ["download", "move", "delete"],
[CONTENT_TYPES.File]: ["download", "delete", "move"]
}), [])

const itemOperations: IFilesTableBrowserProps["itemOperations"] = useMemo(() => ({
Expand All @@ -215,7 +215,7 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
[CONTENT_TYPES.Pdf]: ["preview"],
[CONTENT_TYPES.Text]: ["preview"],
[CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "share"],
[CONTENT_TYPES.Directory]: ["rename", "move", "delete"]
[CONTENT_TYPES.Directory]: ["download", "rename", "move", "delete"]
}), [])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ const SharedFileBrowser = () => {
}, [addToastMessage, uploadFiles, bucket, refreshContents])

const bulkOperations: IBulkOperations = useMemo(() => ({
[CONTENT_TYPES.Directory]: ["move", "delete"],
[CONTENT_TYPES.File]: ["delete", "move"]
[CONTENT_TYPES.Directory]: ["download", "move", "delete"],
[CONTENT_TYPES.File]: ["download", "delete", "move"]
}), [])

const itemOperations: IFilesTableBrowserProps["itemOperations"] = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { t } from "@lingui/macro"
import { useCallback, useRef, useState } from "react"
import { IFileSystemItem, useFiles } from "../../../../Contexts/FilesContext"
import { FileSystemItem, useFiles } from "../../../../Contexts/FilesContext"
import axios, { CancelTokenSource } from "axios"
import { useFileBrowser } from "../../../../Contexts/FileBrowserContext"

interface getFilesParams {
file: IFileSystemItem
file: FileSystemItem
filePath: string
bucketId?: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ interface IFileSystemTableItemProps {
isFolder: boolean
isOverMove: boolean
isOverUpload: boolean
selected: string[]
selectedCids: string[]
file: FileSystemItem
editing: string | undefined
onFolderOrFileClicks: (e?: React.MouseEvent) => void
Expand All @@ -134,7 +134,7 @@ const FileSystemGridItem = React.forwardRef(
isFolder,
isOverMove,
isOverUpload,
selected,
selectedCids,
file,
editing,
onFolderOrFileClicks,
Expand Down Expand Up @@ -211,7 +211,7 @@ const FileSystemGridItem = React.forwardRef(
classes.fileIcon,
isFolder && classes.folderIcon,
classes.gridIcon,
(isOverMove || isOverUpload || selected.includes(cid)) && "highlighted"
(isOverMove || isOverUpload || selectedCids.includes(cid)) && "highlighted"
)}
>
{icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { BrowserView, FileOperation } from "../../types"
import { CSFTheme } from "../../../../../Themes/types"
import FileItemTableItem from "./FileSystemTableItem"
import FileItemGridItem from "./FileSystemGridItem"
import { FileSystemItem as FileSystemItemType } from "../../../../../Contexts/FilesContext"
import { FileSystemItem as FileSystemItemType, useFiles } from "../../../../../Contexts/FilesContext"
import { useFileBrowser } from "../../../../../Contexts/FileBrowserContext"
import { getPathWithFile } from "../../../../../Utils/pathUtils"
import { BucketUser } from "@chainsafe/files-api-client"
Expand Down Expand Up @@ -104,10 +104,10 @@ const useStyles = makeStyles(({ breakpoints, constants }: CSFTheme) => {
interface IFileSystemItemProps {
file: FileSystemItemType
files: FileSystemItemType[]
selected: string[]
selectedCids: string[]
owners?: BucketUser[]
handleSelectCid(selectedCid: string): void
handleAddToSelectedCids(selectedCid: string): void
handleSelectItem(selectedItem: FileSystemItemType): void
handleAddToSelectedItems(selectedItems: FileSystemItemType): void
editing: string | undefined
setEditing(editing: string | undefined): void
handleRename?: (cid: string, newName: string) => Promise<void>
Expand All @@ -128,7 +128,7 @@ interface IFileSystemItemProps {
const FileSystemItem = ({
file,
files,
selected,
selectedCids,
owners,
editing,
setEditing,
Expand All @@ -137,8 +137,8 @@ const FileSystemItem = ({
recoverFile,
viewFolder,
moveFile,
handleSelectCid,
handleAddToSelectedCids,
handleSelectItem,
handleAddToSelectedItems,
itemOperations,
browserView,
resetSelectedFiles,
Expand All @@ -147,7 +147,8 @@ const FileSystemItem = ({
share,
showPreview
}: IFileSystemItemProps) => {
const { downloadFile, currentPath, handleUploadOnDrop, moveItems } = useFileBrowser()
const { bucket, downloadFile, currentPath, handleUploadOnDrop, moveItems } = useFileBrowser()
const { downloadMultipleFiles } = useFiles()
const { cid, name, isFolder, content_type } = file

const formik = useFormik({
Expand Down Expand Up @@ -210,11 +211,17 @@ const FileSystemItem = ({
<>
<DownloadSvg className={classes.menuIcon} />
<span data-cy="menu-download">
<Trans>Download</Trans>
{file.isFolder ? <Trans>Download as zip</Trans> : <Trans>Download</Trans>}
</span>
</>
),
onClick: () => downloadFile && downloadFile(cid)
onClick: () => {
if (file.isFolder) {
bucket && downloadMultipleFiles([file], currentPath, bucket.id)
} else {
downloadFile && downloadFile(cid)
}
}
},
move: {
contents: (
Expand Down Expand Up @@ -295,21 +302,24 @@ const FileSystemItem = ({
}
}),
[
cid,
classes.menuIcon,
file,
setEditing,
cid,
deleteFile,
bucket,
downloadMultipleFiles,
currentPath,
downloadFile,
file,
moveFile,
share,
filePath,
files,
moveFile,
recoverFile,
reportFile,
setEditing,
showFileInfo,
recoverFile,
onFilePreview,
viewFolder,
share,
onFilePreview
reportFile
])

const menuItems: IMenuItem[] = itemOperations.map(
Expand All @@ -319,13 +329,13 @@ const FileSystemItem = ({
const [, dragMoveRef, preview] = useDrag(() =>
({ type: DragTypes.MOVABLE_FILE,
item: () => {
if (selected.includes(file.cid)) {
return { ids: selected }
if (selectedCids.includes(file.cid)) {
return { ids: selectedCids }
} else {
return { ids: [...selected, file.cid] }
return { ids: [...selectedCids, file.cid] }
}
}
}), [selected])
}), [selectedCids])

useEffect(() => {
// This gets called after every render, by default
Expand Down Expand Up @@ -377,9 +387,9 @@ const FileSystemItem = ({
if (desktop) {
// on desktop
if (e && (e.ctrlKey || e.metaKey)) {
handleAddToSelectedCids(cid)
handleAddToSelectedItems(file)
} else {
handleSelectCid(cid)
handleSelectItem(file)
}
} else {
// on mobile
Expand All @@ -390,7 +400,7 @@ const FileSystemItem = ({
}
}
},
[cid, handleSelectCid, handleAddToSelectedCids, desktop, isFolder, viewFolder, file, onFilePreview]
[desktop, handleAddToSelectedItems, file, handleSelectItem, isFolder, viewFolder, onFilePreview]
)

const onDoubleClick = useCallback(
Expand Down Expand Up @@ -423,7 +433,7 @@ const FileSystemItem = ({
currentPath,
editing,
file,
handleAddToSelectedCids,
handleAddToSelectedItems,
handleRename,
icon: <Icon />,
isFolder,
Expand All @@ -432,7 +442,7 @@ const FileSystemItem = ({
menuItems,
onFolderOrFileClicks,
preview,
selected,
selectedCids,
setEditing,
resetSelectedFiles
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ interface IFileSystemTableItemProps {
isFolder: boolean
isOverMove: boolean
isOverUpload: boolean
selected: string[]
selectedCids: string[]
file: FileSystemItem
editing: string | undefined
handleAddToSelectedCids: (selected: string) => void
handleAddToSelectedItems: (selected: FileSystemItem) => void
onFolderOrFileClicks: (e?: React.MouseEvent) => void
icon: React.ReactNode
preview: ConnectDragPreview
Expand All @@ -121,10 +121,10 @@ const FileSystemTableItem = React.forwardRef(
isFolder,
isOverMove,
isOverUpload,
selected,
selectedCids,
file,
editing,
handleAddToSelectedCids,
handleAddToSelectedItems,
onFolderOrFileClicks,
icon,
preview,
Expand Down Expand Up @@ -162,13 +162,13 @@ const FileSystemTableItem = React.forwardRef(
})}
type="grid"
ref={forwardedRef}
selected={selected.includes(cid)}
selected={selectedCids.includes(cid)}
>
{desktop && (
<TableCell>
<CheckboxInput
value={selected.includes(cid)}
onChange={() => handleAddToSelectedCids(cid)}
value={selectedCids.includes(cid)}
onChange={() => handleAddToSelectedItems(file)}
/>
</TableCell>
)}
Expand Down
Loading