Skip to content

Commit

Permalink
Transfer multiple files and folders (#1606)
Browse files Browse the repository at this point in the history
* initial restructure

* folder transfers

* sharing working as expected

* sharing is ready

* toasts and error handling

* error messages

* transfer progress ready

* lingui extract

* Update packages/files-ui/src/Contexts/FilesContext.tsx

Co-authored-by: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com>

* using  reduce and handling each file share error

* updated terms

* lingui extract

* added no files check

* lingui extract

* share  messages

* lingui extract

* lint

Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: Michael Yankelev <12774278+FSM1@users.noreply.github.com>
Co-authored-by: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 8, 2021
1 parent 920bc0e commit 99b330b
Show file tree
Hide file tree
Showing 12 changed files with 315 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
}, [currentPath, pathContents, redirect])

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

const itemOperations: IFilesTableBrowserProps["itemOperations"] = useMemo(() => ({
Expand All @@ -180,7 +180,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]: ["download", "rename", "move", "delete"]
[CONTENT_TYPES.Directory]: ["download", "rename", "move", "delete", "share"]
}), [])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ const useStyles = makeStyles(
)

interface IShareFileProps {
file: FileSystemItem
fileSystemItems: FileSystemItem[]
close: () => void
filePath: string
}

const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
const ShareModal = ({ close, fileSystemItems }: IShareFileProps) => {
const classes = useStyles()
const { handleCreateSharedFolder } = useCreateOrEditSharedFolder()
const [sharedFolderName, setSharedFolderName] = useState("")
Expand All @@ -194,7 +193,7 @@ const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
const [keepOriginalFile, setKeepOriginalFile] = useState(true)
const [destinationBucket, setDestinationBucket] = useState<BucketKeyPermission | undefined>()
const { buckets, transferFileBetweenBuckets } = useFiles()
const { bucket } = useFileBrowser()
const { bucket, currentPath } = useFileBrowser()
const { profile } = useUser()
const [nameError, setNameError] = useState("")
const inSharedBucket = useMemo(() => bucket?.type === "share", [bucket])
Expand Down Expand Up @@ -284,21 +283,21 @@ const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
return
}

transferFileBetweenBuckets(bucket.id, file, filePath, bucketToUpload, keepOriginalFile)
transferFileBetweenBuckets(bucket, fileSystemItems, currentPath, bucketToUpload, keepOriginalFile)
close()
}, [
bucket,
destinationBucket,
file,
filePath,
handleCreateSharedFolder,
isUsingCurrentBucket,
sharedFolderName,
sharedFolderReaders,
sharedFolderWriters,
keepOriginalFile,
close,
transferFileBetweenBuckets
transferFileBetweenBuckets,
currentPath,
fileSystemItems
])

return (
Expand Down Expand Up @@ -428,7 +427,7 @@ const ShareModal = ({ close, file, filePath }: IShareFileProps) => {
<CheckboxInput
value={keepOriginalFile}
onChange={() => setKeepOriginalFile(!keepOriginalFile)}
label={t`Keep original file`}
label={t`Keep original files`}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const SharedFileBrowser = () => {
}, [addToast, uploadFiles, bucket, refreshContents])

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

Expand All @@ -204,7 +204,7 @@ const SharedFileBrowser = () => {
[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]: ["rename", "move", "delete", "share"]
}
case "writer":
return {
Expand All @@ -214,7 +214,7 @@ const SharedFileBrowser = () => {
[CONTENT_TYPES.Pdf]: ["preview"],
[CONTENT_TYPES.Text]: ["preview"],
[CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "report", "share"],
[CONTENT_TYPES.Directory]: ["rename", "move", "delete"]
[CONTENT_TYPES.Directory]: ["rename", "move", "delete", "share"]
}
// case "reader":
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ interface IFileSystemItemProps {
browserView: BrowserView
reportFile?: (path: string) => void
showFileInfo?: (path: string) => void
share?: (path: string, fileIndex: number) => void
handleShare?: (file: FileSystemItemType) => void
showPreview?: (fileIndex: number) => void
}

Expand All @@ -145,7 +145,7 @@ const FileSystemItem = ({
resetSelectedFiles,
reportFile,
showFileInfo,
share,
handleShare,
showPreview
}: IFileSystemItemProps) => {
const { bucket, downloadFile, currentPath, handleUploadOnDrop, moveItems } = useFileBrowser()
Expand Down Expand Up @@ -247,7 +247,7 @@ const FileSystemItem = ({
</span>
</>
),
onClick: () => share && share(filePath, files?.indexOf(file))
onClick: () => handleShare && handleShare(file)
},
info: {
contents: (
Expand Down Expand Up @@ -316,9 +316,8 @@ const FileSystemItem = ({
currentPath,
downloadFile,
moveFile,
share,
handleShare,
filePath,
files,
showFileInfo,
recoverFile,
onFilePreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,12 @@ const FilesList = ({ isShared = false }: Props) => {
setIsDeleteModalOpen(true)
}, [])

const handleOpenShareDialog = useCallback((e: React.MouseEvent) => {
e.preventDefault()
e.stopPropagation()
setIsShareModalOpen(true)
}, [])

const mobileMenuItems = useMemo(() => [
{
contents: (
Expand All @@ -642,13 +648,12 @@ const FilesList = ({ isShared = false }: Props) => {
],
[classes.menuIcon])

const onShare = useCallback((fileInfoPath: string, fileIndex: number) => {
const onShare = useCallback((fileSystemItem: FileSystemItemType) => {
if(hasSeenSharingExplainerModal) {
setClickedShare(true)
}

setFilePath(fileInfoPath)
setFileIndex(fileIndex)
setSelectedItems([fileSystemItem])
setIsShareModalOpen(true)
}, [hasSeenSharingExplainerModal])

Expand Down Expand Up @@ -817,6 +822,15 @@ const FilesList = ({ isShared = false }: Props) => {
<Trans>Delete selected</Trans>
</Button>
)}
{validBulkOps.includes("share") && (
<Button
onClick={handleOpenShareDialog}
variant="outline"
testId="share-selected-file"
>
<Trans>Share selected</Trans>
</Button>
)}
</>
)}
</section>
Expand Down Expand Up @@ -954,7 +968,7 @@ const FilesList = ({ isShared = false }: Props) => {
setFileIndex(fileIndex)
setIsPreviewOpen(true)
}}
share={onShare}
handleShare={onShare}
/>
))}
</TableBody>
Expand Down Expand Up @@ -1007,7 +1021,7 @@ const FilesList = ({ isShared = false }: Props) => {
setFilePath(fileInfoPath)
setIsFileInfoModalOpen(true)
}}
share={onShare}
handleShare={onShare}
showPreview={(fileIndex: number) => {
setFileIndex(fileIndex)
setIsPreviewOpen(true)
Expand Down Expand Up @@ -1093,14 +1107,13 @@ const FilesList = ({ isShared = false }: Props) => {
}}
/>
}
{ !showExplainerBeforeShare && isShareModalOpen && filePath && fileIndex !== undefined &&
{ !showExplainerBeforeShare && isShareModalOpen && selectedItems.length &&
<ShareModal
file={files[fileIndex]}
close={() => {
setIsShareModalOpen(false)
setFilePath(undefined)
}}
filePath={currentPath}
fileSystemItems={selectedItems}
/>
}
<SharingExplainerModal
Expand Down
Loading

0 comments on commit 99b330b

Please sign in to comment.