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

Copy/Move to shared folder #1396

Merged
merged 14 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
refreshContents(true)
}, [bucket, refreshContents])

const moveItemsToBin = useCallback(async (cids: string[]) => {
const moveItemsToBin = useCallback(async (cids: string[], hideToast?: boolean) => {
if (!bucket) return
await Promise.all(
cids.map(async (cid: string) => {
Expand All @@ -92,13 +92,15 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
new_path: getPathWithFile("/", itemToDelete.name),
destination: buckets.find(b => b.type === "trash")?.id
})
const message = `${
itemToDelete.isFolder ? t`Folder` : t`File`
} ${t`deleted successfully`}`
addToastMessage({
message: message,
appearance: "success"
})
if (!hideToast) {
const message = `${
itemToDelete.isFolder ? t`Folder` : t`File`
} ${t`deleted successfully`}`
addToastMessage({
message: message,
appearance: "success"
})
}
return Promise.resolve()
} catch (error) {
const message = `${t`There was an error deleting this`} ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CustomModal from "../../Elements/CustomModal"
import { t, Trans } from "@lingui/macro"
import {
Button,
CheckboxInput,
CheckCircleIcon,
Link,
Loading,
Expand Down Expand Up @@ -96,11 +97,16 @@ const useStyles = makeStyles(
justifyContent: "center",
flexDirection: "column"
},
buttonsContainer: {
checkboxContainer: {
display: "flex",
justifyContent: "center",
marginTop: constants.generalUnit * 4
},
buttonsContainer: {
display: "flex",
justifyContent: "center",
marginTop: constants.generalUnit * 2
},
mainButton: {
width: "100%"
},
Expand Down Expand Up @@ -199,10 +205,11 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
const [sharedFolderName, setSharedFolderName] = useState("")
const { sharedFolderReaders, sharedFolderWriters, handleLookupUser, onNewUsers, usersError } = useLookupSharedFolderUser()
const [isUsingCurrentBucket, setIsUsingCurrentBucket] = useState(true)
const [keepOriginalFile, setKeepOriginalFile] = useState(true)
const [currentStep, setCurrentStep] = useState<Step>("1_SHARED_FOLDER_SELECTION_CREATION")
const [destinationBucket, setDestinationBucket] = useState<BucketKeyPermission | undefined>()
const { buckets, uploadFiles } = useFiles()
const { bucket } = useFileBrowser()
const { bucket, deleteItems } = useFileBrowser()
const { profile } = useUser()
const { getFile, error: downloadError, isDownloading } = useGetFile()
const [error, setError] = useState("")
Expand Down Expand Up @@ -294,6 +301,11 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
setIsUploading(true)

uploadFiles(bucketToUpload.id, [new File([fileContent], file.name)], UPLOAD_PATH, bucketToUpload.encryptionKey)
.then(() => {
if (!keepOriginalFile) {
deleteItems && deleteItems([file.cid], true)
}
})
.catch((e) => {
setError(t`Error while uploading ${file.name}`)
console.error(e)
Expand All @@ -315,7 +327,9 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
sharedFolderName,
uploadFiles,
sharedFolderReaders,
sharedFolderWriters
sharedFolderWriters,
deleteItems,
keepOriginalFile
])


Expand Down Expand Up @@ -432,7 +446,7 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
</div>
<div className={classes.heading}>
<Typography className={classes.inputLabel}>
<Trans>Copy to shared folder</Trans>
<Trans>Share file</Trans>
</Typography>
</div>
{(error || downloadError) && (
Expand Down Expand Up @@ -477,6 +491,13 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
{usersError}
</Typography>
)}
<div className={classes.checkboxContainer}>
<CheckboxInput
value={keepOriginalFile}
onChange={() => setKeepOriginalFile(!keepOriginalFile)}
label="Keep original file"
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
<div className={classes.buttonsContainer}>
<Button
size="large"
Expand All @@ -498,7 +519,10 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
className={classes.sideBySideButton}
disabled={currentStep === "1_SHARED_FOLDER_SELECTION_CREATION" ? !!usersError : false}
>
<Trans>Copy over</Trans>
{keepOriginalFile
? <Trans>Copy over</Trans>
: <Trans>Move over</Trans>
}
</Button>
</div>
</div>
Expand All @@ -515,7 +539,7 @@ const CopyToSharedFolderModal = ({ close, file, filePath }: IShareFileProps) =>
variant="h4"
component="p"
>
<Trans>File added successfully!</Trans>
<Trans>File shared successfully!</Trans>
</Typography>
</div>
<Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const FileSystemItem = ({
<>
<ShareAltSvg className={classes.menuIcon} />
<span data-cy="menu-share">
<Trans>Copy to shared folder</Trans>
<Trans>Share</Trans>
</span>
</>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import SurveyBanner from "../../../SurveyBanner"
import { DragPreviewLayer } from "./DragPreviewLayer"
import { useFileBrowser } from "../../../../Contexts/FileBrowserContext"
import ReportFileModal from "../ReportFileModal"
import CopyToSharedFolderModal from "../CopyToSharedFolderModal"
import CopyToSharedFolderModal from "../ShareToSharedFolderModal"

const baseOperations: FileOperation[] = ["download", "info", "preview"]
const readerOperations: FileOperation[] = [...baseOperations, "report"]
Expand Down
2 changes: 1 addition & 1 deletion packages/files-ui/src/Contexts/FileBrowserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface FileBrowserContext extends IFileBrowserModuleProps {
renameItem?: (cid: string, newName: string) => Promise<void>
moveItems?: (cids: string[], newPath: string) => Promise<void>
downloadFile?: (cid: string) => Promise<void>
deleteItems?: (cid: string[]) => Promise<void>
deleteItems?: (cid: string[], hideToast?: boolean) => Promise<void>
recoverItems?: (cid: string[], newPath: string) => Promise<void>
viewFolder?: (cid: string) => void
allowDropUpload?: boolean
Expand Down
18 changes: 12 additions & 6 deletions packages/files-ui/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ msgstr ""
msgid "Copy over"
msgstr ""

msgid "Copy to shared folder"
msgstr ""

msgid "Create"
msgstr "Erstellen"

Expand Down Expand Up @@ -250,15 +247,15 @@ msgstr "Datei"
msgid "File Info"
msgstr "Dateiinfos"

msgid "File added successfully!"
msgstr ""

msgid "File format not supported."
msgstr "Dateiformat wird nicht unterstützt."

msgid "File path"
msgstr ""

msgid "File shared successfully!"
msgstr ""

msgid "File size"
msgstr "Dateigröße"

Expand Down Expand Up @@ -379,6 +376,9 @@ msgstr ""
msgid "Move"
msgstr "Verschieben"

msgid "Move over"
msgstr ""

msgid "Move selected"
msgstr "Ausgewählte verschieben"

Expand Down Expand Up @@ -616,6 +616,12 @@ msgstr "Einstellungen"
msgid "Setup incomplete"
msgstr "Einrichtung unvollständig"

msgid "Share"
msgstr ""

msgid "Share file"
msgstr ""

msgid "Shared"
msgstr "Geteilt"

Expand Down
18 changes: 12 additions & 6 deletions packages/files-ui/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ msgstr "Copy info"
msgid "Copy over"
msgstr "Copy over"

msgid "Copy to shared folder"
msgstr "Copy to shared folder"

msgid "Create"
msgstr "Create"

Expand Down Expand Up @@ -253,15 +250,15 @@ msgstr "File"
msgid "File Info"
msgstr "File Info"

msgid "File added successfully!"
msgstr "File added successfully!"

msgid "File format not supported."
msgstr "File format not supported."

msgid "File path"
msgstr "File path"

msgid "File shared successfully!"
msgstr "File shared successfully!"

msgid "File size"
msgstr "File size"

Expand Down Expand Up @@ -382,6 +379,9 @@ msgstr "Manage Access"
msgid "Move"
msgstr "Move"

msgid "Move over"
msgstr "Move over"

msgid "Move selected"
msgstr "Move selected"

Expand Down Expand Up @@ -619,6 +619,12 @@ msgstr "Settings"
msgid "Setup incomplete"
msgstr "Setup incomplete"

msgid "Share"
msgstr "Share"

msgid "Share file"
msgstr "Share file"

msgid "Shared"
msgstr "Shared"

Expand Down
18 changes: 12 additions & 6 deletions packages/files-ui/src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ msgstr ""
msgid "Copy over"
msgstr ""

msgid "Copy to shared folder"
msgstr ""

msgid "Create"
msgstr "Crear"

Expand Down Expand Up @@ -254,15 +251,15 @@ msgstr "Archivo"
msgid "File Info"
msgstr "Información del archivo"

msgid "File added successfully!"
msgstr ""

msgid "File format not supported."
msgstr "Formato de archivo no soportado."

msgid "File path"
msgstr ""

msgid "File shared successfully!"
msgstr ""

msgid "File size"
msgstr "Tamaño del archivo"

Expand Down Expand Up @@ -383,6 +380,9 @@ msgstr ""
msgid "Move"
msgstr "Moverse"

msgid "Move over"
msgstr ""

msgid "Move selected"
msgstr "Mover seleccionado"

Expand Down Expand Up @@ -620,6 +620,12 @@ msgstr "Ajustes"
msgid "Setup incomplete"
msgstr "Configuración incompleta"

msgid "Share"
msgstr ""

msgid "Share file"
msgstr ""

msgid "Shared"
msgstr ""

Expand Down
18 changes: 12 additions & 6 deletions packages/files-ui/src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ msgstr "Copier les infos"
msgid "Copy over"
msgstr "Copier sur"

msgid "Copy to shared folder"
msgstr "Copier dans le dossier partagé"

msgid "Create"
msgstr "Créer"

Expand Down Expand Up @@ -254,15 +251,15 @@ msgstr "Fichier"
msgid "File Info"
msgstr "Infos du fichier"

msgid "File added successfully!"
msgstr "Fichier ajouté avec succès !"

msgid "File format not supported."
msgstr "Format de fichier non pris en charge."

msgid "File path"
msgstr "Chemin du fichier"

msgid "File shared successfully!"
msgstr ""

msgid "File size"
msgstr "Taille"

Expand Down Expand Up @@ -383,6 +380,9 @@ msgstr "Gérer l’accès"
msgid "Move"
msgstr "Déplacer"

msgid "Move over"
msgstr ""

msgid "Move selected"
msgstr "Déplacer la sélection"

Expand Down Expand Up @@ -620,6 +620,12 @@ msgstr "Paramètres"
msgid "Setup incomplete"
msgstr "Configuration incomplète"

msgid "Share"
msgstr ""

msgid "Share file"
msgstr ""

msgid "Shared"
msgstr "Partagé"

Expand Down
Loading