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

feat: Show share synchronization as a minor action (Part 1) #3250

Merged
merged 12 commits into from
Nov 22, 2024
Merged
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"cozy-devtools": "^1.2.1",
"cozy-doctypes": "1.85.4",
"cozy-flags": "^4.6.1",
"cozy-harvest-lib": "^30.0.0",
"cozy-harvest-lib": "^30.6.4",
"cozy-intent": "^2.29.1",
"cozy-keys-lib": "6.0.0",
"cozy-logger": "1.9.1",
Expand All @@ -97,7 +97,8 @@
"cozy-scripts": "^8.3.0",
"cozy-sharing": "^16.0.0",
"cozy-stack-client": "^49.8.0",
"cozy-ui": "^111.21.0",
"cozy-ui": "^113.3.0",
"cozy-viewer": "^2.9.0",
"date-fns": "1.30.1",
"diacritics": "1.3.0",
"filesize": "10.1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"menu_create_shortcut": "Raccourci",
"share": "Partager",
"trash": "Supprimer",
"leave": "Quitter le dossier partagé et le supprimer",
"leave": "Quitter le partage et supprimer le dossier",
"menu_add": "Ajouter",
"menu_add_item": "Ajouter un élément",
"menu_onlyOffice": {
Expand Down
1 change: 0 additions & 1 deletion src/modules/actionmenu/ActionMenuWithHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const ActionMenuWithHeader = ({
actions={actions}
docs={[file]}
anchorOrigin={{
strategy: 'fixed',
vertical: 'bottom',
horizontal: 'right'
}}
Expand Down
54 changes: 50 additions & 4 deletions src/modules/actions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'

import { downloadFiles, restoreFiles } from './utils'
import { HOME_LINK_HREF } from 'constants/config'
import { isEncryptedFolder, isEncryptedFile } from 'lib/encryption'
import { navigateToModal } from 'modules/actions/helpers'
import DeleteConfirm from 'modules/drive/DeleteConfirm'
Expand All @@ -37,6 +38,7 @@ export const download = ({ client, t, vaultClient, showAlert }) => {
// Then, we do not display the download button when the selection
// includes an encrypted folder or several encrypted files
return (
files.length > 0 &&
!files.some(file => isEncryptedFolder(file)) &&
!(files.length > 1 && files.some(file => isEncryptedFile(file)))
)
Expand Down Expand Up @@ -67,15 +69,21 @@ export const hr = () => {
}
}

export const trash = ({ t, pushModal, popModal, hasWriteAccess, refresh }) => {
const label = t('SelectionBar.trash')
export const trash = ({
t,
pushModal,
popModal,
hasWriteAccess,
refresh,
byDocId,
isOwner
}) => {
const icon = TrashIcon

return {
name: 'trash',
label,
Merkur39 marked this conversation as resolved.
Show resolved Hide resolved
icon,
displayCondition: () => hasWriteAccess,
displayCondition: files => files.length > 0 && hasWriteAccess,
action: files =>
pushModal(
<DeleteConfirm
Expand All @@ -87,6 +95,12 @@ export const trash = ({ t, pushModal, popModal, hasWriteAccess, refresh }) => {
/>
),
Component: forwardRef(function Trash(props, ref) {
const sharedWithMe =
byDocId !== undefined &&
byDocId[props.docs[0].id] &&
!isOwner(props.docs[0].id)
const label = sharedWithMe ? t('toolbar.leave') : t('SelectionBar.trash')

return (
<ActionsMenuItem {...props} ref={ref}>
<ListItemIcon>
Expand Down Expand Up @@ -209,3 +223,35 @@ export const restore = ({ t, refresh, client }) => {
})
}
}

export const openExternalLink = ({ t, isSharingShortcutCreated, link }) => {
const label =
link === HOME_LINK_HREF
? t('Share.create-cozy')
: isSharingShortcutCreated
? t('toolbar.menu_sync_cozy')
: t('toolbar.add_to_mine')
const icon =
!isSharingShortcutCreated || link === HOME_LINK_HREF
? 'to-the-cloud'
: 'sync'

return {
name: 'openExternalLink',
label,
icon,
action: () => {
openExternalLink(link)
},
Component: forwardRef(function OpenExternalLink(props, ref) {
return (
<ActionsMenuItem isListItem {...props} ref={ref}>
<ListItemIcon>
<Icon icon={icon} />
</ListItemIcon>
<ListItemText primary={label} />
</ActionsMenuItem>
)
})
}
}
45 changes: 20 additions & 25 deletions src/modules/breadcrumb/components/DesktopBreadcrumb.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useMemo, useState } from 'react'

import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu'
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import BreadcrumbMui from 'cozy-ui/transpiled/react/Breadcrumbs'
import Icon from 'cozy-ui/transpiled/react/Icon'
import FolderIcon from 'cozy-ui/transpiled/react/Icons/Folder'
import RightIcon from 'cozy-ui/transpiled/react/Icons/Right'
import ActionMenu, {
ActionMenuItem
} from 'cozy-ui/transpiled/react/deprecated/ActionMenu'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import IconServer from 'assets/icons/icon-server.svg'
Expand All @@ -28,13 +28,15 @@ const DesktopBreadcrumb = ({ onBreadcrumbClick, path }) => {
)
const [menuDisplayed, setMenuDisplayed] = useState(false)

const closeMenu = () => setMenuDisplayed(false)

const handleDropdownTriggerClick = e => {
e.stopPropagation()
setMenuDisplayed(true)
}

useEffect(() => {
setMenuDisplayed(false)
closeMenu()
setDropdownTrigger(document.querySelector(`[aria-label="${expandText}"]`))
}, [path]) // eslint-disable-line react-hooks/exhaustive-deps

Expand All @@ -43,7 +45,7 @@ const DesktopBreadcrumb = ({ onBreadcrumbClick, path }) => {
if (trigger) {
trigger.addEventListener('click', handleDropdownTriggerClick)
return () => {
setMenuDisplayed(false)
closeMenu()
trigger.removeEventListener('click', handleDropdownTriggerClick)
}
}
Expand Down Expand Up @@ -115,36 +117,29 @@ const DesktopBreadcrumb = ({ onBreadcrumbClick, path }) => {
</BreadcrumbMui>

{menuDisplayed && (
<ActionMenu
anchorElRef={anchorElRef}
autoclose={true}
onClose={() => {
setMenuDisplayed(false)
}}
popperOptions={{
placement: 'bottom-end',
modifiers: [
{
name: 'offset',
options: {
offset: [0, 10]
}
}
]
<ActionsMenu
open
ref={anchorElRef}
onClose={closeMenu}
actions={[]}
docs={[]}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left'
}}
>
{path.slice(1, -2).map(breadcrumbPath => (
<ActionMenuItem
<ActionsMenuItem
key={breadcrumbPath.name}
onClick={e => {
e.stopPropagation()
onBreadcrumbClick(breadcrumbPath)
}}
>
{breadcrumbPath.name}
</ActionMenuItem>
<ListItemText primary={breadcrumbPath.name} />
</ActionsMenuItem>
))}
</ActionMenu>
</ActionsMenu>
)}
</>
)
Expand Down
24 changes: 15 additions & 9 deletions src/modules/breadcrumb/components/DesktopBreadcrumb.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import DesktopBreadcrumb from './DesktopBreadcrumb'
import { dummyBreadcrumbPath } from 'test/dummies/dummyBreadcrumbPath'

jest.mock('cozy-ui/transpiled/react/deprecated/ActionMenu', () => ({
__esModule: true,
// eslint-disable-next-line react/display-name
default: ({ children }) => <div data-testid="action-menu">{children}</div>,
// eslint-disable-next-line react/display-name
ActionMenuItem: ({ children }) => (
<div data-testid="action-menu-item">{children}</div>
)
}))
jest.mock('cozy-ui/transpiled/react/ActionsMenu', () => ({ children }) => (
<div data-testid="action-menu">{children}</div>
))
jest.mock(
'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem',
() =>
({ children }) =>
<div data-testid="action-menu-item">{children}</div>
)

jest.mock('cozy-ui/transpiled/react/providers/I18n')
describe('DesktopBreadcrumb', () => {
Expand Down Expand Up @@ -53,6 +53,12 @@
})

describe('mount', () => {
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {})
})
afterEach(() => {
console.error.mockRestore()

Check warning on line 60 in src/modules/breadcrumb/components/DesktopBreadcrumb.spec.jsx

View workflow job for this annotation

GitHub Actions / Build and publish

Unexpected console statement
})
it('should hide menu displayed while navigating', async () => {
// Given
const { container, queryByTestId, rerender } = await render(
Expand Down
51 changes: 28 additions & 23 deletions src/modules/drive/AddMenu/AddMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'

import flag from 'cozy-flags'
import Typography from 'cozy-ui/transpiled/react/Typography'
import ActionMenu from 'cozy-ui/transpiled/react/deprecated/ActionMenu'
import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu'
import ActionsMenuMobileHeader from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuMobileHeader'
import Divider from 'cozy-ui/transpiled/react/Divider'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

Expand All @@ -23,25 +25,27 @@ export const ActionMenuContent = ({
refreshFolderContent,
isPublic,
isEncryptedFolder,
displayedFolder
displayedFolder,
onClick
}) => {
const { t } = useI18n()
const { isMobile, isDesktop } = useBreakpoints()
const { isDesktop } = useBreakpoints()
const { hasScanner } = useScannerContext()

return (
<>
{isMobile && (
<>
<Typography variant="h6" className="u-p-1">
{t('toolbar.menu_add')}
</Typography>
<hr />
</>
<ActionsMenuMobileHeader>
<ListItemText
primary={t('toolbar.menu_add')}
primaryTypographyProps={{ variant: 'h6' }}
/>
</ActionsMenuMobileHeader>

{canCreateFolder && !isEncryptedFolder && (
<AddFolderItem onClick={onClick} />
Merkur39 marked this conversation as resolved.
Show resolved Hide resolved
)}
{canCreateFolder && !isEncryptedFolder && <AddFolderItem />}
{canCreateFolder && !isPublic && flag('drive.enable-encryption') && (
<AddEncryptedFolderItem />
<AddEncryptedFolderItem onClick={onClick} />
)}
{!isPublic && !isEncryptedFolder && (
<CreateNoteItem displayedFolder={displayedFolder} />
Expand All @@ -54,17 +58,18 @@ export const ActionMenuContent = ({
</>
)}
{!isEncryptedFolder && (
<CreateShortcut onCreated={refreshFolderContent} />
<CreateShortcut onCreated={refreshFolderContent} onClick={onClick} />
)}
{canUpload && <hr />}
{canUpload && <Divider className="u-mv-half" />}
{canUpload && (
<UploadItem
disabled={isDisabled}
onUploaded={refreshFolderContent}
displayedFolder={displayedFolder}
onClick={onClick}
/>
)}
{hasScanner && <ScannerMenuItem />}
{hasScanner && <ScannerMenuItem onClick={onClick} />}
</>
)
}
Expand All @@ -82,13 +87,12 @@ const AddMenu = ({
...actionMenuProps
}) => {
return (
<ActionMenu
anchorElRef={anchorRef}
<ActionsMenu
open
ref={anchorRef}
onClose={handleClose}
autoclose={true}
popperOptions={{
strategy: 'fixed'
}}
docs={[displayedFolder]}
actions={[]}
{...actionMenuProps}
>
<ActionMenuContent
Expand All @@ -99,8 +103,9 @@ const AddMenu = ({
isPublic={isPublic}
isEncryptedFolder={isEncryptedFolder}
displayedFolder={displayedFolder}
onClick={handleClose}
/>
</ActionMenu>
</ActionsMenu>
)
}

Expand Down
Loading
Loading