cozy-sharing 12.3.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 (65) hide show
  1. package/.storybook/preview.jsx +1 -0
  2. package/CHANGELOG.md +29 -0
  3. package/dist/components/ContactSuggestion.js +7 -3
  4. package/dist/components/ContactSuggestion.spec.js +7 -1
  5. package/dist/components/Recipient/GroupRecipient.js +14 -7
  6. package/dist/components/Recipient/GroupRecipientDetail.js +4 -2
  7. package/dist/components/Recipient/GroupRecipientDetailWithAccess.js +9 -11
  8. package/dist/components/Recipient/GroupRecipientDetailWithoutAccess.js +8 -4
  9. package/dist/components/Recipient/GroupRecipientPermissions.js +3 -6
  10. package/dist/components/Recipient/MemberRecipient.js +1 -2
  11. package/dist/components/Recipient/MemberRecipientPermissions.js +1 -1
  12. package/dist/components/ShareAutosuggest.js +16 -9
  13. package/dist/components/ShareAutosuggest.spec.js +38 -13
  14. package/dist/components/ShareAutosuggest.stories.js +61 -0
  15. package/dist/components/ShareByEmail.js +15 -15
  16. package/dist/components/ShareByEmail.spec.js +0 -6
  17. package/dist/components/ShareDialogCozyToCozy.js +1 -5
  18. package/dist/components/ShareDialogCozyToCozy.spec.js +0 -61
  19. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -5
  20. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +0 -61
  21. package/dist/components/ShareModal/EditableSharingModal.js +3 -10
  22. package/dist/components/ShareModal/EditableSharingModal.spec.js +0 -6
  23. package/dist/components/ShareModal.js +1 -8
  24. package/dist/components/ShareRecipientsInput.js +46 -49
  25. package/dist/components/ShareRecipientsInput.spec.js +120 -144
  26. package/dist/helpers/contacts.js +12 -1
  27. package/dist/helpers/recipients.js +16 -9
  28. package/dist/helpers/successMessage.js +58 -16
  29. package/dist/helpers/successMessage.spec.js +122 -57
  30. package/dist/queries/queries.js +37 -5
  31. package/dist/styles/autosuggest.styl +2 -1
  32. package/dist/stylesheet.css +2 -1
  33. package/locales/en.json +23 -10
  34. package/locales/fr.json +23 -8
  35. package/package.json +4 -4
  36. package/src/components/ContactSuggestion.jsx +9 -3
  37. package/src/components/ContactSuggestion.spec.jsx +10 -1
  38. package/src/components/Recipient/GroupRecipient.jsx +17 -10
  39. package/src/components/Recipient/GroupRecipientDetail.jsx +5 -2
  40. package/src/components/Recipient/GroupRecipientDetailWithAccess.jsx +9 -14
  41. package/src/components/Recipient/GroupRecipientDetailWithoutAccess.jsx +8 -3
  42. package/src/components/Recipient/GroupRecipientPermissions.jsx +3 -8
  43. package/src/components/Recipient/MemberRecipient.jsx +4 -3
  44. package/src/components/Recipient/MemberRecipientPermissions.jsx +1 -1
  45. package/src/components/ShareAutosuggest.jsx +16 -11
  46. package/src/components/ShareAutosuggest.spec.jsx +31 -10
  47. package/src/components/ShareAutosuggest.stories.jsx +63 -0
  48. package/src/components/ShareByEmail.jsx +11 -11
  49. package/src/components/ShareByEmail.spec.jsx +0 -4
  50. package/src/components/ShareDialogCozyToCozy.jsx +0 -4
  51. package/src/components/ShareDialogCozyToCozy.spec.jsx +0 -67
  52. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -4
  53. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +0 -67
  54. package/src/components/ShareModal/EditableSharingModal.jsx +3 -21
  55. package/src/components/ShareModal/EditableSharingModal.spec.jsx +0 -2
  56. package/src/components/ShareModal.jsx +1 -7
  57. package/src/components/ShareRecipientsInput.jsx +84 -52
  58. package/src/components/ShareRecipientsInput.spec.jsx +140 -145
  59. package/src/helpers/contacts.js +8 -0
  60. package/src/helpers/recipients.js +24 -15
  61. package/src/helpers/successMessage.js +71 -21
  62. package/src/helpers/successMessage.spec.js +129 -69
  63. package/src/queries/queries.js +36 -5
  64. package/src/styles/autosuggest.styl +2 -1
  65. package/test/AppLike.jsx +6 -3
@@ -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,