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: Update actions when sharing Cozy to non-associated Cozy #3256

Merged
merged 17 commits into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"cozy-scripts": "^8.3.0",
"cozy-sharing": "^16.7.0",
"cozy-stack-client": "^49.8.0",
"cozy-ui": "^113.3.0",
"cozy-ui": "^113.5.0",
"cozy-viewer": "^2.9.0",
"date-fns": "1.30.1",
"diacritics": "1.3.0",
Expand Down
49 changes: 49 additions & 0 deletions src/modules/actions/addItems.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { forwardRef, useContext } from 'react'

import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import Icon from 'cozy-ui/transpiled/react/Icon'
import PlusIcon from 'cozy-ui/transpiled/react/Icons/Plus'
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'

import { AddMenuContext } from 'modules/drive/AddMenu/AddMenuProvider'

const makeComponent = (label, icon) => {
const Component = forwardRef((props, ref) => {
const addMenuCtx = useContext(AddMenuContext)
const { a11y } = addMenuCtx

return (
<ActionsMenuItem
{...props}
onClick={() => props.onClick(addMenuCtx)}
ref={ref}
{...a11y}
>
<ListItemIcon>
<Icon icon={icon} />
</ListItemIcon>
<ListItemText primary={label} />
</ActionsMenuItem>
)
})
Component.displayName = 'AddItems'

return Component
}

export const addItems = ({ t, hasWriteAccess }) => {
const label = t('toolbar.menu_add_item')
const icon = PlusIcon

return {
name: 'addItems',
label,
icon,
displayCondition: () => hasWriteAccess,
action: (_, { isOffline, handleOfflineClick, handleToggle }) => {
return isOffline ? handleOfflineClick() : handleToggle()
},
Component: makeComponent(label, icon)
}
}
14 changes: 14 additions & 0 deletions src/modules/actions/divider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { forwardRef } from 'react'

import Divider from 'cozy-ui/transpiled/react/Divider'

export const hr = () => {
return {
name: 'hr',
icon: 'hr',
displayInSelectionBar: false,
Component: forwardRef(function hr(_, ref) {
return <Divider ref={ref} className="u-mv-half" />
})
}
}
51 changes: 51 additions & 0 deletions src/modules/actions/download.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { forwardRef } from 'react'

import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import Icon from 'cozy-ui/transpiled/react/Icon'
import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'

import { downloadFiles } from './utils'
import { isEncryptedFolder, isEncryptedFile } from 'lib/encryption'

const makeComponent = (label, icon) => {
const Component = forwardRef((props, ref) => {
return (
<ActionsMenuItem {...props} ref={ref}>
<ListItemIcon>
<Icon icon={icon} />
</ListItemIcon>
<ListItemText primary={label} />
</ActionsMenuItem>
)
})
Component.displayName = 'Download'

return Component
}

export const download = ({ client, t, vaultClient, showAlert }) => {
const label = t('SelectionBar.download')
const icon = DownloadIcon

return {
name: 'download',
label,
icon,
displayCondition: files => {
// We cannot generate archive for encrypted files, for now.
// 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)))
)
},
action: files => {
return downloadFiles(client, files, { vaultClient, showAlert, t })
},
Component: makeComponent(label, icon)
}
}
11 changes: 11 additions & 0 deletions src/modules/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { share } from './share'
export { download } from './download'
export { hr } from './divider'
export { trash } from './trash'
export { rename } from './rename'
export { qualify } from './qualify'
export { versions } from './versions'
export { restore } from './restore'
export { openExternalLink } from './openExternalLink'
export { select } from './select'
export { addItems } from './addItems'
258 changes: 0 additions & 258 deletions src/modules/actions/index.jsx

This file was deleted.

Loading
Loading