diff --git a/src/drive/locales/en.json b/src/drive/locales/en.json index 8d7cdf3c3e..74f6d25b1a 100644 --- a/src/drive/locales/en.json +++ b/src/drive/locales/en.json @@ -502,14 +502,19 @@ } }, "upload": { + "documentType": { + "file": "file", + "directory": "folder", + "element": "element" + }, "alert": { - "success": "%{smart_count} file uploaded with success. |||| %{smart_count} files uploaded with success.", - "success_conflicts": "%{smart_count} file uploaded with %{conflictNumber} conflict(s). |||| %{smart_count} files uploaded with %{conflictNumber} conflict(s).", - "success_updated": "%{smart_count} file uploaded and %{updatedCount} updated. |||| %{smart_count} files uploaded and %{updatedCount} updated.", - "success_updated_conflicts": "%{smart_count} file uploaded, %{updatedCount} updated and %{conflictCount} conflict(s). |||| %{smart_count} files uploaded, %{updatedCount} updated and %{conflictCount} conflict(s).", - "updated": "%{smart_count} file updated. |||| %{smart_count} files updated.", - "updated_conflicts": "%{smart_count} file updated with %{conflictCount} conflict(s). |||| %{smart_count} files updated with %{conflictCount} conflict(s).", - "errors": "Errors occurred during the file upload.", + "success": "%{smart_count} %{type} uploaded with success. |||| %{smart_count} %{type}s uploaded with success.", + "success_conflicts": "%{smart_count} %{type} uploaded with %{conflictNumber} conflict(s). |||| %{smart_count} %{type}s uploaded with %{conflictNumber} conflict(s).", + "success_updated": "%{smart_count} %{type} uploaded and %{updatedCount} updated. |||| %{smart_count} %{type}s uploaded and %{updatedCount} updated.", + "success_updated_conflicts": "%{smart_count} %{type} uploaded, %{updatedCount} updated and %{conflictCount} conflict(s). |||| %{smart_count} %{type}s uploaded, %{updatedCount} updated and %{conflictCount} conflict(s).", + "updated": "%{smart_count} %{type} updated. |||| %{smart_count} %{type} updated.", + "updated_conflicts": "%{smart_count} %{type} updated with %{conflictCount} conflict(s). |||| %{smart_count} %{type}s updated with %{conflictCount} conflict(s).", + "errors": "Errors occurred during the %{type} upload.", "network": "You are currenly offline. Please try again once you're connected." } }, diff --git a/src/drive/web/modules/drive/Toolbar/components/UploadItem.jsx b/src/drive/web/modules/drive/Toolbar/components/UploadItem.jsx index c196f8f869..4edaf0b50e 100644 --- a/src/drive/web/modules/drive/Toolbar/components/UploadItem.jsx +++ b/src/drive/web/modules/drive/Toolbar/components/UploadItem.jsx @@ -38,12 +38,13 @@ const UploadItem = ({ t, isDisabled, onUpload, displayedFolder }) => { ) } -const mapDispatchToProps = (dispatch, { sharingState, onUploaded }) => ({ +const mapDispatchToProps = (dispatch, { sharingState, onUploaded, t }) => ({ onUpload: (client, vaultClient, files, displayedFolder) => { dispatch( uploadFiles(files, displayedFolder.id, sharingState, onUploaded, { client, - vaultClient + vaultClient, + t }) ) } diff --git a/src/drive/web/modules/navigation/duck/actions.jsx b/src/drive/web/modules/navigation/duck/actions.jsx index 382bbe4b25..f6643ce9f2 100644 --- a/src/drive/web/modules/navigation/duck/actions.jsx +++ b/src/drive/web/modules/navigation/duck/actions.jsx @@ -38,7 +38,7 @@ export const uploadFiles = dirId, sharingState, fileUploadedCallback = () => null, - { client, vaultClient } + { client, vaultClient, t } ) => dispatch => { dispatch( @@ -55,7 +55,8 @@ export const uploadFiles = conflicts, networkErrors, errors, - updated + updated, + t ) ), { client, vaultClient } @@ -63,11 +64,36 @@ export const uploadFiles = ) } +const getEntriesType = entries => { + const types = entries.reduce((acc, entry) => { + if (entry.isDirectory) { + acc.add('directory') + } else { + acc.add('file') + } + return acc + }, new Set()) + + if (types.size > 1) { + return 'element' + } else { + return types.has('directory') ? 'directory' : 'file' + } +} + const uploadQueueProcessed = - (created, quotas, conflicts, networkErrors, errors, updated) => dispatch => { + (created, quotas, conflicts, networkErrors, errors, updated, t) => + dispatch => { const conflictCount = conflicts.length const createdCount = created.length const updatedCount = updated.length + const type = t( + `upload.documentType.${getEntriesType([ + ...created, + ...updated, + ...conflicts + ])}` + ) if (quotas.length > 0) { logger.warn(`Upload module triggers a quota alert: ${quotas}`) // quota errors have their own modal instead of a notification @@ -82,30 +108,36 @@ const uploadQueueProcessed = Alerter.success('upload.alert.success_updated_conflicts', { smart_count: createdCount, updatedCount, - conflictCount + conflictCount, + type }) } else if (updatedCount > 0 && createdCount > 0) { Alerter.success('upload.alert.success_updated', { smart_count: createdCount, - updatedCount + updatedCount, + type }) } else if (updatedCount > 0 && conflictCount > 0) { Alerter.success('upload.alert.updated_conflicts', { smart_count: updatedCount, - conflictCount + conflictCount, + type }) } else if (conflictCount > 0) { Alerter.info('upload.alert.success_conflicts', { smart_count: createdCount, - conflictNumber: conflictCount + conflictNumber: conflictCount, + type }) } else if (updatedCount > 0 && createdCount === 0) { Alerter.success('upload.alert.updated', { - smart_count: updatedCount + smart_count: updatedCount, + type }) } else { Alerter.success('upload.alert.success', { - smart_count: createdCount + smart_count: createdCount, + type }) } } diff --git a/src/drive/web/modules/upload/Dropzone.jsx b/src/drive/web/modules/upload/Dropzone.jsx index 342b7ab843..2230bda57b 100644 --- a/src/drive/web/modules/upload/Dropzone.jsx +++ b/src/drive/web/modules/upload/Dropzone.jsx @@ -4,6 +4,7 @@ import UIDropzone from 'react-dropzone' import { compose } from 'redux' import { withVaultClient } from 'cozy-keys-lib' import { withClient } from 'cozy-client' +import { translate } from 'cozy-ui/transpiled/react/I18n' import { uploadFiles } from 'drive/web/modules/navigation/duck' @@ -25,11 +26,11 @@ export class Dropzone extends Component { this.setState(state => ({ ...state, dropzoneActive: false })) onDrop = async (files, _, evt) => { - const { uploadFiles, client, vaultClient } = this.props + const { uploadFiles, client, vaultClient, t } = this.props this.setState(state => ({ ...state, dropzoneActive: false })) if (!canDrop(evt)) return const filesToUpload = canHandleFolders(evt) ? evt.dataTransfer.items : files - uploadFiles(filesToUpload, { client, vaultClient }) + uploadFiles(filesToUpload, { client, vaultClient, t }) } render() { @@ -69,16 +70,18 @@ const canDrop = evt => { } const mapDispatchToProps = (dispatch, { displayedFolder, sharingState }) => ({ - uploadFiles: (files, { client, vaultClient }) => + uploadFiles: (files, { client, vaultClient, t }) => dispatch( uploadFiles(files, displayedFolder.id, sharingState, () => null, { client, - vaultClient + vaultClient, + t }) ) }) export default compose( + translate(), withSharingState, withClient, withVaultClient, diff --git a/src/drive/web/modules/upload/UploadButton.jsx b/src/drive/web/modules/upload/UploadButton.jsx index 0e53425f05..9cd96735c7 100644 --- a/src/drive/web/modules/upload/UploadButton.jsx +++ b/src/drive/web/modules/upload/UploadButton.jsx @@ -7,6 +7,7 @@ import withSharingState from 'cozy-sharing/dist/hoc/withSharingState' import Icon from 'cozy-ui/transpiled/react/Icon' import FileInput from 'cozy-ui/transpiled/react/FileInput' import UploadIcon from 'cozy-ui/transpiled/react/Icons/Upload' +import { translate } from 'cozy-ui/transpiled/react/I18n' import { uploadFiles } from 'drive/web/modules/navigation/duck' @@ -43,14 +44,17 @@ UploadButton.defaultProps = { const mapDispatchToProps = ( dispatch, - { displayedFolder, sharingState, onUploaded } + { displayedFolder, sharingState, onUploaded, t } ) => ({ onUpload: files => { - dispatch(uploadFiles(files, displayedFolder.id, sharingState, onUploaded)) + dispatch( + uploadFiles(files, displayedFolder.id, sharingState, onUploaded, { t }) + ) } }) export default compose( + translate(), withSharingState, connect(null, mapDispatchToProps) )(UploadButton) diff --git a/src/drive/web/modules/upload/__snapshots__/Dropzone.spec.jsx.snap b/src/drive/web/modules/upload/__snapshots__/Dropzone.spec.jsx.snap index d3ae3d990f..0b531c7446 100644 --- a/src/drive/web/modules/upload/__snapshots__/Dropzone.spec.jsx.snap +++ b/src/drive/web/modules/upload/__snapshots__/Dropzone.spec.jsx.snap @@ -98,39 +98,31 @@ exports[`Dropzone should match snapshot 1`] = ` - - - - - + t={[Function]} + > + + + +