Skip to content

Commit

Permalink
fix(MoveOutsideSharedFolderModal): Improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Jul 28, 2023
1 parent 942ff75 commit a5242a8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/drive/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,15 @@
"cancelledWithRestoreErrors": "%{subject} has been moved back to it's original location but there was an error while restoring the file from trash. |||| %{smart_count} elements have been moved back to their original location but there was %{restoreErrorsCount} error(s) while restoring the file(s) from trash.",
"cancelled_error": "Sorry, there was an error while moving the element back. |||| Sorry, there was an error while moving these elements back.",
"multipleEntries": "%{smart_count} element |||| %{smart_count} elements",
"entriesType": {
"file": "file",
"directory": "folder",
"element": "element"
},
"outsideSharedFolder": {
"title": "Moving outside the folder %{sharedFolder}",
"content": "Warning, you want to move %{entriesName} outside the shared folder %{sharedFolder}. This move will remove access to the file/folder from all members of the share. They will find the file/folder in their recycle bin.",
"title": "Moving outside the %{sharedFolder} folder",
"content_1": "Warning, you want to move %{name} out of the shared %{sharedFolder} folder. |||| Warning, you want to move %{smart_count} %{type}s out of the shared %{sharedFolder} folder.",
"content_2": "This move, will remove the %{type} %{name} from the share. This %{type} will therefore be trashed for all members of the share. |||| This move, will remove %{smart_count} %{type}s from the share. These %{type}s will therefore be trashed for all members of the share.",
"cancel": "Cancel",
"confirm": "I understand"
},
Expand Down
2 changes: 1 addition & 1 deletion src/drive/web/modules/move/MoveModal.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('MoveModal component', () => {

await waitFor(() => {
expect(
screen.getByText('Moving outside the folder Bills')
screen.getByText('Moving outside the Bills folder')
).toBeInTheDocument()
})
})
Expand Down
28 changes: 23 additions & 5 deletions src/drive/web/modules/move/MoveOutsideSharedFolderModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import Buttons from 'cozy-ui/transpiled/react/Buttons'
import { useI18n } from 'cozy-ui/transpiled/react'
import { useQuery } from 'cozy-client'
import { useSharingContext } from 'cozy-sharing'
import Typography from 'cozy-ui/transpiled/react/Typography'

import { buildFolderByPathQuery } from 'drive/web/modules/queries'
import { LoaderModal } from 'drive/web/modules/move/LoaderModal'
import { getEntriesName } from 'drive/web/modules/move/helpers'
import { getEntriesType } from 'drive/web/modules/move/helpers'

/**
* Alert the user when is trying to move a folder/file outside of a shared folder
Expand All @@ -26,16 +27,33 @@ const MoveOutsideSharedFolderModal = ({ entries, onCancel, onConfirm }) => {
)

if (fetchStatus === 'loaded') {
const type = t(`Move.entriesType.${getEntriesType(entries)}`)

return (
<ConfirmDialog
open
title={t('Move.outsideSharedFolder.title', {
sharedFolder: data[0].name
})}
content={t('Move.outsideSharedFolder.content', {
entriesName: getEntriesName(entries, t),
sharedFolder: data[0].name
})}
content={
<>
<Typography variant="body1" className="u-mb-half">
{t('Move.outsideSharedFolder.content_1', {
sharedFolder: data[0].name,
name: entries[0].name,
type,
smart_count: entries.length
})}
</Typography>
<Typography variant="body1">
{t('Move.outsideSharedFolder.content_2', {
name: entries[0].name,
type,
smart_count: entries.length
})}
</Typography>
</>
}
actions={
<>
<Buttons
Expand Down
19 changes: 19 additions & 0 deletions src/drive/web/modules/move/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ export const getEntriesName = (entries, t) => {
})
: entries[0].name
}

/**
* Get type from the entries
* @param {object[]} entries
* @returns {string} type from the entries
*/
export const getEntriesType = entries => {
return entries.reduce((previous, current) => {
const type =
current.type === 'file' || current.type === 'folder'
? current.type
: 'element'

if (previous !== null) {
return previous === type ? previous : 'element'
}
return current.type
}, null)
}
40 changes: 39 additions & 1 deletion src/drive/web/modules/move/helpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CozyClient from 'cozy-client'

import { cancelMove } from 'drive/web/modules/move/helpers'
import { cancelMove, getEntriesType } from 'drive/web/modules/move/helpers'
import { CozyFile } from 'models'

jest.mock('cozy-doctypes')
Expand Down Expand Up @@ -81,3 +81,41 @@ describe('cancelMove', () => {
expect(refreshSpy).toHaveBeenCalled()
})
})

describe('getEntriesType', () => {
it('should return file for entries only file', () => {
const res = getEntriesType([
{ type: 'file' },
{ type: 'file' },
{ type: 'file' }
])
expect(res).toBe('file')
})

it('should return folder for entries only folder', () => {
const res = getEntriesType([
{ type: 'folder' },
{ type: 'folder' },
{ type: 'folder' }
])
expect(res).toBe('folder')
})

it('should return element for entries with multiples types', () => {
const res = getEntriesType([
{ type: 'file' },
{ type: 'folder' },
{ type: 'file' }
])
expect(res).toBe('element')
})

it('should return element if something else from file or directory', () => {
const res = getEntriesType([
{ type: 'something' },
{ type: 'something' },
{ type: 'something' }
])
expect(res).toBe('element')
})
})

0 comments on commit a5242a8

Please sign in to comment.