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

Read-write actions on public view #2017

Merged
merged 30 commits into from May 19, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f6eced
refactor: Moved Toolbar file
y-lohse Apr 21, 2020
8c56a17
refactor: Separate MoreMenu from Toolbar
y-lohse Apr 21, 2020
94be56a
refactor: Switch MoreMenu to ActionMenu
y-lohse Apr 27, 2020
c7dd42f
refactor: Migrate Trash MoreMenu
y-lohse Apr 27, 2020
1944efd
refactor: Removed old menu code
y-lohse Apr 28, 2020
4aadd0e
refactor: Shortcut menu item doesn't display the modal itself
y-lohse Apr 30, 2020
c172464
refactor: Make SelectableItem a real action menu item
y-lohse Apr 30, 2020
1d7da32
fix: ActionMenus close automatically
y-lohse May 7, 2020
4a222a3
fix: Enable rendering modals on public view
y-lohse May 7, 2020
a5cb33d
feat: Render file history on public view
y-lohse May 7, 2020
0e0a42d
refactor: Pass write permission to toolbar
y-lohse May 7, 2020
b40da3e
feat: New actions for files on public view
y-lohse May 7, 2020
896e7d1
feat: New toolbar for public view
y-lohse May 7, 2020
71ef983
fix: Avoid duplicate menu item in trash
y-lohse May 11, 2020
7a0ab75
fix: Fallback link to notes if no permissions
y-lohse May 11, 2020
5858716
refactor: Removed unused style
y-lohse May 11, 2020
347b53c
fix: Check write conditions on public actions
y-lohse May 12, 2020
82bf301
fix: Case sensitive file name
y-lohse May 12, 2020
9a98cd3
chore: Set test env variable
y-lohse May 12, 2020
49fb54c
chore: Use recent versions of node and yarn on android
y-lohse May 12, 2020
03b821a
feat: Upgrade cozy-sharings
y-lohse May 12, 2020
705bfd2
refactor: Make SharingProvider available to all public views
y-lohse May 12, 2020
8d12fec
fix: Add reloadView proptype
y-lohse May 15, 2020
fffb585
refactor: Removed useless translate HOC
y-lohse May 15, 2020
a605f32
docs: Added comment about realtime
y-lohse May 15, 2020
dfeb56e
refactor: Renamed props
y-lohse May 15, 2020
d6ed0df
feat: Reload public view after upload
y-lohse May 12, 2020
291d6f8
refactor: Only query notes app url if we have permissions
y-lohse May 12, 2020
6169bb6
refactor: Use permissions model fetchOwn
y-lohse May 12, 2020
06392ba
docs: Added missing doc string
y-lohse May 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -115,7 +115,7 @@
"cozy-scripts": "1.13.2",
"cozy-sharing": "1.9.1",
"cozy-stack-client": "13.5.2",
"cozy-ui": "35.9.0",
"cozy-ui": "35.17.0",
"date-fns": "1.30.1",
"diacritics": "1.3.0",
"fastclick": "1.0.6",
Expand Down
3 changes: 0 additions & 3 deletions src/drive/assets/icons/icon-checkbox-16.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/drive/assets/icons/icon-share-dark.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/drive/assets/icons/icon-trash-red.svg

This file was deleted.

3 changes: 0 additions & 3 deletions src/drive/assets/icons/icons-16-icon-note.svg

This file was deleted.

76 changes: 8 additions & 68 deletions src/drive/styles/toolbar.styl
Expand Up @@ -29,72 +29,12 @@
.fil-toolbar-trash
margin-left auto
display flex

.menu-recipients-wrapper
position relative

.menu-recipients
position absolute
right 0
top -.5rem

.fil-toolbar-menu
//!TODO Remove this code after upgrading to cozy-bar@6
button
svg
visibility: initial
display: initial
a
label
&.fil-action-upload
span[role=button]
display flex
padding-left 1rem
svg
margin-right .5rem

&.fil-action-newfolder
background embedurl('../assets/icons/icon-folder-add-16.svg') 1rem center no-repeat
&.fil-action-download
background embedurl("../assets/icons/icon-download-16.svg") 1rem center no-repeat
&.fil-action-select
background embedurl('../assets/icons/icon-checkbox-16.svg') 1rem center no-repeat
&.fil-action-delete
color var(--pomegranate)
background embedurl('../assets/icons/icon-trash-red.svg') 1rem center no-repeat
&.fil-action-share
position relative
background embedurl('../assets/icons/icon-share-dark.svg') 1rem center no-repeat
&.fil-action-create-note
background embedurl('../assets/icons/icons-16-icon-note.svg') 1rem center no-repeat
&.fil-action-create-shortcut
background embedurl('../assets/icons/icon-link.svg') 1rem center no-repeat
.fil-toolbar-menu-recipients
position absolute
right 1rem
top .1rem
.fil-action-share
display none
+medium-screen()
.fil-toolbar-menu
display block
left 1em
.fil-action-share
.fil-action-select
.fil-action-upload
display block
+tablet()
.fil-toolbar-menu-recipients
display none
+small-screen()
.fil-toolbar-inner-menu
position fixed
margin .5rem
width calc(100% - 1rem)
.fil-toolbar-files
.fil-toolbar-trash
position fixed
top 0
right 0
z-index $nav-index

.fil-public-download
display none
.fil-toolbar-menu
.fil-toolbar-menu-recipients
display inline-flex
+small-screen('min')
.fil-toolbar-menu--public
display none
23 changes: 16 additions & 7 deletions src/drive/targets/public/index.jsx
Expand Up @@ -10,13 +10,15 @@ import { RealtimePlugin } from 'cozy-realtime'

import { I18n, initTranslation } from 'cozy-ui/transpiled/react/I18n'
import Alerter from 'cozy-ui/transpiled/react/Alerter'
import SharingProvider from 'cozy-sharing'

import { getQueryParameter } from 'react-cozy-helpers'
import { schema } from 'drive/lib/doctypes'
import configureStore from 'drive/store/configureStore'
import PublicLayout from 'drive/web/modules/public/PublicLayout'
import LightFolderView from 'drive/web/modules/public/LightFolderView'
import LightFileViewer from 'drive/web/modules/public/LightFileViewer'
import FileHistory from 'components/FileHistory'
import ErrorShare from 'components/Error/ErrorShare'
import { configureReporter, setCozyUrl } from 'drive/lib/reporter'
import getSharedDocument from 'cozy-sharing/dist/getSharedDocument'
Expand Down Expand Up @@ -107,13 +109,20 @@ const init = async () => {
<LightFileViewer files={[data]} isFile={true} />
</PublicLayout>
) : (
<Router history={hashHistory}>
<Route component={PublicLayout}>
<Route path="files(/:folderId)" component={LightFolderView} />
</Route>
<Route path="external/:fileId" component={ExternalRedirect} />
<Redirect from="/*" to={`files/${sharedDocumentId}`} />
</Router>
<SharingProvider>
<Router history={hashHistory}>
<Route component={PublicLayout}>
<Route path="files(/:folderId)" component={LightFolderView}>
<Route
path="file/:fileId/revision"
component={FileHistory}
/>
</Route>
</Route>
<Route path="external/:fileId" component={ExternalRedirect} />
<Redirect from="/*" to={`files/${sharedDocumentId}`} />
</Router>
</SharingProvider>
y-lohse marked this conversation as resolved.
Show resolved Hide resolved
)}
</App>,
root
Expand Down
Expand Up @@ -9,29 +9,17 @@ import withBreakpoints from 'cozy-ui/transpiled/react/helpers/withBreakpoints'

import BarContextProvider from 'cozy-ui/transpiled/react/BarContextProvider'
import { withClient } from 'cozy-client'
import { isMobileApp } from 'cozy-device-helper'

import { MoreButton } from 'components/Button'
import Menu, { Item } from 'components/Menu'

import { isSelectionBarVisible } from 'drive/web/modules/selection/duck'

import styles from 'drive/styles/toolbar.styl'

import NotRootFolder from 'drive/web/modules/drive/Toolbar/components/NotRootFolder'

import DeleteItem from './Toolbar/delete/DeleteItem'
import SelectableItem from './Toolbar/selectable/SelectableItem'
import AddFolderItem from './Toolbar/components/AddFolderItem'
import UploadItem from './Toolbar/components/UploadItem'
import CreateNoteItem from './Toolbar/components/CreateNoteItem'
import CreateShortcut from './Toolbar/components/CreateShortcut'
import UploadButtonItem from './components/UploadButtonItem'
import MoreMenu from './components/MoreMenu'

import DownloadButtonItem from './Toolbar/components/DownloadButtonItem'
import ShareItem from './Toolbar/share/ShareItem'
import ShareButton from './Toolbar/share/ShareButton'
import SharedRecipients from './Toolbar/share/SharedRecipients'
import ScanWrapper from './Toolbar/components/ScanWrapper'
import ShareButton from './share/ShareButton'
import SharedRecipients from './share/SharedRecipients'

class Toolbar extends Component {
static contextTypes = {
Expand All @@ -54,72 +42,6 @@ class Toolbar extends Component {
const isDisabled = disabled || selectionModeActive
const { BarRight } = cozy.bar

const MoreMenu = (
<Menu
title={t('toolbar.item_more')}
disabled={isDisabled}
className={styles['fil-toolbar-menu']}
innerClassName={styles['fil-toolbar-inner-menu']}
button={<MoreButton />}
>
{canCreateFolder &&
hasWriteAccess && (
<Item>
<AddFolderItem />
</Item>
)}
{hasWriteAccess && (
<Item>
<CreateNoteItem />
</Item>
)}
{hasWriteAccess && (
<Item>
<CreateShortcut />
</Item>
)}
{canUpload &&
hasWriteAccess && (
<Item>
<UploadItem insideMoreMenu disabled={isDisabled} />
</Item>
)}
{isMobileApp() &&
canUpload &&
hasWriteAccess && (
<Item>
<ScanWrapper insideMoreMenu disabled={isDisabled} />
</Item>
)}
{hasWriteAccess && <hr />}
<NotRootFolder>
<Item>
<ShareItem />
</Item>
</NotRootFolder>
<NotRootFolder>
<Item>
<DownloadButtonItem />
</Item>
</NotRootFolder>
<Item>
<SelectableItem>
<a className={styles['fil-action-select']}>
{t('toolbar.menu_select')}
</a>
</SelectableItem>
</Item>
{hasWriteAccess && (
<NotRootFolder>
<hr />
<Item>
<DeleteItem />
</Item>
</NotRootFolder>
)}
</Menu>
)

return (
<div
data-test-id="fil-toolbar-files"
Expand All @@ -128,7 +50,7 @@ class Toolbar extends Component {
>
{!isShared &&
canUpload &&
hasWriteAccess && <UploadItem disabled={isDisabled} />}
hasWriteAccess && <UploadButtonItem disabled={isDisabled} />}
<NotRootFolder>
<SharedRecipients />
</NotRootFolder>
Expand All @@ -145,12 +67,22 @@ class Toolbar extends Component {
lang={lang}
>
<SharingProvider doctype="io.cozy.files" documentType="Files">
{MoreMenu}
<MoreMenu
isDisabled={isDisabled}
canCreateFolder={canCreateFolder}
canUpload={canUpload}
hasWriteAccess={hasWriteAccess}
/>
</SharingProvider>
</BarContextProvider>
</BarRight>
) : (
MoreMenu
<MoreMenu
isDisabled={isDisabled}
canCreateFolder={canCreateFolder}
canUpload={canUpload}
hasWriteAccess={hasWriteAccess}
/>
)}
</div>
)
Expand Down
@@ -1,18 +1,19 @@
import React from 'react'
import { connect } from 'react-redux'
import { translate } from 'cozy-ui/transpiled/react/I18n'
import styles from 'drive/styles/toolbar.styl'
import { showNewFolderInput } from 'drive/web/modules/filelist/duck'
import { ActionMenuItem } from 'cozy-ui/transpiled/react/ActionMenu'
import Icon from 'cozy-ui/transpiled/react/Icon'

const AddFolderItem = translate()(({ t, addFolder }) => {
return (
<a
<ActionMenuItem
data-test-id="add-folder-link"
className={styles['fil-action-newfolder']}
onClick={addFolder}
left={<Icon icon="folder-add" />}
>
{t('toolbar.menu_new_folder')}
</a>
</ActionMenuItem>
)
})
const mapDispatchToProps = dispatch => ({
Expand Down
38 changes: 27 additions & 11 deletions src/drive/web/modules/drive/Toolbar/components/CreateNoteItem.jsx
Expand Up @@ -8,21 +8,37 @@ import {
useAppLinkWithStoreFallback,
useCapabilities
} from 'cozy-client'
import { generateUniversalLink } from 'cozy-ui/transpiled/react/AppLinker/native'
import {
generateUniversalLink,
generateWebLink
} from 'cozy-ui/transpiled/react/AppLinker/native'
import { ActionMenuItem } from 'cozy-ui/transpiled/react/ActionMenu'
import Icon from 'cozy-ui/transpiled/react/Icon'

import toolbarContainer from 'drive/web/modules/drive/Toolbar/toolbar'
import styles from 'drive/styles/toolbar.styl'

const CreateNoteItem = ({ client, t, displayedFolder }) => {
const { fetchStatus, url, isInstalled } = useAppLinkWithStoreFallback(
'notes',
client
)
const capabilities = useCapabilities(client)
const isFlatDomain = get(
capabilities,
'capabilities.data.attributes.flat_subdomains'
)

let notesAppUrl = ''
const { fetchStatus, url, isInstalled } = useAppLinkWithStoreFallback(
'notes',
client
)
if (fetchStatus === 'loaded') {
notesAppUrl = url
} else if (fetchStatus === 'errored') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the commit message is explicit enough, but on the public page we don't have permissions to query the list of apps, and this is one of the only places where we really need it. I think the fallback to a generated link is ok, the only issue is if the notes app is not installed, then we won't have a link to the store.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if click on the button with no network?

Can't we do a check if we're in a public context or not?

(and no the commit was not self explaining, maybe you can add your comment to it ;))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if click on the button with no network?

It will try to open notes :/.

Can't we do a check if we're in a public context or not?

Yep, we can! The offline behavior would be the same though. But it's probably a better solution.

(and no the commit was not self explaining, maybe you can add your comment to it ;))

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @poupotte pour info ;)

notesAppUrl = returnUrl = generateWebLink({
slug: 'notes',
cozyUrl: client.getStackClient().uri,
subDomainType: isFlatDomain ? 'flat' : 'nested'
})
}

let returnUrl = ''
if (displayedFolder) {
returnUrl = generateUniversalLink({
Expand All @@ -34,9 +50,9 @@ const CreateNoteItem = ({ client, t, displayedFolder }) => {
}

return (
<a
<ActionMenuItem
data-test-id="create-a-note"
className={styles['fil-action-create-note']}
left={<Icon icon="note" />}
onClick={async () => {
if (!fetchStatus) return
if (isInstalled) {
Expand All @@ -45,17 +61,17 @@ const CreateNoteItem = ({ client, t, displayedFolder }) => {
})

window.location.href = await models.note.generatePrivateUrl(
url,
notesAppUrl,
file,
{ returnUrl }
)
} else {
window.location.href = url
window.location.href = notesAppUrl
}
}}
>
{t('toolbar.menu_create_note')}
</a>
</ActionMenuItem>
)
}

Expand Down