cozy-sharing 31.0.2 → 31.2.0

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/FederatedFolder/DumbFederatedFolderModal.js +15 -16
  3. package/dist/components/FederatedFolder/FederatedFolderModal.js +78 -103
  4. package/dist/components/FederatedFolder/FederatedFolderModal.spec.js +102 -292
  5. package/dist/components/Recipient/GroupRecipientPermissions.js +15 -11
  6. package/dist/components/Recipient/LinkRecipient.js +15 -11
  7. package/dist/components/Recipient/LinkRecipientLite.js +1 -1
  8. package/dist/components/Recipient/LinkRecipientPermissions.js +2 -1
  9. package/dist/components/Recipient/MemberRecipient.spec.js +8 -10
  10. package/dist/components/Recipient/MemberRecipientLite.js +1 -1
  11. package/dist/components/Recipient/MemberRecipientPermissions.js +16 -12
  12. package/dist/components/Recipient/MemberRecipientPermissions.spec.js +62 -50
  13. package/dist/components/Recipient/RecipientConfirm.js +0 -5
  14. package/dist/components/ShareAutosuggest.js +9 -4
  15. package/dist/components/ShareByEmail.js +29 -274
  16. package/dist/components/ShareByEmail.spec.js +52 -230
  17. package/dist/components/ShareByLink.js +1 -3
  18. package/dist/components/ShareDialogCozyToCozy.js +169 -35
  19. package/dist/components/ShareDialogCozyToCozy.spec.js +123 -36
  20. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +13 -3
  21. package/dist/components/ShareModal/SharingDetailsModal.js +0 -5
  22. package/dist/components/ShareRecipientsInput.js +6 -3
  23. package/dist/components/SharedDrive/SharedDriveForm.js +17 -25
  24. package/dist/components/SharedDrive/SharedDriveModal.js +1 -1
  25. package/dist/components/SharedDrive/SharedDriveRecipientPermissions.js +15 -10
  26. package/dist/components/SharedDrive/useSharedDrive.js +33 -57
  27. package/dist/components/SharedDrive/useSharedDrive.spec.js +29 -93
  28. package/dist/components/SharedFolder/DumbBatchSharedFolderModal.js +15 -26
  29. package/dist/components/Sharetypeselect.js +85 -90
  30. package/dist/hooks/usePendingRecipients.js +20 -0
  31. package/dist/hooks/usePendingRecipients.spec.js +30 -0
  32. package/dist/styles/autosuggest.styl +8 -2
  33. package/dist/styles/share.styl +0 -39
  34. package/dist/stylesheet.css +8 -36
  35. package/locales/en.json +14 -44
  36. package/locales/fr.json +14 -44
  37. package/locales/ru.json +14 -44
  38. package/locales/vi.json +14 -42
  39. package/package.json +2 -2
  40. package/src/components/FederatedFolder/DumbFederatedFolderModal.jsx +14 -15
  41. package/src/components/FederatedFolder/FederatedFolderModal.jsx +50 -67
  42. package/src/components/FederatedFolder/FederatedFolderModal.spec.jsx +63 -186
  43. package/src/components/Recipient/GroupRecipientPermissions.jsx +15 -13
  44. package/src/components/Recipient/LinkRecipient.jsx +9 -9
  45. package/src/components/Recipient/LinkRecipientLite.jsx +1 -3
  46. package/src/components/Recipient/LinkRecipientPermissions.jsx +2 -1
  47. package/src/components/Recipient/MemberRecipient.spec.jsx +4 -6
  48. package/src/components/Recipient/MemberRecipientLite.jsx +2 -2
  49. package/src/components/Recipient/MemberRecipientPermissions.jsx +16 -21
  50. package/src/components/Recipient/MemberRecipientPermissions.spec.jsx +21 -23
  51. package/src/components/ShareAutosuggest.jsx +7 -2
  52. package/src/components/ShareByEmail.jsx +35 -186
  53. package/src/components/ShareByEmail.spec.jsx +22 -173
  54. package/src/components/ShareByLink.jsx +1 -7
  55. package/src/components/ShareDialogCozyToCozy.jsx +171 -38
  56. package/src/components/ShareDialogCozyToCozy.spec.jsx +67 -1
  57. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +11 -1
  58. package/src/components/ShareRecipientsInput.jsx +5 -2
  59. package/src/components/SharedDrive/SharedDriveForm.jsx +16 -25
  60. package/src/components/SharedDrive/SharedDriveModal.jsx +1 -1
  61. package/src/components/SharedDrive/SharedDriveRecipientPermissions.jsx +15 -17
  62. package/src/components/SharedDrive/useSharedDrive.js +24 -50
  63. package/src/components/SharedDrive/useSharedDrive.spec.js +19 -67
  64. package/src/components/SharedFolder/DumbBatchSharedFolderModal.jsx +15 -29
  65. package/src/components/Sharetypeselect.jsx +75 -58
  66. package/src/hooks/usePendingRecipients.js +13 -0
  67. package/src/hooks/usePendingRecipients.spec.js +21 -0
  68. package/src/styles/autosuggest.styl +8 -2
  69. package/src/styles/share.styl +0 -39
  70. package/dist/components/Recipient/actions/revokeGroup.js +0 -42
  71. package/dist/components/Recipient/actions/revokeMember.js +0 -42
  72. package/dist/components/Recipient/actions/revokeSharedDriveMember.js +0 -41
  73. package/dist/components/SharedDrive/helpers.js +0 -102
  74. package/dist/components/SharedDrive/helpers.spec.js +0 -227
  75. package/dist/components/Sharesubmit.js +0 -28
  76. package/src/components/Recipient/actions/revokeGroup.js +0 -42
  77. package/src/components/Recipient/actions/revokeMember.js +0 -42
  78. package/src/components/Recipient/actions/revokeSharedDriveMember.js +0 -41
  79. package/src/components/SharedDrive/helpers.js +0 -108
  80. package/src/components/SharedDrive/helpers.spec.js +0 -177
  81. package/src/components/Sharesubmit.jsx +0 -31
@@ -1,20 +1,11 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- import _regeneratorRuntime from "@babel/runtime/regenerator";
5
2
  import PropTypes from 'prop-types';
6
- import React, { useState } from 'react';
7
- import { useClient } from 'cozy-client';
3
+ import React from 'react';
8
4
  import flag from 'cozy-flags';
9
- import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
10
5
  import { useI18n } from 'twake-i18n';
11
6
  import ShareRecipientsInput from './ShareRecipientsInput';
12
- import { ShareRecipientsLimitModal } from './ShareRecipientsLimitModal';
13
- import ShareSubmit from './Sharesubmit';
14
7
  import ShareTypeSelect from './Sharetypeselect';
15
- import { getOrCreateFromArray } from '../helpers/contacts';
16
- import { mergeRecipients, spreadGroupAndMergeRecipients, hasReachRecipientsLimit } from '../helpers/recipients';
17
- import { getSuccessMessage, getErrorMessage } from '../helpers/share';
8
+ import { mergeRecipients, spreadGroupAndMergeRecipients } from '../helpers/recipients';
18
9
  import { isReadOnlySharing } from '../state';
19
10
  var styles = {
20
11
  "share-modal-content": "share__share-modal-content___1iqEq",
@@ -30,309 +21,73 @@ var styles = {
30
21
  "error": "share__error___pwqPO",
31
22
  "share-byemail-onlybylink": "share__share-byemail-onlybylink___29W-t",
32
23
  "aligned-dropdown-button": "share__aligned-dropdown-button___3crgG",
33
- "share-type-control": "share__share-type-control___1YoRr",
34
- "select-wrapper": "share__select-wrapper___3XBKC",
35
- "select-option": "share__select-option___3Jp8_",
36
- "select-option-label": "share__select-option-label___1BWz_",
37
- "select-option-desc": "share__select-option-desc___3jOnr",
38
24
  "share-details-created": "share__share-details-created___z3nvO",
39
25
  "share-details-perm": "share__share-details-perm___3HjxK",
40
26
  "share-details-perm-desc": "share__share-details-perm-desc___3HyHu"
41
27
  };
42
28
  export var ShareByEmail = function ShareByEmail(_ref) {
43
29
  var document = _ref.document,
44
- sharingDesc = _ref.sharingDesc,
45
- onShare = _ref.onShare,
46
- createContact = _ref.createContact,
47
30
  documentType = _ref.documentType,
48
31
  currentRecipients = _ref.currentRecipients,
49
- sharing = _ref.sharing,
50
- submitLabel = _ref.submitLabel,
51
- _ref$showNotification = _ref.showNotifications,
52
- showNotifications = _ref$showNotification === void 0 ? true : _ref$showNotification,
53
- _ref$sharedDrive = _ref.sharedDrive,
54
- sharedDrive = _ref$sharedDrive === void 0 ? false : _ref$sharedDrive;
55
- var client = useClient();
32
+ pendingRecipients = _ref.pendingRecipients,
33
+ onPendingRecipientsChange = _ref.onPendingRecipientsChange,
34
+ selectedOption = _ref.selectedOption,
35
+ onSelectedOptionChange = _ref.onSelectedOptionChange,
36
+ sharing = _ref.sharing;
56
37
 
57
38
  var _useI18n = useI18n(),
58
39
  t = _useI18n.t;
59
40
 
60
- var _useAlert = useAlert(),
61
- showAlert = _useAlert.showAlert;
62
-
63
- var isFederatedMode = flag('drive.federated-shared-folder.enabled');
64
-
65
- var _useState = useState([]),
66
- _useState2 = _slicedToArray(_useState, 2),
67
- recipients = _useState2[0],
68
- setRecipients = _useState2[1];
69
-
70
- var _useState3 = useState(false),
71
- _useState4 = _slicedToArray(_useState3, 2),
72
- loading = _useState4[0],
73
- setLoading = _useState4[1];
74
-
75
- var _useState5 = useState('readWrite'),
76
- _useState6 = _slicedToArray(_useState5, 2),
77
- selectedOption = _useState6[0],
78
- setSelectedOption = _useState6[1];
79
-
80
- var _useState7 = useState(false),
81
- _useState8 = _slicedToArray(_useState7, 2),
82
- showRecipientsLimit = _useState8[0],
83
- setRecipientsLimit = _useState8[1];
84
-
85
- var reset = function reset() {
86
- setSelectedOption('readWrite');
87
- setRecipients([]);
88
- setLoading(false);
89
- };
90
-
91
- var onChange = function onChange(value) {
92
- setSelectedOption(value);
41
+ var onRecipientPick = function onRecipientPick(recipient) {
42
+ var merged = flag('sharing.show-recipient-groups') ? mergeRecipients(pendingRecipients, recipient) : spreadGroupAndMergeRecipients(pendingRecipients, recipient);
43
+ onPendingRecipientsChange(merged);
93
44
  };
94
45
 
95
- var onRecipientPick = /*#__PURE__*/function () {
96
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(recipient) {
97
- var contacts, mergedRecipients;
98
- return _regeneratorRuntime.wrap(function _callee$(_context) {
99
- while (1) switch (_context.prev = _context.next) {
100
- case 0:
101
- if (!isFederatedMode) {
102
- _context.next = 17;
103
- break;
104
- }
105
-
106
- setLoading(true);
107
- _context.prev = 2;
108
- _context.next = 5;
109
- return getOrCreateFromArray(client, [recipient], createContact);
110
-
111
- case 5:
112
- contacts = _context.sent;
113
- _context.next = 8;
114
- return onShare({
115
- document: document,
116
- recipients: contacts,
117
- readOnlyRecipients: [],
118
- description: sharingDesc,
119
- openSharing: false,
120
- sharedDrive: true
121
- });
122
-
123
- case 8:
124
- _context.next = 13;
125
- break;
126
-
127
- case 10:
128
- _context.prev = 10;
129
- _context.t0 = _context["catch"](2);
130
-
131
- if (showNotifications) {
132
- showAlert({
133
- message: t('Share.shareByEmail.error.addingRecipient'),
134
- severity: 'error',
135
- variant: 'filled'
136
- });
137
- }
138
-
139
- case 13:
140
- _context.prev = 13;
141
- reset();
142
- return _context.finish(13);
143
-
144
- case 16:
145
- return _context.abrupt("return");
146
-
147
- case 17:
148
- // Normal mode: just add to the list
149
- mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient);
150
- setRecipients(mergedRecipients);
151
-
152
- case 19:
153
- case "end":
154
- return _context.stop();
155
- }
156
- }, _callee, null, [[2, 10, 13, 16]]);
157
- }));
158
-
159
- return function onRecipientPick(_x) {
160
- return _ref2.apply(this, arguments);
161
- };
162
- }();
163
-
164
46
  var onRecipientRemove = function onRecipientRemove(recipient) {
165
- var idx = recipients.findIndex(function (r) {
47
+ var idx = pendingRecipients.findIndex(function (r) {
166
48
  return r === recipient;
167
49
  });
168
- setRecipients([].concat(_toConsumableArray(recipients.slice(0, idx)), _toConsumableArray(recipients.slice(idx + 1))));
50
+ onPendingRecipientsChange([].concat(_toConsumableArray(pendingRecipients.slice(0, idx)), _toConsumableArray(pendingRecipients.slice(idx + 1))));
169
51
  };
170
52
 
171
- var share = /*#__PURE__*/function () {
172
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
173
- var recipientsBefore, contacts, readWriteRecipients, readOnlyRecipients;
174
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
175
- while (1) switch (_context2.prev = _context2.next) {
176
- case 0:
177
- if (!(recipients.length === 0)) {
178
- _context2.next = 2;
179
- break;
180
- }
181
-
182
- return _context2.abrupt("return");
183
-
184
- case 2:
185
- // we can't use currentRecipients prop in getSuccessMessage because it may use
186
- // the updated prop to count the new recipients
187
- recipientsBefore = currentRecipients;
188
-
189
- if (!hasReachRecipientsLimit(recipientsBefore, recipients)) {
190
- _context2.next = 6;
191
- break;
192
- }
193
-
194
- setRecipientsLimit(true);
195
- return _context2.abrupt("return");
196
-
197
- case 6:
198
- setLoading(true);
199
- _context2.prev = 7;
200
- _context2.next = 10;
201
- return getOrCreateFromArray(client, recipients, createContact);
202
-
203
- case 10:
204
- contacts = _context2.sent;
205
- readWriteRecipients = [];
206
- readOnlyRecipients = [];
207
-
208
- if (selectedOption === 'readOnly') {
209
- readOnlyRecipients = contacts;
210
- } else {
211
- readWriteRecipients = contacts;
212
- }
213
-
214
- _context2.next = 16;
215
- return onShare({
216
- document: document,
217
- recipients: readWriteRecipients,
218
- readOnlyRecipients: readOnlyRecipients,
219
- description: sharingDesc,
220
- openSharing: readWriteRecipients.length > 0,
221
- sharedDrive: sharedDrive
222
- });
223
-
224
- case 16:
225
- if (showNotifications) {
226
- showAlert({
227
- message: t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore, contacts, documentType))),
228
- severity: 'success',
229
- variant: 'filled'
230
- });
231
- }
232
-
233
- _context2.next = 22;
234
- break;
235
-
236
- case 19:
237
- _context2.prev = 19;
238
- _context2.t0 = _context2["catch"](7);
239
-
240
- if (showNotifications) {
241
- showAlert({
242
- message: t.apply(void 0, _toConsumableArray(getErrorMessage({
243
- t: t,
244
- err: _context2.t0,
245
- documentType: documentType,
246
- recipients: recipients,
247
- selectedOption: selectedOption
248
- }))),
249
- severity: 'error',
250
- variant: 'filled'
251
- });
252
- }
253
-
254
- case 22:
255
- _context2.prev = 22;
256
- reset();
257
- return _context2.finish(22);
258
-
259
- case 25:
260
- case "end":
261
- return _context2.stop();
262
- }
263
- }, _callee2, null, [[7, 19, 22, 25]]);
264
- }));
265
-
266
- return function share() {
267
- return _ref3.apply(this, arguments);
268
- };
269
- }();
270
-
271
53
  var getSharingOptions = function getSharingOptions() {
272
54
  var isSharingReadOnly = sharing ? isReadOnlySharing(sharing, document === null || document === void 0 ? void 0 : document._id) : false;
273
55
  var readWrite = {
274
56
  value: 'readWrite',
275
- label: t('Share.type.two-way'),
276
- desc: t('Share.type.desc.two-way'),
277
- disabled: false
57
+ label: t('Share.type.two-way')
278
58
  };
279
59
  var readOnly = {
280
60
  value: 'readOnly',
281
- label: t('Share.type.one-way'),
282
- desc: t('Share.type.desc.one-way'),
283
- disabled: false
61
+ label: t('Share.type.one-way')
284
62
  };
285
63
  return isSharingReadOnly ? [readOnly] : [readWrite, readOnly];
286
64
  };
287
65
 
288
- var showShareControl = recipients.length > 0;
289
66
  return /*#__PURE__*/React.createElement("div", {
290
67
  className: styles['coz-form-group']
291
68
  }, /*#__PURE__*/React.createElement("div", {
292
69
  className: styles['coz-form']
293
70
  }, /*#__PURE__*/React.createElement(ShareRecipientsInput, {
294
- placeholder: recipients.length === 0 ? t("".concat(documentType, ".share.shareByEmail.emailPlaceholder")) : '',
295
- onPick: function onPick(recipient) {
296
- return onRecipientPick(recipient);
297
- },
298
- onRemove: function onRemove(recipient) {
299
- return onRecipientRemove(recipient);
300
- },
71
+ placeholder: pendingRecipients.length === 0 ? t("".concat(documentType, ".share.shareByEmail.emailPlaceholder")) : '',
72
+ onPick: onRecipientPick,
73
+ onRemove: onRecipientRemove,
301
74
  currentRecipients: currentRecipients,
302
- recipients: recipients,
303
- disabled: loading
304
- })), !isFederatedMode && showShareControl && /*#__PURE__*/React.createElement("div", {
305
- className: styles['share-type-control']
306
- }, /*#__PURE__*/React.createElement(ShareTypeSelect, {
307
- value: selectedOption,
308
- options: getSharingOptions(),
309
- onChange: onChange
310
- }), /*#__PURE__*/React.createElement(ShareSubmit, {
311
- label: submitLabel || t("".concat(documentType, ".share.shareByEmail.send")),
312
- onSubmit: share,
313
- loading: loading,
314
- disabled: recipients.length === 0
315
- })), showRecipientsLimit ? /*#__PURE__*/React.createElement(ShareRecipientsLimitModal, {
316
- documentName: document === null || document === void 0 ? void 0 : document.name,
317
- onConfirm: function onConfirm() {
318
- return setRecipientsLimit(false);
319
- }
320
- }) : null);
75
+ recipients: pendingRecipients,
76
+ endAdornment: /*#__PURE__*/React.createElement(ShareTypeSelect, {
77
+ value: selectedOption,
78
+ options: getSharingOptions(),
79
+ onChange: onSelectedOptionChange
80
+ })
81
+ })));
321
82
  };
322
83
  ShareByEmail.propTypes = {
323
84
  currentRecipients: PropTypes.arrayOf(PropTypes.object),
324
85
  document: PropTypes.object,
325
86
  documentType: PropTypes.string.isRequired,
326
- sharingDesc: PropTypes.string.isRequired,
327
- onShare: PropTypes.func.isRequired,
328
- createContact: PropTypes.func.isRequired,
329
- // We can display this component without having created the sharing yet
330
- sharing: PropTypes.object,
331
- // Customize the label of the button that submit contacts
332
- submitLabel: PropTypes.string,
333
- // Display success or error notifications
334
- showNotifications: PropTypes.bool,
335
- // Set to true for shared drive context
336
- sharedDrive: PropTypes.bool
87
+ pendingRecipients: PropTypes.array.isRequired,
88
+ onPendingRecipientsChange: PropTypes.func.isRequired,
89
+ selectedOption: PropTypes.oneOf(['readWrite', 'readOnly']).isRequired,
90
+ onSelectedOptionChange: PropTypes.func.isRequired,
91
+ sharing: PropTypes.object
337
92
  };
338
93
  export default ShareByEmail;
@@ -1,247 +1,69 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { render, fireEvent, waitFor, screen } from '@testing-library/react';
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ import { fireEvent, render, screen } from '@testing-library/react';
4
8
  import React from 'react';
5
9
  import { act } from 'react-dom/test-utils';
6
- import flag from 'cozy-flags';
7
10
  import { ShareByEmail } from './ShareByEmail';
8
11
  import AppLike from '../../test/AppLike';
9
- import { getOrCreateFromArray } from '../helpers/contacts';
10
- jest.mock('../helpers/contacts', function () {
11
- return {
12
- // eslint-disable-next-line no-unused-vars
13
- getOrCreateFromArray: jest.fn(function (client, recipients, _createContact) {
14
- // Return the recipients as-is by default (simulating contact creation/lookup)
15
- return Promise.resolve(recipients);
16
- })
17
- };
18
- });
19
- jest.mock('cozy-flags', function () {
20
- return jest.fn(function (flagName) {
21
- if (flagName === 'drive.federated-shared-folder.enabled') {
22
- return false;
23
- }
24
-
25
- return null;
26
- });
27
- });
28
- describe('ShareByEmailComponent', function () {
29
- var defaultDocument = {
30
- id: 'doc_id',
31
- name: 'documentName'
32
- };
33
- var onShare = jest.fn();
34
-
12
+ describe('ShareByEmail (controlled)', function () {
35
13
  var setup = function setup() {
36
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
37
- _ref$sharingDesc = _ref.sharingDesc,
38
- sharingDesc = _ref$sharingDesc === void 0 ? 'test' : _ref$sharingDesc,
39
- _ref$document = _ref.document,
40
- document = _ref$document === void 0 ? defaultDocument : _ref$document,
41
- _ref$currentRecipient = _ref.currentRecipients,
42
- currentRecipients = _ref$currentRecipient === void 0 ? [] : _ref$currentRecipient,
43
- _ref$sharedDrive = _ref.sharedDrive,
44
- sharedDrive = _ref$sharedDrive === void 0 ? false : _ref$sharedDrive;
14
+ var overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
15
+ var onPendingRecipientsChange = jest.fn();
16
+ var onSelectedOptionChange = jest.fn();
45
17
 
46
- var props = {
18
+ var props = _objectSpread({
19
+ document: {
20
+ id: 'doc_id',
21
+ name: 'documentName'
22
+ },
47
23
  documentType: 'Files',
48
- onShare: onShare,
49
- document: document,
50
- sharingDesc: sharingDesc,
51
- currentRecipients: currentRecipients,
52
- createContact: jest.fn(),
53
- sharedDrive: sharedDrive
54
- };
55
- return render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareByEmail, props)));
24
+ currentRecipients: [],
25
+ pendingRecipients: [],
26
+ onPendingRecipientsChange: onPendingRecipientsChange,
27
+ selectedOption: 'readWrite',
28
+ onSelectedOptionChange: onSelectedOptionChange
29
+ }, overrides);
30
+
31
+ var utils = render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareByEmail, props)));
32
+ return _objectSpread(_objectSpread({}, utils), {}, {
33
+ onPendingRecipientsChange: onPendingRecipientsChange,
34
+ onSelectedOptionChange: onSelectedOptionChange
35
+ });
56
36
  };
57
37
 
58
38
  beforeEach(function () {
59
- jest.clearAllMocks(); // Reset flag mock to default (non-federated mode)
60
-
61
- flag.mockImplementation(function (flagName) {
62
- if (flagName === 'drive.federated-shared-folder.enabled') {
63
- return false;
64
- }
65
-
66
- return null;
67
- });
39
+ jest.clearAllMocks();
68
40
  });
69
- it('shoud call share if submited', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
70
- var sharingDesc;
71
- return _regeneratorRuntime.wrap(function _callee$(_context) {
72
- while (1) switch (_context.prev = _context.next) {
73
- case 0:
74
- sharingDesc = 'test';
75
- setup({
76
- sharingDesc: sharingDesc
77
- });
78
- act(function () {
79
- fireEvent.change(screen.getByPlaceholderText('Add contacts'), {
80
- target: {
81
- value: 'quentin@cozycloud.cc'
82
- }
83
- });
84
- });
85
- act(function () {
86
- fireEvent.keyPress(screen.getByPlaceholderText('Add contacts'), {
87
- key: 'Enter',
88
- code: 'Enter',
89
- charCode: 13
90
- });
91
- });
92
- act(function () {
93
- fireEvent.click(screen.getByRole('button', {
94
- name: 'Send'
95
- }));
96
- });
97
- _context.next = 7;
98
- return waitFor(function () {
99
- expect(onShare).toHaveBeenCalledWith({
100
- description: sharingDesc,
101
- document: defaultDocument,
102
- openSharing: true,
103
- readOnlyRecipients: [],
104
- recipients: [{
105
- email: 'quentin@cozycloud.cc'
106
- }],
107
- sharedDrive: false
108
- });
109
- });
110
-
111
- case 7:
112
- case "end":
113
- return _context.stop();
114
- }
115
- }, _callee);
116
- })));
117
- it('should alert user when it has reached the recipients limit for a document', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
118
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
119
- while (1) switch (_context2.prev = _context2.next) {
120
- case 0:
121
- flag.mockImplementation(function (flagName) {
122
- if (flagName === 'sharing.recipients-limit') {
123
- return 2;
124
- }
125
-
126
- if (flagName === 'drive.federated-shared-folder.enabled') {
127
- return false;
128
- }
41
+ it('calls onPendingRecipientsChange when an email is picked', function () {
42
+ var _setup = setup(),
43
+ onPendingRecipientsChange = _setup.onPendingRecipientsChange;
129
44
 
130
- return null;
131
- });
132
- setup({
133
- currentRecipients: [{
134
- email: 'alice@gmail.com',
135
- status: 'pending',
136
- type: 'two-way'
137
- }, {
138
- email: 'bob@gmail.com',
139
- status: 'pending',
140
- type: 'two-way'
141
- }]
142
- });
143
- act(function () {
144
- fireEvent.change(screen.getByPlaceholderText('Add contacts'), {
145
- target: {
146
- value: 'john@gmail.com'
147
- }
148
- });
149
- });
150
- act(function () {
151
- fireEvent.keyPress(screen.getByPlaceholderText('Add contacts'), {
152
- key: 'Enter',
153
- code: 'Enter',
154
- charCode: 13
155
- });
156
- });
157
- act(function () {
158
- fireEvent.click(screen.getByRole('button', {
159
- name: 'Send'
160
- }));
161
- });
162
- act(function () {
163
- fireEvent.click(screen.getByRole('button', {
164
- name: 'I understand'
165
- }));
166
- });
167
- _context2.next = 8;
168
- return waitFor(function () {
169
- expect(onShare).not.toHaveBeenCalled();
170
- });
171
-
172
- case 8:
173
- case "end":
174
- return _context2.stop();
175
- }
176
- }, _callee2);
177
- })));
178
- describe('federated mode', function () {
179
- beforeEach(function () {
180
- flag.mockImplementation(function (flagName) {
181
- if (flagName === 'drive.federated-shared-folder.enabled') {
182
- return true;
45
+ act(function () {
46
+ fireEvent.change(screen.getByPlaceholderText('Add contacts'), {
47
+ target: {
48
+ value: 'quentin@cozycloud.cc'
183
49
  }
184
-
185
- return null;
186
50
  });
187
- getOrCreateFromArray.mockResolvedValue([{
188
- _id: 'contact1',
189
- email: 'quentin@cozycloud.cc'
190
- }]);
191
51
  });
192
- it('should directly share when selecting a recipient in federated mode', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
193
- var sharingDesc, createContact;
194
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
195
- while (1) switch (_context3.prev = _context3.next) {
196
- case 0:
197
- sharingDesc = 'test';
198
- createContact = jest.fn();
199
- setup({
200
- sharingDesc: sharingDesc,
201
- createContact: createContact
202
- });
203
- act(function () {
204
- fireEvent.change(screen.getByPlaceholderText('Add contacts'), {
205
- target: {
206
- value: 'quentin@cozycloud.cc'
207
- }
208
- });
209
- });
210
- act(function () {
211
- fireEvent.keyPress(screen.getByPlaceholderText('Add contacts'), {
212
- key: 'Enter',
213
- code: 'Enter',
214
- charCode: 13
215
- });
216
- });
217
- _context3.next = 7;
218
- return waitFor(function () {
219
- expect(getOrCreateFromArray).toHaveBeenCalledWith(expect.any(Object), [{
220
- email: 'quentin@cozycloud.cc'
221
- }], expect.any(Function));
222
- });
223
-
224
- case 7:
225
- _context3.next = 9;
226
- return waitFor(function () {
227
- expect(onShare).toHaveBeenCalledWith({
228
- document: defaultDocument,
229
- recipients: [{
230
- _id: 'contact1',
231
- email: 'quentin@cozycloud.cc'
232
- }],
233
- readOnlyRecipients: [],
234
- description: sharingDesc,
235
- openSharing: false,
236
- sharedDrive: true
237
- });
238
- });
239
-
240
- case 9:
241
- case "end":
242
- return _context3.stop();
243
- }
244
- }, _callee3);
245
- })));
52
+ act(function () {
53
+ fireEvent.keyPress(screen.getByPlaceholderText('Add contacts'), {
54
+ key: 'Enter',
55
+ code: 'Enter',
56
+ charCode: 13
57
+ });
58
+ });
59
+ expect(onPendingRecipientsChange).toHaveBeenCalledWith([{
60
+ email: 'quentin@cozycloud.cc'
61
+ }]);
62
+ });
63
+ it('always shows the read/write dropdown trigger inside the input', function () {
64
+ setup();
65
+ expect(screen.getByRole('button', {
66
+ name: 'Editor'
67
+ })).not.toBeNull();
246
68
  });
247
69
  });
@@ -4,7 +4,6 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import PropTypes from 'prop-types';
5
5
  import React, { useReducer, useState } from 'react';
6
6
  import { useClient } from 'cozy-client';
7
- import flag from 'cozy-flags';
8
7
  import Button from 'cozy-ui/transpiled/react/Buttons';
9
8
  import Icon from 'cozy-ui/transpiled/react/Icon';
10
9
  import CopyIcon from 'cozy-ui/transpiled/react/Icons/Copy';
@@ -52,7 +51,6 @@ var ShareByLink = function ShareByLink(_ref) {
52
51
  var showGenerateButton = showGenerateLinkButton && !link;
53
52
  var showCopyAndSendButtons = !showGenerateButton && isMobile && canShare;
54
53
  var showOnlyCopyButton = !showGenerateButton && (!isMobile || !canShare);
55
- var isFederated = flag('drive.federated-shared-folder.enabled');
56
54
 
57
55
  var _useReducer = useReducer(function (state) {
58
56
  return !state;
@@ -280,7 +278,7 @@ var ShareByLink = function ShareByLink(_ref) {
280
278
  }();
281
279
 
282
280
  return /*#__PURE__*/React.createElement("div", {
283
- className: isFederated ? 'u-w-100' : 'u-w-100 u-flex u-flex-justify-center'
281
+ className: "u-w-100"
284
282
  }, showCopyAndSendButtons && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
285
283
  label: t("".concat(documentType, ".share.shareByLink.send")),
286
284
  variant: "secondary",