cozy-sharing 5.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +80 -0
- package/dist/SharedRecipients.js +1 -1
- package/dist/SharedStatus.js +1 -1
- package/dist/SharingBanner/hooks/useSharingInfos.js +1 -1
- package/dist/SharingDetailsModal.js +1 -1
- package/dist/SharingOwnerAvatar.js +1 -1
- package/dist/SharingProvider.js +21 -8
- package/dist/components/ConfirmTrustedRecipientsDialog.js +1 -1
- package/dist/components/ContactSuggestion.js +15 -27
- package/dist/components/EditLinkPermissionDialog.js +72 -0
- package/dist/components/EditLinkPermissionDialog.spec.js +48 -0
- package/dist/components/EditableSharingModal.js +15 -62
- package/dist/components/{AvatarPlusX.js → Recipient/AvatarPlusX.js} +1 -1
- package/dist/components/{Identity.js → Recipient/Identity.js} +17 -16
- package/dist/components/Recipient/LinkRecipient.js +72 -0
- package/dist/components/Recipient/LinkRecipientPermissions.js +159 -0
- package/dist/components/Recipient/OwnerIdentity.js +44 -0
- package/dist/components/Recipient/Recipient.js +72 -0
- package/dist/components/{Recipient.spec.js → Recipient/Recipient.spec.js} +4 -45
- package/dist/components/Recipient/RecipientAvatar.js +33 -0
- package/dist/components/Recipient/RecipientConfirm.js +63 -0
- package/dist/components/Recipient/RecipientPermissions.js +126 -0
- package/dist/components/Recipient/RecipientPlusX.js +45 -0
- package/dist/components/Recipient/RecipientStatus.js +64 -0
- package/dist/components/Recipient/RecipientWithoutStatus.js +45 -0
- package/dist/components/Recipient/RecipientsAvatars.js +100 -0
- package/dist/components/{RecipientsAvatars.spec.js → Recipient/RecipientsAvatars.spec.js} +43 -2
- package/dist/components/{recipient.styl → Recipient/recipient.styl} +6 -2
- package/dist/components/ShareAutosuggest.js +176 -252
- package/dist/components/ShareAutosuggest.spec.js +3 -2
- package/dist/components/ShareByEmail.js +142 -193
- package/dist/components/ShareByEmail.spec.js +42 -23
- package/dist/components/ShareByLink.js +251 -357
- package/dist/components/ShareDialogCozyToCozy.js +16 -4
- package/dist/components/ShareDialogCozyToCozy.spec.js +12 -1
- package/dist/components/ShareDialogOnlyByLink.js +23 -10
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +7 -7
- package/dist/components/ShareModal.js +5 -1
- package/dist/components/ShareRecipientsInput.js +44 -128
- package/dist/components/WhoHasAccess.js +43 -5
- package/dist/components/WhoHasAccessLight.js +3 -19
- package/dist/components/autosuggest.styl +21 -36
- package/dist/helpers/documentType.js +6 -0
- package/dist/helpers/hooks.js +8 -1
- package/dist/helpers/link.js +5 -0
- package/dist/helpers/permissions.js +8 -0
- package/dist/helpers/recipients.js +24 -0
- package/dist/helpers/sharings.js +72 -53
- package/dist/helpers/synchronousJobQueue.js +67 -0
- package/dist/helpers/synchronousJobQueue.spec.js +97 -0
- package/dist/index.js +2 -1
- package/dist/queries/queries.js +72 -0
- package/dist/share.styl +0 -15
- package/dist/stylesheet.css +67 -92
- package/locales/en.json +29 -41
- package/locales/fr.json +26 -39
- package/package.json +10 -10
- package/src/SharedRecipients.jsx +1 -1
- package/src/SharedStatus.jsx +1 -1
- package/src/SharingBanner/hooks/useSharingInfos.jsx +1 -1
- package/src/SharingDetailsModal.jsx +1 -1
- package/src/SharingOwnerAvatar.jsx +1 -1
- package/src/SharingProvider.jsx +17 -4
- package/src/components/ConfirmTrustedRecipientsDialog.jsx +1 -1
- package/src/components/ContactSuggestion.jsx +25 -10
- package/src/components/EditLinkPermissionDialog.jsx +89 -0
- package/src/components/EditLinkPermissionDialog.spec.jsx +52 -0
- package/src/components/EditableSharingModal.jsx +58 -100
- package/src/components/{AvatarPlusX.jsx → Recipient/AvatarPlusX.jsx} +1 -1
- package/src/components/{Identity.jsx → Recipient/Identity.jsx} +0 -0
- package/src/components/Recipient/LinkRecipient.jsx +59 -0
- package/src/components/Recipient/LinkRecipientPermissions.jsx +157 -0
- package/src/components/Recipient/OwnerIdentity.jsx +20 -0
- package/src/components/Recipient/Recipient.jsx +79 -0
- package/src/components/{Recipient.spec.jsx → Recipient/Recipient.spec.jsx} +4 -42
- package/src/components/Recipient/RecipientAvatar.jsx +38 -0
- package/src/components/Recipient/RecipientConfirm.jsx +37 -0
- package/src/components/Recipient/RecipientPermissions.jsx +114 -0
- package/src/components/Recipient/RecipientPlusX.jsx +28 -0
- package/src/components/Recipient/RecipientStatus.jsx +48 -0
- package/src/components/Recipient/RecipientWithoutStatus.jsx +21 -0
- package/src/components/Recipient/RecipientsAvatars.jsx +108 -0
- package/src/components/{RecipientsAvatars.spec.jsx → Recipient/RecipientsAvatars.spec.jsx} +43 -2
- package/src/components/{recipient.styl → Recipient/recipient.styl} +6 -2
- package/src/components/ShareAutosuggest.jsx +136 -127
- package/src/components/ShareAutosuggest.spec.jsx +12 -8
- package/src/components/ShareByEmail.jsx +65 -90
- package/src/components/ShareByEmail.spec.jsx +39 -11
- package/src/components/ShareByLink.jsx +146 -238
- package/src/components/ShareDialogCozyToCozy.jsx +14 -2
- package/src/components/ShareDialogCozyToCozy.spec.jsx +8 -1
- package/src/components/ShareDialogOnlyByLink.jsx +30 -13
- package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +5 -5
- package/src/components/ShareModal.jsx +5 -1
- package/src/components/ShareRecipientsInput.jsx +30 -44
- package/src/components/WhoHasAccess.jsx +85 -27
- package/src/components/WhoHasAccessLight.jsx +2 -1
- package/src/components/__snapshots__/ContactSuggestion.spec.jsx.snap +915 -132
- package/src/components/__snapshots__/ShareRecipientsInput.spec.jsx.snap +86 -102
- package/src/components/autosuggest.styl +21 -36
- package/src/helpers/documentType.js +6 -0
- package/src/helpers/hooks.js +11 -1
- package/src/helpers/link.js +4 -0
- package/src/helpers/permissions.js +15 -0
- package/src/helpers/recipients.js +21 -0
- package/src/helpers/sharings.js +15 -12
- package/src/helpers/synchronousJobQueue.js +22 -0
- package/src/helpers/synchronousJobQueue.spec.js +75 -0
- package/src/index.jsx +1 -0
- package/src/queries/queries.js +75 -0
- package/src/share.styl +0 -15
- package/dist/SharingBanner/helpers/queries.js +0 -12
- package/dist/components/ContactsAndGroupsDataLoader.js +0 -50
- package/dist/components/Recipient.js +0 -450
- package/src/SharingBanner/helpers/queries.js +0 -14
- package/src/components/ContactsAndGroupsDataLoader.jsx +0 -30
- package/src/components/Recipient.jsx +0 -415
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import get from 'lodash/get'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useClient } from 'cozy-client'
|
|
6
|
+
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
|
|
6
7
|
import Alerter from 'cozy-ui/transpiled/react/Alerter'
|
|
7
|
-
import { translate } from 'cozy-ui/transpiled/react/I18n'
|
|
8
8
|
|
|
9
9
|
import ShareSubmit from './Sharesubmit'
|
|
10
10
|
import ShareTypeSelect from './Sharetypeselect'
|
|
@@ -16,38 +16,38 @@ import styles from '../share.styl'
|
|
|
16
16
|
import { getSuccessMessage } from '../helpers/successMessage'
|
|
17
17
|
import { getOrCreateFromArray } from '../helpers/contacts'
|
|
18
18
|
import { isReadOnlySharing } from '../state'
|
|
19
|
-
export class ShareByEmail extends Component {
|
|
20
|
-
constructor(props) {
|
|
21
|
-
super(props)
|
|
22
|
-
this.initialState = {
|
|
23
|
-
recipients: [],
|
|
24
|
-
loading: false
|
|
25
|
-
}
|
|
26
|
-
this.state = { ...this.initialState }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
state = { ...this.initialState }
|
|
30
19
|
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
export const ShareByEmail = ({
|
|
21
|
+
contacts,
|
|
22
|
+
groups,
|
|
23
|
+
document,
|
|
24
|
+
sharingDesc,
|
|
25
|
+
onShare,
|
|
26
|
+
createContact,
|
|
27
|
+
documentType,
|
|
28
|
+
currentRecipients,
|
|
29
|
+
sharing
|
|
30
|
+
}) => {
|
|
31
|
+
const client = useClient()
|
|
32
|
+
const { t } = useI18n()
|
|
33
|
+
const [recipients, setRecipients] = useState([])
|
|
34
|
+
const [loading, setLoading] = useState(false)
|
|
35
|
+
const [selectedOption, setSelectedOption] = useState()
|
|
36
|
+
|
|
37
|
+
const reset = () => {
|
|
38
|
+
setRecipients([])
|
|
39
|
+
setLoading(false)
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
onChange = value => {
|
|
36
|
-
|
|
37
|
-
...state,
|
|
38
|
-
selectedOption: value
|
|
39
|
-
}))
|
|
42
|
+
const onChange = value => {
|
|
43
|
+
setSelectedOption(value)
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
this.sendSharingLink()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
onRecipientPick = recipient => {
|
|
46
|
+
const onRecipientPick = recipient => {
|
|
47
47
|
let contactsToAdd
|
|
48
48
|
if (recipient._type === Group.doctype) {
|
|
49
49
|
const groupId = recipient.id
|
|
50
|
-
contactsToAdd =
|
|
50
|
+
contactsToAdd = contacts.data.filter(contact => {
|
|
51
51
|
const contactGroupIds = get(
|
|
52
52
|
contact,
|
|
53
53
|
'relationships.groups.data',
|
|
@@ -66,45 +66,26 @@ export class ShareByEmail extends Component {
|
|
|
66
66
|
(contact.email && contact.email.length > 0) ||
|
|
67
67
|
(contact.cozy && contact.cozy.length > 0)
|
|
68
68
|
)
|
|
69
|
-
.filter(contact => !
|
|
69
|
+
.filter(contact => !recipients.find(r => r === contact))
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
...state,
|
|
73
|
-
recipients: [...state.recipients, ...filtered]
|
|
74
|
-
}))
|
|
71
|
+
setRecipients([...recipients, ...filtered])
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
onRecipientRemove = recipient => {
|
|
78
|
-
const idx =
|
|
79
|
-
|
|
80
|
-
...state,
|
|
81
|
-
recipients: [
|
|
82
|
-
...state.recipients.slice(0, idx),
|
|
83
|
-
...state.recipients.slice(idx + 1)
|
|
84
|
-
]
|
|
85
|
-
}))
|
|
74
|
+
const onRecipientRemove = recipient => {
|
|
75
|
+
const idx = recipients.findIndex(r => r === recipient)
|
|
76
|
+
setRecipients([...recipients.slice(0, idx), ...recipients.slice(idx + 1)])
|
|
86
77
|
}
|
|
87
78
|
|
|
88
|
-
share = async () => {
|
|
89
|
-
const {
|
|
90
|
-
document,
|
|
91
|
-
sharingDesc,
|
|
92
|
-
onShare,
|
|
93
|
-
createContact,
|
|
94
|
-
documentType,
|
|
95
|
-
client,
|
|
96
|
-
t
|
|
97
|
-
} = this.props
|
|
98
|
-
const { recipients, selectedOption } = this.state
|
|
79
|
+
const share = async () => {
|
|
99
80
|
if (recipients.length === 0) {
|
|
100
81
|
return
|
|
101
82
|
}
|
|
102
83
|
|
|
103
84
|
// we can't use currentRecipients prop in getSuccessMessage because it may use
|
|
104
85
|
// the updated prop to count the new recipients
|
|
105
|
-
const recipientsBefore =
|
|
86
|
+
const recipientsBefore = currentRecipients
|
|
106
87
|
|
|
107
|
-
|
|
88
|
+
setLoading(true)
|
|
108
89
|
try {
|
|
109
90
|
const contacts = await getOrCreateFromArray(
|
|
110
91
|
client,
|
|
@@ -129,16 +110,15 @@ export class ShareByEmail extends Component {
|
|
|
129
110
|
Alerter.success(
|
|
130
111
|
t(...getSuccessMessage(recipientsBefore, contacts, documentType))
|
|
131
112
|
)
|
|
132
|
-
|
|
113
|
+
reset()
|
|
133
114
|
} catch (err) {
|
|
134
115
|
Alerter.error('Error.generic')
|
|
135
|
-
|
|
116
|
+
reset()
|
|
136
117
|
throw err
|
|
137
118
|
}
|
|
138
119
|
}
|
|
139
120
|
|
|
140
|
-
getSharingOptions = () => {
|
|
141
|
-
const { t, sharing, document } = this.props
|
|
121
|
+
const getSharingOptions = () => {
|
|
142
122
|
const isSharingReadOnly = sharing
|
|
143
123
|
? isReadOnlySharing(sharing, document._id)
|
|
144
124
|
: false
|
|
@@ -156,43 +136,38 @@ export class ShareByEmail extends Component {
|
|
|
156
136
|
}
|
|
157
137
|
return isSharingReadOnly ? [readOnly] : [readWrite, readOnly]
|
|
158
138
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
<div className={styles['coz-form
|
|
165
|
-
<
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
/>
|
|
180
|
-
</div>
|
|
139
|
+
|
|
140
|
+
const showShareControl = recipients.length > 0
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div className={styles['coz-form-group']}>
|
|
144
|
+
<div className={styles['coz-form']}>
|
|
145
|
+
<ShareRecipientsInput
|
|
146
|
+
placeholder={
|
|
147
|
+
recipients.length === 0
|
|
148
|
+
? t(`${documentType}.share.shareByEmail.emailPlaceholder`)
|
|
149
|
+
: ''
|
|
150
|
+
}
|
|
151
|
+
onPick={recipient => onRecipientPick(recipient)}
|
|
152
|
+
onRemove={recipient => onRecipientRemove(recipient)}
|
|
153
|
+
contacts={contacts}
|
|
154
|
+
groups={groups}
|
|
155
|
+
recipients={recipients}
|
|
156
|
+
/>
|
|
157
|
+
</div>
|
|
158
|
+
{showShareControl && (
|
|
181
159
|
<div className={styles['share-type-control']}>
|
|
182
|
-
<ShareTypeSelect
|
|
183
|
-
options={this.getSharingOptions()}
|
|
184
|
-
onChange={this.onChange}
|
|
185
|
-
/>
|
|
160
|
+
<ShareTypeSelect options={getSharingOptions()} onChange={onChange} />
|
|
186
161
|
<ShareSubmit
|
|
187
162
|
label={t(`${documentType}.share.shareByEmail.send`)}
|
|
188
|
-
onSubmit={
|
|
189
|
-
loading={
|
|
163
|
+
onSubmit={share}
|
|
164
|
+
loading={loading}
|
|
190
165
|
disabled={recipients.length === 0}
|
|
191
166
|
/>
|
|
192
167
|
</div>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
)
|
|
196
171
|
}
|
|
197
172
|
|
|
198
173
|
ShareByEmail.propTypes = {
|
|
@@ -208,4 +183,4 @@ ShareByEmail.propTypes = {
|
|
|
208
183
|
sharing: PropTypes.object
|
|
209
184
|
}
|
|
210
185
|
|
|
211
|
-
export default
|
|
186
|
+
export default ShareByEmail
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { render, fireEvent, waitFor } from '@testing-library/react'
|
|
3
3
|
import { ShareByEmail } from './ShareByEmail'
|
|
4
|
+
import AppLike from '../../test/AppLike'
|
|
5
|
+
import { act } from 'react-dom/test-utils'
|
|
6
|
+
|
|
7
|
+
jest.mock('../helpers/contacts', () => ({
|
|
8
|
+
getOrCreateFromArray: (client, recipients) => recipients
|
|
9
|
+
}))
|
|
4
10
|
|
|
5
11
|
describe('ShareByEmailComponent', () => {
|
|
6
12
|
it('shoud call share if submited', async () => {
|
|
@@ -9,7 +15,6 @@ describe('ShareByEmailComponent', () => {
|
|
|
9
15
|
contacts: {
|
|
10
16
|
data: []
|
|
11
17
|
},
|
|
12
|
-
t: x => x,
|
|
13
18
|
groups: { data: [] },
|
|
14
19
|
documentType: 'Files',
|
|
15
20
|
onShare: onShare,
|
|
@@ -19,15 +24,38 @@ describe('ShareByEmailComponent', () => {
|
|
|
19
24
|
sharingDesc: 'test',
|
|
20
25
|
createContact: jest.fn()
|
|
21
26
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const root = render(
|
|
28
|
+
<AppLike>
|
|
29
|
+
<ShareByEmail {...props} />
|
|
30
|
+
</AppLike>
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
act(() => {
|
|
34
|
+
fireEvent.change(root.getByPlaceholderText('Add contacts or groups'), {
|
|
35
|
+
target: { value: 'quentin@cozycloud.cc' }
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
act(() => {
|
|
40
|
+
fireEvent.keyPress(root.getByPlaceholderText('Add contacts or groups'), {
|
|
41
|
+
key: 'Enter',
|
|
42
|
+
code: 'Enter',
|
|
43
|
+
charCode: 13
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
act(() => {
|
|
48
|
+
fireEvent.click(root.getByRole('button', { name: 'Send' }))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
await waitFor(() => {
|
|
52
|
+
expect(onShare).toHaveBeenCalledWith({
|
|
53
|
+
description: props.sharingDesc,
|
|
54
|
+
document: props.document,
|
|
55
|
+
openSharing: true,
|
|
56
|
+
readOnlyRecipients: [],
|
|
57
|
+
recipients: [{ email: 'quentin@cozycloud.cc' }]
|
|
58
|
+
})
|
|
31
59
|
})
|
|
32
60
|
})
|
|
33
61
|
})
|