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

Merge dev to epic/link sharing #1633

Merged
merged 6 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion packages/files-ui/cypress/tests/file-preview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe("File Preview", () => {
homePage.fileItemName().dblclick()
previewModal.unsupportedFileLabel().should("exist")
previewModal.downloadUnsupportedFileButton().should("be.visible")

// ensure the download request contains the correct file
cy.get("@downloadRequest").its("request.body").should("contain", {
path: "/file.zip"
Expand Down
2 changes: 1 addition & 1 deletion packages/files-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@types/yup": "^0.29.9",
"@types/zxcvbn": "^4.4.0",
"babel-plugin-macros": "^2.8.0",
"cypress": "^8.5",
"cypress": "^8.6",
"cypress-file-upload": "^5.0.8",
"cypress-pipe": "^2.0.0"
},
Expand Down
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 @@ -427,7 +426,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