cozy-sharing 12.2.0 → 13.0.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 (73) hide show
  1. package/.storybook/preview.jsx +1 -0
  2. package/CHANGELOG.md +40 -0
  3. package/dist/components/Avatar/AvatarList.js +13 -2
  4. package/dist/components/Avatar/AvatarList.spec.js +11 -6
  5. package/dist/components/Avatar/AvatarList.stories.js +13 -1
  6. package/dist/components/Avatar/GroupAvatar.js +4 -2
  7. package/dist/components/ContactSuggestion.js +7 -3
  8. package/dist/components/ContactSuggestion.spec.js +7 -1
  9. package/dist/components/Recipient/GroupRecipient.js +14 -7
  10. package/dist/components/Recipient/GroupRecipientDetail.js +4 -2
  11. package/dist/components/Recipient/GroupRecipientDetailWithAccess.js +9 -11
  12. package/dist/components/Recipient/GroupRecipientDetailWithoutAccess.js +8 -4
  13. package/dist/components/Recipient/GroupRecipientPermissions.js +3 -6
  14. package/dist/components/Recipient/MemberRecipient.js +1 -2
  15. package/dist/components/Recipient/MemberRecipientPermissions.js +1 -1
  16. package/dist/components/ShareAutosuggest.js +16 -9
  17. package/dist/components/ShareAutosuggest.spec.js +38 -13
  18. package/dist/components/ShareAutosuggest.stories.js +61 -0
  19. package/dist/components/ShareByEmail.js +15 -15
  20. package/dist/components/ShareByEmail.spec.js +0 -6
  21. package/dist/components/ShareDialogCozyToCozy.js +1 -5
  22. package/dist/components/ShareDialogCozyToCozy.spec.js +0 -61
  23. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -5
  24. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +0 -61
  25. package/dist/components/ShareModal/EditableSharingModal.js +3 -10
  26. package/dist/components/ShareModal/EditableSharingModal.spec.js +0 -6
  27. package/dist/components/ShareModal.js +1 -8
  28. package/dist/components/ShareRecipientsInput.js +46 -49
  29. package/dist/components/ShareRecipientsInput.spec.js +120 -144
  30. package/dist/helpers/contacts.js +12 -1
  31. package/dist/helpers/recipients.js +16 -9
  32. package/dist/helpers/successMessage.js +58 -16
  33. package/dist/helpers/successMessage.spec.js +122 -57
  34. package/dist/queries/queries.js +37 -5
  35. package/dist/styles/autosuggest.styl +2 -1
  36. package/dist/stylesheet.css +2 -1
  37. package/locales/en.json +23 -10
  38. package/locales/fr.json +23 -8
  39. package/package.json +4 -4
  40. package/src/components/Avatar/AvatarList.jsx +33 -14
  41. package/src/components/Avatar/AvatarList.spec.jsx +11 -6
  42. package/src/components/Avatar/AvatarList.stories.jsx +19 -1
  43. package/src/components/Avatar/GroupAvatar.jsx +2 -2
  44. package/src/components/ContactSuggestion.jsx +9 -3
  45. package/src/components/ContactSuggestion.spec.jsx +10 -1
  46. package/src/components/Recipient/GroupRecipient.jsx +17 -10
  47. package/src/components/Recipient/GroupRecipientDetail.jsx +5 -2
  48. package/src/components/Recipient/GroupRecipientDetailWithAccess.jsx +9 -14
  49. package/src/components/Recipient/GroupRecipientDetailWithoutAccess.jsx +8 -3
  50. package/src/components/Recipient/GroupRecipientPermissions.jsx +3 -8
  51. package/src/components/Recipient/MemberRecipient.jsx +4 -3
  52. package/src/components/Recipient/MemberRecipientPermissions.jsx +1 -1
  53. package/src/components/ShareAutosuggest.jsx +16 -11
  54. package/src/components/ShareAutosuggest.spec.jsx +31 -10
  55. package/src/components/ShareAutosuggest.stories.jsx +63 -0
  56. package/src/components/ShareByEmail.jsx +11 -11
  57. package/src/components/ShareByEmail.spec.jsx +0 -4
  58. package/src/components/ShareDialogCozyToCozy.jsx +0 -4
  59. package/src/components/ShareDialogCozyToCozy.spec.jsx +0 -67
  60. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -4
  61. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +0 -67
  62. package/src/components/ShareModal/EditableSharingModal.jsx +3 -21
  63. package/src/components/ShareModal/EditableSharingModal.spec.jsx +0 -2
  64. package/src/components/ShareModal.jsx +1 -7
  65. package/src/components/ShareRecipientsInput.jsx +84 -52
  66. package/src/components/ShareRecipientsInput.spec.jsx +140 -145
  67. package/src/helpers/contacts.js +8 -0
  68. package/src/helpers/recipients.js +24 -15
  69. package/src/helpers/successMessage.js +71 -21
  70. package/src/helpers/successMessage.spec.js +129 -69
  71. package/src/queries/queries.js +36 -5
  72. package/src/styles/autosuggest.styl +2 -1
  73. package/test/AppLike.jsx +6 -3
@@ -7,6 +7,7 @@ import React, { useState } from 'react';
7
7
  import { useClient } from 'cozy-client';
8
8
  import flag from 'cozy-flags';
9
9
  import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
10
+ import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
10
11
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
11
12
  import ShareRecipientsInput from './ShareRecipientsInput';
12
13
  import { ShareRecipientsLimitModal } from './ShareRecipientsLimitModal';
@@ -15,7 +16,6 @@ import ShareTypeSelect from './Sharetypeselect';
15
16
  import { getOrCreateFromArray } from '../helpers/contacts';
16
17
  import { mergeRecipients, spreadGroupAndMergeRecipients, hasReachRecipientsLimit } from '../helpers/recipients';
17
18
  import { getSuccessMessage } from '../helpers/successMessage';
18
- import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
19
19
  import { isReadOnlySharing } from '../state';
20
20
  var styles = {
21
21
  "share-modal-content": "share__share-modal-content___1iqEq",
@@ -41,9 +41,7 @@ var styles = {
41
41
  "share-details-perm-desc": "share__share-details-perm-desc___3HyHu"
42
42
  };
43
43
  export var ShareByEmail = function ShareByEmail(_ref) {
44
- var contacts = _ref.contacts,
45
- contactGroups = _ref.contactGroups,
46
- document = _ref.document,
44
+ var document = _ref.document,
47
45
  sharingDesc = _ref.sharingDesc,
48
46
  onShare = _ref.onShare,
49
47
  createContact = _ref.createContact,
@@ -55,6 +53,9 @@ export var ShareByEmail = function ShareByEmail(_ref) {
55
53
  var _useI18n = useI18n(),
56
54
  t = _useI18n.t;
57
55
 
56
+ var _useAlert = useAlert(),
57
+ showAlert = _useAlert.showAlert;
58
+
58
59
  var _useState = useState([]),
59
60
  _useState2 = _slicedToArray(_useState, 2),
60
61
  recipients = _useState2[0],
@@ -85,7 +86,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
85
86
  };
86
87
 
87
88
  var onRecipientPick = function onRecipientPick(recipient) {
88
- var mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient, contacts);
89
+ var mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient);
89
90
  setRecipients(mergedRecipients);
90
91
  };
91
92
 
@@ -98,8 +99,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
98
99
 
99
100
  var share = /*#__PURE__*/function () {
100
101
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
101
- var recipientsBefore, _contacts, readWriteRecipients, readOnlyRecipients;
102
-
102
+ var recipientsBefore, contacts, readWriteRecipients, readOnlyRecipients;
103
103
  return _regeneratorRuntime.wrap(function _callee$(_context) {
104
104
  while (1) switch (_context.prev = _context.next) {
105
105
  case 0:
@@ -130,14 +130,14 @@ export var ShareByEmail = function ShareByEmail(_ref) {
130
130
  return getOrCreateFromArray(client, recipients, createContact);
131
131
 
132
132
  case 10:
133
- _contacts = _context.sent;
133
+ contacts = _context.sent;
134
134
  readWriteRecipients = [];
135
135
  readOnlyRecipients = [];
136
136
 
137
137
  if (selectedOption === 'readOnly') {
138
- readOnlyRecipients = _contacts;
138
+ readOnlyRecipients = contacts;
139
139
  } else {
140
- readWriteRecipients = _contacts;
140
+ readWriteRecipients = contacts;
141
141
  }
142
142
 
143
143
  _context.next = 16;
@@ -150,7 +150,11 @@ export var ShareByEmail = function ShareByEmail(_ref) {
150
150
  });
151
151
 
152
152
  case 16:
153
- Alerter.success(t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore, _contacts, documentType))));
153
+ showAlert({
154
+ message: t.apply(void 0, _toConsumableArray(getSuccessMessage(recipientsBefore, contacts, documentType))),
155
+ severity: 'success',
156
+ variant: 'filled'
157
+ });
154
158
  reset();
155
159
  _context.next = 25;
156
160
  break;
@@ -204,8 +208,6 @@ export var ShareByEmail = function ShareByEmail(_ref) {
204
208
  onRemove: function onRemove(recipient) {
205
209
  return onRecipientRemove(recipient);
206
210
  },
207
- contacts: contacts,
208
- contactGroups: contactGroups,
209
211
  recipients: recipients
210
212
  })), showShareControl && /*#__PURE__*/React.createElement("div", {
211
213
  className: styles['share-type-control']
@@ -226,8 +228,6 @@ export var ShareByEmail = function ShareByEmail(_ref) {
226
228
  };
227
229
  ShareByEmail.propTypes = {
228
230
  currentRecipients: PropTypes.arrayOf(PropTypes.object),
229
- contacts: contactsResponseType.isRequired,
230
- contactGroups: contactGroupsResponseType.isRequired,
231
231
  document: PropTypes.object.isRequired,
232
232
  documentType: PropTypes.string.isRequired,
233
233
  sharingDesc: PropTypes.string.isRequired,
@@ -31,12 +31,6 @@ describe('ShareByEmailComponent', function () {
31
31
  currentRecipients = _ref$currentRecipient === void 0 ? [] : _ref$currentRecipient;
32
32
 
33
33
  var props = {
34
- contacts: {
35
- data: []
36
- },
37
- contactGroups: {
38
- data: []
39
- },
40
34
  documentType: 'Files',
41
35
  onShare: onShare,
42
36
  document: document,
@@ -38,9 +38,7 @@ var styles = {
38
38
  */
39
39
 
40
40
  var SharingContent = function SharingContent(_ref) {
41
- var contacts = _ref.contacts,
42
- contactGroups = _ref.contactGroups,
43
- createContact = _ref.createContact,
41
+ var createContact = _ref.createContact,
44
42
  document = _ref.document,
45
43
  documentType = _ref.documentType,
46
44
  hasSharedParent = _ref.hasSharedParent,
@@ -80,8 +78,6 @@ var SharingContent = function SharingContent(_ref) {
80
78
  variant: "h6",
81
79
  className: "u-mb-1-half"
82
80
  }, t('Share.contacts.whoHasAccess')), showShareByEmail && /*#__PURE__*/React.createElement(DumbShareByEmail, {
83
- contacts: contacts,
84
- contactGroups: contactGroups,
85
81
  createContact: createContact,
86
82
  currentRecipients: recipients,
87
83
  document: document,
@@ -381,51 +381,6 @@ var deferablePromise = function deferablePromise() {
381
381
 
382
382
  var getMockProps = function getMockProps() {
383
383
  return {
384
- contacts: {
385
- id: 'contacts',
386
- definition: {
387
- doctype: 'io.cozy.contacts',
388
- selector: {
389
- _id: {
390
- $gt: null
391
- }
392
- },
393
- indexedFields: ['_id'],
394
- partialFilter: {
395
- trashed: {
396
- $or: [{
397
- $eq: false
398
- }, {
399
- $exists: false
400
- }]
401
- },
402
- $or: [{
403
- cozy: {
404
- $not: {
405
- $size: 0
406
- }
407
- }
408
- }, {
409
- email: {
410
- $not: {
411
- $size: 0
412
- }
413
- }
414
- }]
415
- },
416
- limit: 1000
417
- },
418
- fetchStatus: 'pending',
419
- lastFetch: null,
420
- lastUpdate: null,
421
- lastErrorUpdate: null,
422
- lastError: null,
423
- hasMore: false,
424
- count: 0,
425
- data: [],
426
- bookmark: null,
427
- options: null
428
- },
429
384
  document: {
430
385
  id: 'SOME_DOCUMENT_ID',
431
386
  name: 'SOME_DOCUMENT_NAME',
@@ -433,22 +388,6 @@ var getMockProps = function getMockProps() {
433
388
  _id: 'SOME_DOCUMENT_ID'
434
389
  },
435
390
  documentType: 'Organizations',
436
- contactGroups: {
437
- id: 'groups',
438
- definition: {
439
- doctype: 'io.cozy.contacts.groups'
440
- },
441
- fetchStatus: 'pending',
442
- lastFetch: null,
443
- lastUpdate: null,
444
- lastErrorUpdate: null,
445
- lastError: null,
446
- hasMore: false,
447
- count: 0,
448
- data: [],
449
- bookmark: null,
450
- options: null
451
- },
452
391
  hasSharedParent: null,
453
392
  isOwner: true,
454
393
  link: null,
@@ -98,9 +98,7 @@ var RejectRecipientActions = function RejectRecipientActions(_ref3) {
98
98
 
99
99
 
100
100
  var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfirmationContainer(_ref4) {
101
- var contacts = _ref4.contacts,
102
- contactGroups = _ref4.contactGroups,
103
- createContact = _ref4.createContact,
101
+ var createContact = _ref4.createContact,
104
102
  document = _ref4.document,
105
103
  documentType = _ref4.documentType,
106
104
  hasSharedParent = _ref4.hasSharedParent,
@@ -240,8 +238,6 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
240
238
  dialogContent = /*#__PURE__*/React.createElement(LoadingContent, null);
241
239
  } else if (status === 'sharing') {
242
240
  dialogContent = /*#__PURE__*/React.createElement(DialogContentOnShare, {
243
- contacts: contacts,
244
- contactGroups: contactGroups,
245
241
  createContact: createContact,
246
242
  document: document,
247
243
  documentType: documentType,
@@ -403,51 +403,6 @@ var deferablePromise = function deferablePromise() {
403
403
 
404
404
  var getMockProps = function getMockProps() {
405
405
  return {
406
- contacts: {
407
- id: 'contacts',
408
- definition: {
409
- doctype: 'io.cozy.contacts',
410
- selector: {
411
- _id: {
412
- $gt: null
413
- }
414
- },
415
- indexedFields: ['_id'],
416
- partialFilter: {
417
- trashed: {
418
- $or: [{
419
- $eq: false
420
- }, {
421
- $exists: false
422
- }]
423
- },
424
- $or: [{
425
- cozy: {
426
- $not: {
427
- $size: 0
428
- }
429
- }
430
- }, {
431
- email: {
432
- $not: {
433
- $size: 0
434
- }
435
- }
436
- }]
437
- },
438
- limit: 1000
439
- },
440
- fetchStatus: 'pending',
441
- lastFetch: null,
442
- lastUpdate: null,
443
- lastErrorUpdate: null,
444
- lastError: null,
445
- hasMore: false,
446
- count: 0,
447
- data: [],
448
- bookmark: null,
449
- options: null
450
- },
451
406
  document: {
452
407
  id: 'SOME_DOCUMENT_ID',
453
408
  name: 'SOME_DOCUMENT_NAME',
@@ -455,22 +410,6 @@ var getMockProps = function getMockProps() {
455
410
  _id: 'SOME_DOCUMENT_ID'
456
411
  },
457
412
  documentType: 'Organizations',
458
- contactGroups: {
459
- id: 'groups',
460
- definition: {
461
- doctype: 'io.cozy.contacts.groups'
462
- },
463
- fetchStatus: 'pending',
464
- lastFetch: null,
465
- lastUpdate: null,
466
- lastErrorUpdate: null,
467
- lastError: null,
468
- hasMore: false,
469
- count: 0,
470
- data: [],
471
- bookmark: null,
472
- options: null
473
- },
474
413
  hasSharedParent: null,
475
414
  isOwner: true,
476
415
  link: null,
@@ -3,22 +3,17 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["document"];
4
4
  import PropTypes from 'prop-types';
5
5
  import React from 'react';
6
- import { useClient, useQueryAll } from 'cozy-client';
6
+ import { useClient } from 'cozy-client';
7
7
  import { useFetchDocumentPath } from '../../hooks/useFetchDocumentPath';
8
8
  import { useSharingContext } from '../../hooks/useSharingContext';
9
9
  import { Contact } from '../../models';
10
- import { buildContactsQuery, buildContactGroupsQuery } from '../../queries/queries';
11
- import { default as DumbShareModal } from '../ShareModal';
10
+ import { ShareModal } from '../ShareModal';
12
11
  export var EditableSharingModal = function EditableSharingModal(_ref) {
13
12
  var document = _ref.document,
14
13
  rest = _objectWithoutProperties(_ref, _excluded);
15
14
 
16
15
  var client = useClient();
17
16
  var documentPath = useFetchDocumentPath(client, document);
18
- var contactsQuery = buildContactsQuery();
19
- var contactsResult = useQueryAll(contactsQuery.definition, contactsQuery.options);
20
- var contactGroupsQuery = buildContactGroupsQuery();
21
- var contactGroupsResult = useQueryAll(contactGroupsQuery.definition, contactGroupsQuery.options);
22
17
 
23
18
  var _useSharingContext = useSharingContext(),
24
19
  documentType = _useSharingContext.documentType,
@@ -36,9 +31,7 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
36
31
  shareByLink = _useSharingContext.shareByLink,
37
32
  updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
38
33
 
39
- return /*#__PURE__*/React.createElement(DumbShareModal, _extends({
40
- contacts: contactsResult,
41
- contactGroups: contactGroupsResult,
34
+ return /*#__PURE__*/React.createElement(ShareModal, _extends({
42
35
  createContact: function createContact(contact) {
43
36
  return client.create(Contact.doctype, contact);
44
37
  },
@@ -33,12 +33,6 @@ describe('EditableSharingModal', function () {
33
33
  client: client
34
34
  }, /*#__PURE__*/React.createElement(EditableSharingModal, {
35
35
  client: client,
36
- contacts: {
37
- data: []
38
- },
39
- contactGroups: {
40
- data: []
41
- },
42
36
  document: document,
43
37
  t: function t(x) {
44
38
  return x;
@@ -3,11 +3,8 @@ 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, contactGroupsResponseType } from '../propTypes';
7
6
  export var ShareModal = function ShareModal(_ref) {
8
- var contacts = _ref.contacts,
9
- contactGroups = _ref.contactGroups,
10
- createContact = _ref.createContact,
7
+ var createContact = _ref.createContact,
11
8
  document = _ref.document,
12
9
  _ref$documentType = _ref.documentType,
13
10
  documentType = _ref$documentType === void 0 ? 'Document' : _ref$documentType,
@@ -47,8 +44,6 @@ export var ShareModal = function ShareModal(_ref) {
47
44
  onUpdateShareLinkPermissions: onUpdateShareLinkPermissions,
48
45
  permissions: permissions
49
46
  }) : /*#__PURE__*/React.createElement(ShareDialogCozyToCozy, {
50
- contacts: contacts,
51
- contactGroups: contactGroups,
52
47
  createContact: createContact,
53
48
  document: document,
54
49
  documentType: documentType,
@@ -76,8 +71,6 @@ export var ShareModal = function ShareModal(_ref) {
76
71
  };
77
72
  export default ShareModal;
78
73
  ShareModal.propTypes = {
79
- contacts: contactsResponseType.isRequired,
80
- contactGroups: contactGroupsResponseType.isRequired,
81
74
  createContact: PropTypes.func.isRequired,
82
75
  document: PropTypes.object.isRequired,
83
76
  documentType: PropTypes.string,
@@ -1,71 +1,70 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
3
 
5
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; }
6
5
 
7
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; }
8
7
 
9
- import get from 'lodash/get';
10
8
  import PropTypes from 'prop-types';
11
- import React, { useState, useEffect } from 'react';
9
+ import React from 'react';
10
+ import { useQueryAll, isQueryLoading } from 'cozy-client';
11
+ import flag from 'cozy-flags';
12
12
  import ShareAutosuggest from './ShareAutosuggest';
13
- import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
13
+ import { getContactsFromGroupId } from '../helpers/contacts';
14
+ import { buildReachableContactsQuery, buildContactGroupsByIdsQuery, buildUnreachableContactsWithGroupsQuery } from '../queries/queries';
15
+ /**
16
+ * ShareRecipientsInput is responsible for fetching contacts and groups.
17
+ * We retrieve all the contacts that are reachable and the groups they belong to.
18
+ * In order to display the total number of members in each group, we also retrieve the contacts that are not reachable.
19
+ */
14
20
 
15
21
  var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
16
- var contacts = _ref.contacts,
17
- contactGroups = _ref.contactGroups,
18
- recipients = _ref.recipients,
22
+ var recipients = _ref.recipients,
19
23
  placeholder = _ref.placeholder,
20
24
  onPick = _ref.onPick,
21
25
  onRemove = _ref.onRemove;
26
+ var reachableContactsQuery = buildReachableContactsQuery();
27
+ var reachableContactsResult = useQueryAll(reachableContactsQuery.definition, reachableContactsQuery.options);
28
+ var unreachableContactsWithGroupsQuery = buildUnreachableContactsWithGroupsQuery();
29
+ var unreachableContactsWithGroupsResult = useQueryAll(unreachableContactsWithGroupsQuery.definition, _objectSpread(_objectSpread({}, unreachableContactsWithGroupsQuery.options), {}, {
30
+ enabled: !!flag('sharing.show-recipient-groups')
31
+ }));
32
+ var contactGroupsByIdsQuery = buildContactGroupsByIdsQuery(_toConsumableArray(new Set((reachableContactsResult.data || []).flatMap(function (contact) {
33
+ var _contact$relationship;
22
34
 
23
- var _useState = useState(false),
24
- _useState2 = _slicedToArray(_useState, 2),
25
- loading = _useState2[0],
26
- setLoading = _useState2[1];
27
-
28
- useEffect(function () {
29
- if (loading && !contacts.hasMore && contacts.fetchStatus === 'loaded' && !contactGroups.hasMore && contactGroups.fetchStatus === 'loaded') {
30
- setLoading(false);
31
- }
32
- }, [contacts, contactGroups, loading]);
33
-
34
- var onShareAutosuggestFocus = function onShareAutosuggestFocus() {
35
- if (contacts.hasMore || contacts.fetchStatus === 'loading' || contactGroups.hasMore || contactGroups.fetchStatus === 'loading') {
36
- setLoading(true);
37
- }
38
- };
39
-
40
- var getContactsAndGroups = function getContactsAndGroups() {
41
- // we need contacts to be loaded to be able to add all group members to recipients
42
- if (contacts.hasMore || contacts.fetchStatus === 'loading') {
43
- return contacts.data;
44
- } else {
45
- var contactGroupsWithCount = contactGroups.data.map(function (contactGroup) {
46
- return _objectSpread(_objectSpread({}, contactGroup), {}, {
47
- membersCount: contacts.data.reduce(function (total, contact) {
48
- if (get(contact, 'relationships.groups.data', []).map(function (group) {
49
- return group._id;
50
- }).includes(contactGroup._id)) {
51
- return total + 1;
52
- }
35
+ return (((_contact$relationship = contact.relationships) === null || _contact$relationship === void 0 || (_contact$relationship = _contact$relationship.groups) === null || _contact$relationship === void 0 ? void 0 : _contact$relationship.data) || []).map(function (group) {
36
+ return group._id;
37
+ });
38
+ }))));
39
+ var contactGroupsByIdsResult = useQueryAll(contactGroupsByIdsQuery.definition, contactGroupsByIdsQuery.options);
40
+ var isLoading = isQueryLoading(reachableContactsResult) || reachableContactsResult.hasMore || isQueryLoading(contactGroupsByIdsResult) || contactGroupsByIdsResult.hasMore || flag('sharing.show-recipient-groups') && (isQueryLoading(unreachableContactsWithGroupsResult) || unreachableContactsWithGroupsResult.hasMore);
41
+ var contactGroups = (contactGroupsByIdsResult.data || []).map(function (contactGroup) {
42
+ var reachableMembers = getContactsFromGroupId(reachableContactsResult.data, contactGroup.id).map(function (contact) {
43
+ return _objectSpread(_objectSpread({}, contact), {}, {
44
+ isReachable: true
45
+ });
46
+ });
53
47
 
54
- return total;
55
- }, 0)
56
- });
57
- }).filter(function (contactGroup) {
58
- return contactGroup.membersCount > 0;
48
+ if (flag('sharing.show-recipient-groups') !== true) {
49
+ return _objectSpread(_objectSpread({}, contactGroup), {}, {
50
+ members: reachableMembers
59
51
  });
60
- return [].concat(_toConsumableArray(contacts.data), _toConsumableArray(contactGroupsWithCount));
61
52
  }
62
- };
63
53
 
54
+ var unreachableMembers = getContactsFromGroupId(unreachableContactsWithGroupsResult.data, contactGroup.id).map(function (contact) {
55
+ return _objectSpread(_objectSpread({}, contact), {}, {
56
+ isReachable: false
57
+ });
58
+ });
59
+ return _objectSpread(_objectSpread({}, contactGroup), {}, {
60
+ members: [].concat(_toConsumableArray(reachableMembers), _toConsumableArray(unreachableMembers))
61
+ });
62
+ });
63
+ var contactsAndGroups = [].concat(_toConsumableArray(reachableContactsResult.data || []), _toConsumableArray(contactGroups));
64
64
  return /*#__PURE__*/React.createElement(ShareAutosuggest, {
65
- loading: loading,
66
- contactsAndGroups: getContactsAndGroups(),
65
+ loading: isLoading,
66
+ contactsAndGroups: contactsAndGroups,
67
67
  recipients: recipients,
68
- onFocus: onShareAutosuggestFocus,
69
68
  onPick: onPick,
70
69
  onRemove: onRemove,
71
70
  placeholder: placeholder
@@ -73,8 +72,6 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
73
72
  };
74
73
 
75
74
  ShareRecipientsInput.propTypes = {
76
- contacts: contactsResponseType.isRequired,
77
- contactGroups: contactGroupsResponseType.isRequired,
78
75
  recipients: PropTypes.array,
79
76
  placeholder: PropTypes.string,
80
77
  onPick: PropTypes.func.isRequired,