cozy-sharing 11.0.0 → 11.1.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 (68) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/components/Avatar/GroupAvatar.js +13 -0
  3. package/dist/components/Avatar/GroupAvatar.stories.js +10 -0
  4. package/dist/components/Avatar/MemberAvatar.js +20 -1
  5. package/dist/components/Recipient/GroupRecipient.js +49 -0
  6. package/dist/components/Recipient/GroupRecipient.stories.js +41 -0
  7. package/dist/components/Recipient/GroupRecipientPermissions.js +71 -0
  8. package/dist/components/Recipient/GroupRecipientPermissions.stories.js +37 -0
  9. package/dist/components/Recipient/MemberRecipient.stories.js +11 -1
  10. package/dist/components/Recipient/MemberRecipientPermissions.js +31 -40
  11. package/dist/components/Recipient/MemberRecipientPermissions.stories.js +30 -4
  12. package/dist/components/Recipient/RecipientList.js +16 -1
  13. package/dist/components/Recipient/RecipientList.stories.js +28 -0
  14. package/dist/components/Recipient/actions/permission.js +33 -0
  15. package/dist/components/Recipient/actions/revokeGroup.js +41 -0
  16. package/dist/components/Recipient/actions/revokeMember.js +41 -0
  17. package/dist/components/ShareByEmail.js +8 -29
  18. package/dist/components/ShareByEmail.spec.js +1 -1
  19. package/dist/components/ShareDialogCozyToCozy.js +2 -2
  20. package/dist/components/ShareDialogCozyToCozy.spec.js +1 -1
  21. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +2 -2
  22. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +1 -1
  23. package/dist/components/ShareModal/EditableSharingModal.js +43 -42
  24. package/dist/components/ShareModal/EditableSharingModal.spec.js +2 -2
  25. package/dist/components/ShareModal.js +4 -4
  26. package/dist/components/ShareRecipientsInput.js +7 -7
  27. package/dist/components/ShareRecipientsInput.spec.js +2 -2
  28. package/dist/helpers/recipients.js +38 -0
  29. package/dist/helpers/successMessage.spec.js +1 -1
  30. package/dist/propTypes.js +1 -1
  31. package/dist/queries/queries.js +1 -1
  32. package/dist/state.js +58 -2
  33. package/dist/state.spec.js +190 -10
  34. package/locales/en.json +24 -30
  35. package/locales/fr.json +24 -30
  36. package/package.json +2 -2
  37. package/src/components/Avatar/GroupAvatar.jsx +10 -0
  38. package/src/components/Avatar/GroupAvatar.stories.jsx +13 -0
  39. package/src/components/Avatar/MemberAvatar.jsx +11 -0
  40. package/src/components/Recipient/GroupRecipient.jsx +56 -0
  41. package/src/components/Recipient/GroupRecipient.stories.jsx +38 -0
  42. package/src/components/Recipient/GroupRecipientPermissions.jsx +77 -0
  43. package/src/components/Recipient/GroupRecipientPermissions.stories.jsx +41 -0
  44. package/src/components/Recipient/MemberRecipient.stories.jsx +12 -1
  45. package/src/components/Recipient/MemberRecipientPermissions.jsx +37 -53
  46. package/src/components/Recipient/MemberRecipientPermissions.stories.jsx +31 -4
  47. package/src/components/Recipient/RecipientList.jsx +18 -1
  48. package/src/components/Recipient/RecipientList.stories.jsx +34 -0
  49. package/src/components/Recipient/actions/permission.js +31 -0
  50. package/src/components/Recipient/actions/revokeGroup.js +39 -0
  51. package/src/components/Recipient/actions/revokeMember.js +39 -0
  52. package/src/components/ShareByEmail.jsx +14 -32
  53. package/src/components/ShareByEmail.spec.jsx +1 -1
  54. package/src/components/ShareDialogCozyToCozy.jsx +2 -2
  55. package/src/components/ShareDialogCozyToCozy.spec.jsx +1 -1
  56. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +2 -2
  57. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +1 -1
  58. package/src/components/ShareModal/EditableSharingModal.jsx +48 -46
  59. package/src/components/ShareModal/EditableSharingModal.spec.jsx +1 -1
  60. package/src/components/ShareModal.jsx +4 -4
  61. package/src/components/ShareRecipientsInput.jsx +9 -9
  62. package/src/components/ShareRecipientsInput.spec.jsx +2 -2
  63. package/src/helpers/recipients.js +45 -0
  64. package/src/helpers/successMessage.spec.js +1 -1
  65. package/src/propTypes.js +1 -1
  66. package/src/queries/queries.js +1 -1
  67. package/src/state.js +53 -2
  68. package/src/state.spec.js +230 -9
@@ -0,0 +1,41 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { forwardRef } from 'react';
3
+ import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
4
+ import Icon from 'cozy-ui/transpiled/react/Icon';
5
+ import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
6
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
7
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
8
+ import Typography from 'cozy-ui/transpiled/react/Typography';
9
+
10
+ var revokeMember = function revokeMember(_ref) {
11
+ var t = _ref.t,
12
+ isOwner = _ref.isOwner,
13
+ handleRevocation = _ref.handleRevocation;
14
+ var revokeType = isOwner ? 'revoke' : 'revokeSelf';
15
+ var title = t("RevokeMemberItem.".concat(revokeType, ".title"));
16
+ var desc = t("RevokeMemberItem.".concat(revokeType, ".desc"));
17
+ var icon = TrashIcon;
18
+ return {
19
+ name: 'revokeMember',
20
+ label: title,
21
+ icon: icon,
22
+ action: function action() {
23
+ handleRevocation();
24
+ },
25
+ Component: /*#__PURE__*/forwardRef(function RevokeMemberItem(props, ref) {
26
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
27
+ ref: ref
28
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
29
+ icon: icon,
30
+ color: "var(--errorColor)"
31
+ })), /*#__PURE__*/React.createElement(ListItemText, {
32
+ primary: /*#__PURE__*/React.createElement(Typography, {
33
+ color: "error"
34
+ }, title),
35
+ secondary: desc
36
+ }));
37
+ })
38
+ };
39
+ };
40
+
41
+ export { revokeMember };
@@ -2,10 +2,10 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
- import get from 'lodash/get';
6
5
  import PropTypes from 'prop-types';
7
6
  import React, { useState } from 'react';
8
7
  import { useClient } from 'cozy-client';
8
+ import flag from 'cozy-flags';
9
9
  import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
10
10
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
11
11
  import ShareRecipientsInput from './ShareRecipientsInput';
@@ -13,10 +13,9 @@ import { ShareRecipientsLimitModal } from './ShareRecipientsLimitModal';
13
13
  import ShareSubmit from './Sharesubmit';
14
14
  import ShareTypeSelect from './Sharetypeselect';
15
15
  import { getOrCreateFromArray } from '../helpers/contacts';
16
- import { hasReachRecipientsLimit } from '../helpers/recipients';
16
+ import { mergeRecipients, spreadGroupAndMergeRecipients, hasReachRecipientsLimit } from '../helpers/recipients';
17
17
  import { getSuccessMessage } from '../helpers/successMessage';
18
- import { Group } from '../models';
19
- import { contactsResponseType, groupsResponseType } from '../propTypes';
18
+ import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
20
19
  import { isReadOnlySharing } from '../state';
21
20
  var styles = {
22
21
  "share-modal-content": "share__share-modal-content___1iqEq",
@@ -43,7 +42,7 @@ var styles = {
43
42
  };
44
43
  export var ShareByEmail = function ShareByEmail(_ref) {
45
44
  var contacts = _ref.contacts,
46
- groups = _ref.groups,
45
+ contactGroups = _ref.contactGroups,
47
46
  document = _ref.document,
48
47
  sharingDesc = _ref.sharingDesc,
49
48
  onShare = _ref.onShare,
@@ -86,28 +85,8 @@ export var ShareByEmail = function ShareByEmail(_ref) {
86
85
  };
87
86
 
88
87
  var onRecipientPick = function onRecipientPick(recipient) {
89
- var contactsToAdd;
90
-
91
- if (recipient._type === Group.doctype) {
92
- var groupId = recipient.id;
93
- contactsToAdd = contacts.data.filter(function (contact) {
94
- var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
95
- return group._id;
96
- });
97
- return contactGroupIds.includes(groupId);
98
- });
99
- } else {
100
- contactsToAdd = [recipient];
101
- }
102
-
103
- var filtered = contactsToAdd.filter(function (contact) {
104
- return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
105
- }).filter(function (contact) {
106
- return !recipients.find(function (r) {
107
- return r === contact;
108
- });
109
- });
110
- setRecipients([].concat(_toConsumableArray(recipients), _toConsumableArray(filtered)));
88
+ var mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient, contacts);
89
+ setRecipients(mergedRecipients);
111
90
  };
112
91
 
113
92
  var onRecipientRemove = function onRecipientRemove(recipient) {
@@ -226,7 +205,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
226
205
  return onRecipientRemove(recipient);
227
206
  },
228
207
  contacts: contacts,
229
- groups: groups,
208
+ contactGroups: contactGroups,
230
209
  recipients: recipients
231
210
  })), showShareControl && /*#__PURE__*/React.createElement("div", {
232
211
  className: styles['share-type-control']
@@ -248,7 +227,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
248
227
  ShareByEmail.propTypes = {
249
228
  currentRecipients: PropTypes.arrayOf(PropTypes.object),
250
229
  contacts: contactsResponseType.isRequired,
251
- groups: groupsResponseType.isRequired,
230
+ contactGroups: contactGroupsResponseType.isRequired,
252
231
  document: PropTypes.object.isRequired,
253
232
  documentType: PropTypes.string.isRequired,
254
233
  sharingDesc: PropTypes.string.isRequired,
@@ -34,7 +34,7 @@ describe('ShareByEmailComponent', function () {
34
34
  contacts: {
35
35
  data: []
36
36
  },
37
- groups: {
37
+ contactGroups: {
38
38
  data: []
39
39
  },
40
40
  documentType: 'Files',
@@ -38,10 +38,10 @@ var styles = {
38
38
 
39
39
  var SharingContent = function SharingContent(_ref) {
40
40
  var contacts = _ref.contacts,
41
+ contactGroups = _ref.contactGroups,
41
42
  createContact = _ref.createContact,
42
43
  document = _ref.document,
43
44
  documentType = _ref.documentType,
44
- groups = _ref.groups,
45
45
  hasSharedParent = _ref.hasSharedParent,
46
46
  isOwner = _ref.isOwner,
47
47
  needsContactsPermission = _ref.needsContactsPermission,
@@ -75,11 +75,11 @@ var SharingContent = function SharingContent(_ref) {
75
75
  className: "u-mb-1-half"
76
76
  }, t('Share.contacts.whoHasAccess')), showShareByEmail && /*#__PURE__*/React.createElement(DumbShareByEmail, {
77
77
  contacts: contacts,
78
+ contactGroups: contactGroups,
78
79
  createContact: createContact,
79
80
  currentRecipients: recipients,
80
81
  document: document,
81
82
  documentType: documentType,
82
- groups: groups,
83
83
  needsContactsPermission: needsContactsPermission,
84
84
  onShare: onShare,
85
85
  sharing: sharing,
@@ -433,7 +433,7 @@ var getMockProps = function getMockProps() {
433
433
  _id: 'SOME_DOCUMENT_ID'
434
434
  },
435
435
  documentType: 'Organizations',
436
- groups: {
436
+ contactGroups: {
437
437
  id: 'groups',
438
438
  definition: {
439
439
  doctype: 'io.cozy.contacts.groups'
@@ -99,10 +99,10 @@ var RejectRecipientActions = function RejectRecipientActions(_ref3) {
99
99
 
100
100
  var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfirmationContainer(_ref4) {
101
101
  var contacts = _ref4.contacts,
102
+ contactGroups = _ref4.contactGroups,
102
103
  createContact = _ref4.createContact,
103
104
  document = _ref4.document,
104
105
  documentType = _ref4.documentType,
105
- groups = _ref4.groups,
106
106
  hasSharedParent = _ref4.hasSharedParent,
107
107
  isOwner = _ref4.isOwner,
108
108
  link = _ref4.link,
@@ -241,10 +241,10 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
241
241
  } else if (status === 'sharing') {
242
242
  dialogContent = /*#__PURE__*/React.createElement(DialogContentOnShare, {
243
243
  contacts: contacts,
244
+ contactGroups: contactGroups,
244
245
  createContact: createContact,
245
246
  document: document,
246
247
  documentType: documentType,
247
- groups: groups,
248
248
  hasSharedParent: hasSharedParent,
249
249
  isOwner: isOwner,
250
250
  needsContactsPermission: needsContactsPermission,
@@ -455,7 +455,7 @@ var getMockProps = function getMockProps() {
455
455
  _id: 'SOME_DOCUMENT_ID'
456
456
  },
457
457
  documentType: 'Organizations',
458
- groups: {
458
+ contactGroups: {
459
459
  id: 'groups',
460
460
  definition: {
461
461
  doctype: 'io.cozy.contacts.groups'
@@ -4,10 +4,10 @@ var _excluded = ["document"];
4
4
  import PropTypes from 'prop-types';
5
5
  import React from 'react';
6
6
  import { useClient, useQueryAll } from 'cozy-client';
7
- import SharingContext from '../../context';
8
7
  import { useFetchDocumentPath } from '../../hooks/useFetchDocumentPath';
8
+ import { useSharingContext } from '../../hooks/useSharingContext';
9
9
  import { Contact } from '../../models';
10
- import { buildContactsQuery, buildGroupsQuery } from '../../queries/queries';
10
+ import { buildContactsQuery, buildContactGroupsQuery } from '../../queries/queries';
11
11
  import { default as DumbShareModal } from '../ShareModal';
12
12
  export var EditableSharingModal = function EditableSharingModal(_ref) {
13
13
  var document = _ref.document,
@@ -17,46 +17,47 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
17
17
  var documentPath = useFetchDocumentPath(client, document);
18
18
  var contactsQuery = buildContactsQuery();
19
19
  var contactsResult = useQueryAll(contactsQuery.definition, contactsQuery.options);
20
- var groupsQuery = buildGroupsQuery();
21
- var groupsResult = useQueryAll(groupsQuery.definition, groupsQuery.options);
22
- return /*#__PURE__*/React.createElement(SharingContext.Consumer, null, function (_ref2) {
23
- var documentType = _ref2.documentType,
24
- getDocumentPermissions = _ref2.getDocumentPermissions,
25
- getRecipients = _ref2.getRecipients,
26
- getSharingForSelf = _ref2.getSharingForSelf,
27
- getSharingLink = _ref2.getSharingLink,
28
- hasSharedChild = _ref2.hasSharedChild,
29
- hasSharedParent = _ref2.hasSharedParent,
30
- isOwner = _ref2.isOwner,
31
- revoke = _ref2.revoke,
32
- revokeSelf = _ref2.revokeSelf,
33
- revokeSharingLink = _ref2.revokeSharingLink,
34
- share = _ref2.share,
35
- shareByLink = _ref2.shareByLink,
36
- updateDocumentPermissions = _ref2.updateDocumentPermissions;
37
- return /*#__PURE__*/React.createElement(DumbShareModal, _extends({
38
- contacts: contactsResult,
39
- createContact: function createContact(contact) {
40
- return client.create(Contact.doctype, contact);
41
- },
42
- document: document,
43
- documentType: documentType,
44
- groups: groupsResult,
45
- hasSharedChild: documentPath && hasSharedChild(documentPath),
46
- hasSharedParent: documentPath && hasSharedParent(documentPath),
47
- isOwner: isOwner(document.id),
48
- link: getSharingLink(document.id),
49
- onRevoke: revoke,
50
- onRevokeLink: revokeSharingLink,
51
- onRevokeSelf: revokeSelf,
52
- onShare: share,
53
- onShareByLink: shareByLink,
54
- onUpdateShareLinkPermissions: updateDocumentPermissions,
55
- permissions: getDocumentPermissions(document.id),
56
- recipients: getRecipients(document.id),
57
- sharing: getSharingForSelf(document.id)
58
- }, rest));
59
- });
20
+ var contactGroupsQuery = buildContactGroupsQuery();
21
+ var contactGroupsResult = useQueryAll(contactGroupsQuery.definition, contactGroupsQuery.options);
22
+
23
+ var _useSharingContext = useSharingContext(),
24
+ documentType = _useSharingContext.documentType,
25
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions,
26
+ getRecipients = _useSharingContext.getRecipients,
27
+ getSharingForSelf = _useSharingContext.getSharingForSelf,
28
+ getSharingLink = _useSharingContext.getSharingLink,
29
+ hasSharedChild = _useSharingContext.hasSharedChild,
30
+ hasSharedParent = _useSharingContext.hasSharedParent,
31
+ isOwner = _useSharingContext.isOwner,
32
+ revoke = _useSharingContext.revoke,
33
+ revokeSelf = _useSharingContext.revokeSelf,
34
+ revokeSharingLink = _useSharingContext.revokeSharingLink,
35
+ share = _useSharingContext.share,
36
+ shareByLink = _useSharingContext.shareByLink,
37
+ updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
38
+
39
+ return /*#__PURE__*/React.createElement(DumbShareModal, _extends({
40
+ contacts: contactsResult,
41
+ contactGroups: contactGroupsResult,
42
+ createContact: function createContact(contact) {
43
+ return client.create(Contact.doctype, contact);
44
+ },
45
+ document: document,
46
+ documentType: documentType,
47
+ hasSharedChild: documentPath && hasSharedChild(documentPath),
48
+ hasSharedParent: documentPath && hasSharedParent(documentPath),
49
+ isOwner: isOwner(document.id),
50
+ link: getSharingLink(document.id),
51
+ onRevoke: revoke,
52
+ onRevokeLink: revokeSharingLink,
53
+ onRevokeSelf: revokeSelf,
54
+ onShare: share,
55
+ onShareByLink: shareByLink,
56
+ onUpdateShareLinkPermissions: updateDocumentPermissions,
57
+ permissions: getDocumentPermissions(document.id),
58
+ recipients: getRecipients(document.id),
59
+ sharing: getSharingForSelf(document.id)
60
+ }, rest));
60
61
  };
61
62
  EditableSharingModal.propTypes = {
62
63
  document: PropTypes.object
@@ -36,10 +36,10 @@ describe('EditableSharingModal', function () {
36
36
  contacts: {
37
37
  data: []
38
38
  },
39
- document: document,
40
- groups: {
39
+ contactGroups: {
41
40
  data: []
42
41
  },
42
+ document: document,
43
43
  t: function t(x) {
44
44
  return x;
45
45
  },
@@ -3,14 +3,14 @@ import React from 'react';
3
3
  import flag from 'cozy-flags';
4
4
  import ShareDialogCozyToCozy from './ShareDialogCozyToCozy';
5
5
  import ShareDialogOnlyByLink from './ShareDialogOnlyByLink';
6
- import { contactsResponseType, groupsResponseType } from '../propTypes';
6
+ import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
7
7
  export var ShareModal = function ShareModal(_ref) {
8
8
  var contacts = _ref.contacts,
9
+ contactGroups = _ref.contactGroups,
9
10
  createContact = _ref.createContact,
10
11
  document = _ref.document,
11
12
  _ref$documentType = _ref.documentType,
12
13
  documentType = _ref$documentType === void 0 ? 'Document' : _ref$documentType,
13
- groups = _ref.groups,
14
14
  hasSharedChild = _ref.hasSharedChild,
15
15
  hasSharedParent = _ref.hasSharedParent,
16
16
  isOwner = _ref.isOwner,
@@ -48,10 +48,10 @@ export var ShareModal = function ShareModal(_ref) {
48
48
  permissions: permissions
49
49
  }) : /*#__PURE__*/React.createElement(ShareDialogCozyToCozy, {
50
50
  contacts: contacts,
51
+ contactGroups: contactGroups,
51
52
  createContact: createContact,
52
53
  document: document,
53
54
  documentType: documentType,
54
- groups: groups,
55
55
  hasSharedParent: hasSharedParent,
56
56
  isOwner: isOwner,
57
57
  link: link,
@@ -77,10 +77,10 @@ export var ShareModal = function ShareModal(_ref) {
77
77
  export default ShareModal;
78
78
  ShareModal.propTypes = {
79
79
  contacts: contactsResponseType.isRequired,
80
+ contactGroups: contactGroupsResponseType.isRequired,
80
81
  createContact: PropTypes.func.isRequired,
81
82
  document: PropTypes.object.isRequired,
82
83
  documentType: PropTypes.string,
83
- groups: groupsResponseType.isRequired,
84
84
  hasSharedChild: PropTypes.bool,
85
85
  hasSharedParent: PropTypes.bool,
86
86
  isOwner: PropTypes.bool,
@@ -3,11 +3,11 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import PropTypes from 'prop-types';
4
4
  import React, { useState, useEffect } from 'react';
5
5
  import ShareAutosuggest from './ShareAutosuggest';
6
- import { contactsResponseType, groupsResponseType } from '../propTypes';
6
+ import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
7
7
 
8
8
  var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
9
9
  var contacts = _ref.contacts,
10
- groups = _ref.groups,
10
+ contactGroups = _ref.contactGroups,
11
11
  recipients = _ref.recipients,
12
12
  placeholder = _ref.placeholder,
13
13
  onPick = _ref.onPick,
@@ -19,13 +19,13 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
19
19
  setLoading = _useState2[1];
20
20
 
21
21
  useEffect(function () {
22
- if (loading && !contacts.hasMore && contacts.fetchStatus === 'loaded' && !groups.hasMore && groups.fetchStatus === 'loaded') {
22
+ if (loading && !contacts.hasMore && contacts.fetchStatus === 'loaded' && !contactGroups.hasMore && contactGroups.fetchStatus === 'loaded') {
23
23
  setLoading(false);
24
24
  }
25
- }, [contacts, groups, loading]);
25
+ }, [contacts, contactGroups, loading]);
26
26
 
27
27
  var onShareAutosuggestFocus = function onShareAutosuggestFocus() {
28
- if (contacts.hasMore || contacts.fetchStatus === 'loading' || groups.hasMore || groups.fetchStatus === 'loading') {
28
+ if (contacts.hasMore || contacts.fetchStatus === 'loading' || contactGroups.hasMore || contactGroups.fetchStatus === 'loading') {
29
29
  setLoading(true);
30
30
  }
31
31
  };
@@ -35,7 +35,7 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
35
35
  if (contacts.hasMore || contacts.fetchStatus === 'loading') {
36
36
  return contacts.data;
37
37
  } else {
38
- return [].concat(_toConsumableArray(contacts.data), _toConsumableArray(groups.data));
38
+ return [].concat(_toConsumableArray(contacts.data), _toConsumableArray(contactGroups.data));
39
39
  }
40
40
  };
41
41
 
@@ -52,7 +52,7 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
52
52
 
53
53
  ShareRecipientsInput.propTypes = {
54
54
  contacts: contactsResponseType.isRequired,
55
- groups: groupsResponseType.isRequired,
55
+ contactGroups: contactGroupsResponseType.isRequired,
56
56
  recipients: PropTypes.array,
57
57
  placeholder: PropTypes.string,
58
58
  onPick: PropTypes.func.isRequired,
@@ -28,7 +28,7 @@ describe('ShareRecipientsInput component', function () {
28
28
  }
29
29
  }]
30
30
  },
31
- groups: {
31
+ contactGroups: {
32
32
  id: 'groups',
33
33
  fetchStatus: 'loaded',
34
34
  hasMore: false,
@@ -85,7 +85,7 @@ describe('ShareRecipientsInput component', function () {
85
85
  }
86
86
  }]
87
87
  },
88
- groups: {
88
+ contactGroups: {
89
89
  id: 'groups',
90
90
  fetchStatus: 'loaded',
91
91
  hasMore: false,
@@ -1,10 +1,13 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
 
3
4
  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
 
5
6
  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
 
8
+ import get from 'lodash/get';
7
9
  import flag from 'cozy-flags';
10
+ import { Group } from '../models';
8
11
  export var filterAndReworkRecipients = function filterAndReworkRecipients(recipients, previousRecipients) {
9
12
  return recipients.filter(function (recipient) {
10
13
  return recipient.status !== 'owner';
@@ -50,4 +53,39 @@ export var hasReachRecipientsLimit = function hasReachRecipientsLimit(current, n
50
53
  }
51
54
 
52
55
  return false;
56
+ };
57
+ /**
58
+ * Merges the recipients list with a new recipient and their associated contacts.
59
+ * @param {object[]} recipients - The list of recipients.
60
+ * @param {object} recipient - The new recipient.
61
+ * @param {object[]} contacts - The list of contacts.
62
+ * @returns {object[]} - The merged recipients list.
63
+ */
64
+
65
+ export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipients(recipients, newRecipient, contacts) {
66
+ var contactsToAdd;
67
+
68
+ if (newRecipient._type === Group.doctype) {
69
+ var groupId = newRecipient.id;
70
+ contactsToAdd = contacts.data.filter(function (contact) {
71
+ var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
72
+ return group._id;
73
+ });
74
+ return contactGroupIds.includes(groupId);
75
+ });
76
+ } else {
77
+ contactsToAdd = [newRecipient];
78
+ }
79
+
80
+ var filtered = contactsToAdd.filter(function (contact) {
81
+ return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
82
+ }).filter(function (contact) {
83
+ return !recipients.find(function (r) {
84
+ return r === contact;
85
+ });
86
+ });
87
+ return [].concat(_toConsumableArray(recipients), _toConsumableArray(filtered));
88
+ };
89
+ export var mergeRecipients = function mergeRecipients(recipients, newRecipient) {
90
+ return [].concat(_toConsumableArray(recipients), [newRecipient]);
53
91
  };
@@ -8,7 +8,7 @@ describe('getSuccessMessage method', function () {
8
8
  hasMore: false,
9
9
  fetchStatus: 'loaded'
10
10
  },
11
- groups: {
11
+ contactGroups: {
12
12
  id: 'groups',
13
13
  data: [],
14
14
  hasMore: false,
package/dist/propTypes.js CHANGED
@@ -12,7 +12,7 @@ export var contactsResponseType = PropTypes.shape({
12
12
  lastFetch: PropTypes.number,
13
13
  lastUpdate: PropTypes.number
14
14
  });
15
- export var groupsResponseType = PropTypes.shape({
15
+ export var contactGroupsResponseType = PropTypes.shape({
16
16
  count: PropTypes.number,
17
17
  data: PropTypes.arrayOf(Group.propType),
18
18
  definition: PropTypes.object,
@@ -53,7 +53,7 @@ export var buildContactsQuery = function buildContactsQuery() {
53
53
  }
54
54
  };
55
55
  };
56
- export var buildGroupsQuery = function buildGroupsQuery() {
56
+ export var buildContactGroupsQuery = function buildContactGroupsQuery() {
57
57
  return {
58
58
  definition: Q(Group.doctype),
59
59
  options: {
package/dist/state.js CHANGED
@@ -11,6 +11,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
11
11
  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; }
12
12
 
13
13
  import get from 'lodash/get';
14
+ import flag from 'cozy-flags';
14
15
  var RECEIVE_SHARINGS = 'RECEIVE_SHARINGS';
15
16
  var ADD_SHARING = 'ADD_SHARING';
16
17
  var UPDATE_SHARING = 'UPDATE_SHARING';
@@ -380,13 +381,24 @@ export var getOwner = function getOwner(state, docId) {
380
381
  });
381
382
  };
382
383
  export var getRecipients = function getRecipients(state, docId) {
383
- var recipients = getDocumentSharings(state, docId).map(function (sharing) {
384
+ var sharings = getDocumentSharings(state, docId);
385
+
386
+ if (flag('sharing.show-recipient-groups')) {
387
+ return getRecipientsWithGroups(sharings, docId);
388
+ }
389
+
390
+ return getRecipientsWithoutGroups(sharings, docId);
391
+ };
392
+
393
+ var getRecipientsWithoutGroups = function getRecipientsWithoutGroups(sharings, docId) {
394
+ var recipients = sharings.map(function (sharing) {
384
395
  var type = getDocumentSharingType(sharing, docId);
385
396
  return sharing.attributes.members.map(function (m, idx) {
386
397
  return _objectSpread(_objectSpread({}, m), {}, {
398
+ index: "sharing-".concat(sharing.id, "-member-").concat(idx),
387
399
  type: m.read_only ? 'one-way' : type,
388
400
  sharingId: sharing.id,
389
- index: idx,
401
+ memberIndex: idx,
390
402
  avatarPath: "/sharings/".concat(sharing.id, "/recipients/").concat(idx, "/avatar")
391
403
  });
392
404
  });
@@ -404,6 +416,50 @@ export var getRecipients = function getRecipients(state, docId) {
404
416
 
405
417
  return recipients;
406
418
  };
419
+
420
+ export var getRecipientsWithGroups = function getRecipientsWithGroups(sharings, docId) {
421
+ var recipients = sharings.flatMap(function (sharing) {
422
+ var _sharing$attributes$g;
423
+
424
+ var type = getDocumentSharingType(sharing, docId);
425
+ var sharingId = sharing.id;
426
+ var members = sharing.attributes.members.map(function (m, idx) {
427
+ return _objectSpread(_objectSpread({}, m), {}, {
428
+ type: m.read_only ? 'one-way' : type,
429
+ sharingId: sharingId,
430
+ index: "sharing-".concat(sharing.id, "-member-").concat(idx),
431
+ memberIndex: idx,
432
+ avatarPath: "/sharings/".concat(sharingId, "/recipients/").concat(idx, "/avatar")
433
+ });
434
+ });
435
+ var groups = ((_sharing$attributes$g = sharing.attributes.groups) === null || _sharing$attributes$g === void 0 ? void 0 : _sharing$attributes$g.map(function (g, idx) {
436
+ return _objectSpread(_objectSpread({}, g), {}, {
437
+ sharingId: sharingId,
438
+ index: "sharing-".concat(sharing.id, "-group-").concat(idx),
439
+ groupIndex: idx,
440
+ owner: members[g.addedBy],
441
+ members: members.filter(function (member) {
442
+ var _member$groups;
443
+
444
+ return (_member$groups = member.groups) === null || _member$groups === void 0 ? void 0 : _member$groups.includes(idx);
445
+ })
446
+ });
447
+ }).filter(function (g) {
448
+ return !g.revoked;
449
+ })) || [];
450
+ return [].concat(_toConsumableArray(members.filter(function (m) {
451
+ return !m.only_in_groups && m.status !== 'revoked';
452
+ })), _toConsumableArray(groups));
453
+ });
454
+
455
+ if (recipients[0] && recipients[0].status === 'owner') {
456
+ return [recipients[0]].concat(_toConsumableArray(recipients.filter(function (r) {
457
+ return r.status !== 'owner';
458
+ })));
459
+ }
460
+
461
+ return recipients;
462
+ };
407
463
  export var getSharingLink = function getSharingLink(state, docId, documentType) {
408
464
  // This shouldn't have happened, but unfortunately some duplicate sharing links have been created in the past
409
465
  var perms = getDocumentPermissions(state, docId);