cozy-sharing 18.0.0 → 20.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 (48) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/SharingProvider.js +16 -9
  3. package/dist/components/Recipient/LinkRecipient.js +20 -4
  4. package/dist/components/Recipient/LinkRecipientPermissions.js +18 -129
  5. package/dist/components/Recipient/actions/editPermissionLink.js +71 -0
  6. package/dist/components/Recipient/actions/readOnlyPermissionLink.js +63 -0
  7. package/dist/components/ShareByLink.js +45 -185
  8. package/dist/components/ShareDialogCozyToCozy.js +2 -6
  9. package/dist/components/ShareDialogOnlyByLink.js +2 -8
  10. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -3
  11. package/dist/components/ShareModal/EditableSharingModal.js +1 -7
  12. package/dist/components/ShareModal.js +0 -12
  13. package/dist/components/ShareRestrictionModal/BoxDate.js +77 -0
  14. package/dist/components/ShareRestrictionModal/BoxEditingRights.js +83 -0
  15. package/dist/components/ShareRestrictionModal/BoxPassword.js +155 -0
  16. package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +118 -0
  17. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +256 -0
  18. package/dist/components/ShareRestrictionModal/helpers.js +310 -0
  19. package/dist/components/ShareRestrictionModal/helpers.spec.js +232 -0
  20. package/dist/components/WhoHasAccess.js +1 -5
  21. package/dist/helpers/permissions.js +15 -0
  22. package/locales/en.json +30 -0
  23. package/locales/fr.json +31 -0
  24. package/package.json +11 -7
  25. package/src/SharingProvider.jsx +10 -5
  26. package/src/components/Recipient/LinkRecipient.jsx +28 -4
  27. package/src/components/Recipient/LinkRecipientPermissions.jsx +28 -137
  28. package/src/components/Recipient/actions/editPermissionLink.js +63 -0
  29. package/src/components/Recipient/actions/readOnlyPermissionLink.js +59 -0
  30. package/src/components/ShareByLink.jsx +20 -96
  31. package/src/components/ShareDialogCozyToCozy.jsx +1 -5
  32. package/src/components/ShareDialogOnlyByLink.jsx +0 -6
  33. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -2
  34. package/src/components/ShareModal/EditableSharingModal.jsx +1 -7
  35. package/src/components/ShareModal.jsx +0 -12
  36. package/src/components/ShareRestrictionModal/BoxDate.jsx +76 -0
  37. package/src/components/ShareRestrictionModal/BoxEditingRights.jsx +91 -0
  38. package/src/components/ShareRestrictionModal/BoxPassword.jsx +126 -0
  39. package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +124 -0
  40. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +186 -0
  41. package/src/components/ShareRestrictionModal/helpers.js +227 -0
  42. package/src/components/ShareRestrictionModal/helpers.spec.js +159 -0
  43. package/src/components/WhoHasAccess.jsx +1 -5
  44. package/src/helpers/permissions.js +12 -0
  45. package/dist/components/EditLinkPermissionDialog.js +0 -72
  46. package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
  47. package/src/components/EditLinkPermissionDialog.jsx +0 -89
  48. package/src/components/EditLinkPermissionDialog.spec.jsx +0 -53
package/CHANGELOG.md CHANGED
@@ -3,6 +3,63 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [20.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@19.0.0...cozy-sharing@20.0.0) (2025-01-22)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **sharing:** Dispatch correct value ([4f2d17c](https://github.com/cozy/cozy-libs/commit/4f2d17cec7ce51fae97c825e3bb605c204dff330))
12
+
13
+
14
+ ### Features
15
+
16
+ * **sharing:** Auto focus password input ([614da3c](https://github.com/cozy/cozy-libs/commit/614da3cceae6f207ced87ae0bc81886224c83a24))
17
+ * **sharing:** Change ShareRestrictionModal validity ([00fb730](https://github.com/cozy/cozy-libs/commit/00fb730160e7f80ea57f6ebf7f47afadff9c0945))
18
+ * **sharing:** Improve BoxPassword ([7e39d7f](https://github.com/cozy/cozy-libs/commit/7e39d7fe16c021c9902a905f7dbdba92b2787eaf))
19
+ * **sharing:** Improve ShareDialogOnlyByLink UX ([4287e74](https://github.com/cozy/cozy-libs/commit/4287e74dc32aa7541e861939c4405a20426640e6))
20
+ * **sharing:** Rework logic of ShareRestrictionModal ([e33df9f](https://github.com/cozy/cozy-libs/commit/e33df9f5bb737dab6db738b435d2d0492698c8e9))
21
+ * **sharing:** Upgrade cozy-client to 53.0.0 ([fd6294f](https://github.com/cozy/cozy-libs/commit/fd6294f0870499a928795a73f099f3885e090a0a))
22
+
23
+
24
+ ### BREAKING CHANGES
25
+
26
+ * **sharing:** You must have `cozy-client >= 53.0.0`
27
+
28
+
29
+
30
+
31
+
32
+ # [19.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@18.0.0...cozy-sharing@19.0.0) (2025-01-08)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * **sharing:** Update propTypes ([0474d9c](https://github.com/cozy/cozy-libs/commit/0474d9c46344b1f7abf65fc6e419a25aef33d2ed))
38
+
39
+
40
+ ### Features
41
+
42
+ * **sharing:** Add 3 actions to use the new action menu ([1af8fa7](https://github.com/cozy/cozy-libs/commit/1af8fa7dbffad63d117149d14e09399e9d71a8a6))
43
+ * **sharing:** Add missing devDeps ([5221b40](https://github.com/cozy/cozy-libs/commit/5221b40397935538e95dcec82c939fb22196c991))
44
+ * **sharing:** Add needed packages ([36a2b67](https://github.com/cozy/cozy-libs/commit/36a2b6771275a35b3ab484b22a18b6d9c7b61496))
45
+ * **sharing:** Add ShareRestrictionModal component ([df5ed28](https://github.com/cozy/cozy-libs/commit/df5ed28c7c7f5dbb339bf26d563e8ffd825a686f))
46
+ * **sharing:** Add the 3 boxes of the new link-sharing modal ([a297d20](https://github.com/cozy/cozy-libs/commit/a297d20c46966c82447491a6fefe2d96509c45a9))
47
+ * **sharing:** Move revoke action to a secondary button ([83d3738](https://github.com/cozy/cozy-libs/commit/83d3738220e2c02ed749a08a47f92ca08ce9feb7))
48
+ * **sharing:** Remove EditLinkPermissionDialog ([1b8bd56](https://github.com/cozy/cozy-libs/commit/1b8bd560f4e72b885817f1f17a83156b6c1a7d58))
49
+ * **sharing:** Remove useless props ([cc3f816](https://github.com/cozy/cozy-libs/commit/cc3f816b6d35deb619488495bb767e1d76b557de))
50
+ * **sharing:** Replace old sharing link menu with the new modal ([de1a1c2](https://github.com/cozy/cozy-libs/commit/de1a1c27a5747c0b8bf091ed1856994f65cdcdb2))
51
+ * **sharing:** Upgrade packages ([9a1312d](https://github.com/cozy/cozy-libs/commit/9a1312d43cba1dcd521e8d6502865ac2071535cf))
52
+ * **sharing:** Use ShareRestrictionModal when creating share link ([248c3b4](https://github.com/cozy/cozy-libs/commit/248c3b4904649e17e935afdef1bd2a0b87082dc7))
53
+
54
+
55
+ ### BREAKING CHANGES
56
+
57
+ * **sharing:** You muse have `cozy-client >= 52.1.0` and `cozy-ui >= 116.0.0`
58
+
59
+
60
+
61
+
62
+
6
63
  # [18.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@17.0.0...cozy-sharing@18.0.0) (2024-12-23)
7
64
 
8
65
 
@@ -465,18 +465,22 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
465
465
  * updateDocumentPermissions - Description
466
466
  *
467
467
  * @param {Object} document A shared document
468
- * @param {Array} newVerbs The new verbs to use for the permission, eg. ['GET']
468
+ * @param {object} options The new verbs to use for the permission, eg. ['GET']
469
+ * @param {string[]} options.verbs The new verbs to use for the permission, eg. ['GET']
470
+ * @param {string} [options.expiresAt] The new expiration date for the permission
471
+ * @param {string} [options.password] The new password for the permission
469
472
  *
470
473
  * @return {Array}
471
474
  */
472
475
  _defineProperty(_this2, "updateDocumentPermissions", /*#__PURE__*/function () {
473
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, newVerbs) {
474
- var permissions, responses;
476
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
477
+ var verbs, expiresAt, password, permissions, responses;
475
478
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
476
479
  while (1) switch (_context11.prev = _context11.next) {
477
480
  case 0:
481
+ verbs = options.verbs, expiresAt = options.expiresAt, password = options.password;
478
482
  permissions = _getDocumentPermissions(_this2.state, document.id);
479
- _context11.next = 3;
483
+ _context11.next = 4;
480
484
  return Promise.all(permissions.map( /*#__PURE__*/function () {
481
485
  var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(permissionDocument) {
482
486
  var updatedPermissions, resp;
@@ -485,15 +489,18 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
485
489
  case 0:
486
490
  updatedPermissions = permissionDocument.attributes.permissions;
487
491
  Object.keys(updatedPermissions).map(function (permType) {
488
- updatedPermissions[permType].verbs = newVerbs;
492
+ updatedPermissions[permType].verbs = verbs;
489
493
  });
490
494
  _context10.next = 4;
491
- return _this2.permissionCol.add(permissionDocument, updatedPermissions);
495
+ return _this2.permissionCol.add(permissionDocument, updatedPermissions, {
496
+ expiresAt: expiresAt,
497
+ password: password
498
+ });
492
499
 
493
500
  case 4:
494
501
  resp = _context10.sent;
495
502
 
496
- _this2.dispatch(updateSharingLink(resp));
503
+ _this2.dispatch(updateSharingLink(resp.data));
497
504
 
498
505
  return _context10.abrupt("return", resp);
499
506
 
@@ -509,11 +516,11 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
509
516
  };
510
517
  }()));
511
518
 
512
- case 3:
519
+ case 4:
513
520
  responses = _context11.sent;
514
521
  return _context11.abrupt("return", responses);
515
522
 
516
- case 5:
523
+ case 6:
517
524
  case "end":
518
525
  return _context11.stop();
519
526
  }
@@ -13,7 +13,9 @@ import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
13
13
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
14
14
  import LinkRecipientPermissions from './LinkRecipientPermissions';
15
15
  import RecipientConfirm from './RecipientConfirm';
16
+ import { checkIsPermissionHasPassword, getPermissionExpiresDate } from '../../helpers/permissions';
16
17
  import { FADE_IN_DURATION } from '../../helpers/recipients';
18
+ import { useSharingContext } from '../../hooks/useSharingContext';
17
19
  var styles = {
18
20
  "recipient": "recipient__recipient___2DmZI",
19
21
  "recipients-list-light": "recipient__recipients-list-light___Vq4op",
@@ -34,15 +36,29 @@ var styles = {
34
36
 
35
37
  var LinkRecipient = function LinkRecipient(props) {
36
38
  var _useI18n = useI18n(),
37
- t = _useI18n.t;
39
+ t = _useI18n.t,
40
+ f = _useI18n.f,
41
+ lang = _useI18n.lang;
38
42
 
39
43
  var _useBreakpoints = useBreakpoints(),
40
44
  isMobile = _useBreakpoints.isMobile;
41
45
 
46
+ var _useSharingContext = useSharingContext(),
47
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions;
48
+
42
49
  var recipientConfirmationData = props.recipientConfirmationData,
43
50
  verifyRecipient = props.verifyRecipient,
44
51
  link = props.link,
45
- fadeIn = props.fadeIn;
52
+ fadeIn = props.fadeIn,
53
+ document = props.document;
54
+ var permissions = getDocumentPermissions(document._id);
55
+ var hasPassword = checkIsPermissionHasPassword(permissions);
56
+ var expiresDate = getPermissionExpiresDate(permissions);
57
+ var dateFormatted = expiresDate ? f(expiresDate, lang === 'fr' ? 'dd/LL/yyyy' : 'LL/dd/yyyy') : null;
58
+ var textPrimary = hasPassword ? t('Share.recipients.linkWithPassword') : t('Share.recipients.anyoneWithTheLink');
59
+ var textSecondary = expiresDate ? t('Share.recipients.expires', {
60
+ date: dateFormatted
61
+ }) : link;
46
62
  var RightPart = recipientConfirmationData ? /*#__PURE__*/React.createElement(RecipientConfirm, {
47
63
  recipientConfirmationData: recipientConfirmationData,
48
64
  verifyRecipient: verifyRecipient
@@ -64,8 +80,8 @@ var LinkRecipient = function LinkRecipient(props) {
64
80
  primary: /*#__PURE__*/React.createElement(Typography, {
65
81
  className: "u-ellipsis",
66
82
  variant: "body1"
67
- }, t('Share.recipients.anyoneWithTheLink')),
68
- secondary: link
83
+ }, textPrimary),
84
+ secondary: textSecondary
69
85
  }), RightPart));
70
86
  };
71
87
 
@@ -1,26 +1,15 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+ import PropTypes from 'prop-types';
4
3
  import React, { useState, useRef } from 'react';
5
4
  import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton';
6
- import Icon from 'cozy-ui/transpiled/react/Icon';
7
- import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
8
- import Spinner from 'cozy-ui/transpiled/react/Spinner';
9
- import Typography from 'cozy-ui/transpiled/react/Typography';
10
- import ActionMenu, { ActionMenuItem, ActionMenuRadio } from 'cozy-ui/transpiled/react/deprecated/ActionMenu';
11
- import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
12
5
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
13
- import { isOnlyReadOnlyLinkAllowed } from '../../helpers/link';
14
6
  import { checkIsReadOnlyPermissions } from '../../helpers/permissions';
15
- import logger from '../../logger';
7
+ import { ShareRestrictionModal } from '../ShareRestrictionModal/ShareRestrictionModal';
16
8
 
17
9
  var LinkRecipientPermissions = function LinkRecipientPermissions(_ref) {
18
10
  var className = _ref.className,
19
11
  document = _ref.document,
20
- documentType = _ref.documentType,
21
- permissions = _ref.permissions,
22
- onChangePermissions = _ref.onChangePermissions,
23
- onDisable = _ref.onDisable;
12
+ permissions = _ref.permissions;
24
13
 
25
14
  var _useI18n = useI18n(),
26
15
  t = _useI18n.t;
@@ -29,129 +18,29 @@ var LinkRecipientPermissions = function LinkRecipientPermissions(_ref) {
29
18
 
30
19
  var _useState = useState(false),
31
20
  _useState2 = _slicedToArray(_useState, 2),
32
- menuIsOpen = _useState2[0],
33
- setMenuIsOpen = _useState2[1];
34
-
35
- var _useState3 = useState(false),
36
- _useState4 = _slicedToArray(_useState3, 2),
37
- loading = _useState4[0],
38
- setLoading = _useState4[1];
21
+ openShareRestrictionModal = _useState2[0],
22
+ setOpenShareRestrictionModal = _useState2[1];
39
23
 
40
24
  var isReadOnlyPermissions = checkIsReadOnlyPermissions(permissions);
41
-
42
- var toggleMenu = function toggleMenu() {
43
- setMenuIsOpen(!menuIsOpen);
44
- };
45
-
46
- var deleteShareLink = /*#__PURE__*/function () {
47
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
48
- return _regeneratorRuntime.wrap(function _callee$(_context) {
49
- while (1) switch (_context.prev = _context.next) {
50
- case 0:
51
- _context.prev = 0;
52
- setLoading(true);
53
- _context.next = 4;
54
- return onDisable(document);
55
-
56
- case 4:
57
- _context.next = 10;
58
- break;
59
-
60
- case 6:
61
- _context.prev = 6;
62
- _context.t0 = _context["catch"](0);
63
- Alerter.error(t("".concat(documentType, ".share.error.revoke")));
64
- logger.log(_context.t0);
65
-
66
- case 10:
67
- _context.prev = 10;
68
- setLoading(false);
69
- return _context.finish(10);
70
-
71
- case 13:
72
- case "end":
73
- return _context.stop();
74
- }
75
- }, _callee, null, [[0, 6, 10, 13]]);
76
- }));
77
-
78
- return function deleteShareLink() {
79
- return _ref2.apply(this, arguments);
80
- };
81
- }();
82
-
83
- var updateLinkPermissions = function updateLinkPermissions(_ref3) {
84
- var isReadOnly = _ref3.isReadOnly;
85
- var verbs = isReadOnly ? ['GET'] : ['GET', 'POST', 'PUT', 'PATCH'];
86
-
87
- try {
88
- onChangePermissions(document, verbs);
89
- } catch (err) {
90
- Alerter.error(t("".concat(documentType, ".share.shareByLink.permserror")));
91
- logger.log(err);
92
- }
93
- };
94
-
95
25
  return /*#__PURE__*/React.createElement("div", {
96
26
  className: className
97
- }, loading && /*#__PURE__*/React.createElement(Spinner, null), !loading && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
98
- onClick: toggleMenu,
27
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DropdownButton, {
99
28
  ref: buttonRef,
100
- textVariant: "body2"
101
- }, t("Share.type.".concat(isReadOnlyPermissions ? 'one-way' : 'two-way')).toLowerCase()), menuIsOpen && /*#__PURE__*/React.createElement(ActionMenu, {
102
- onClose: toggleMenu,
103
- popperOptions: {
104
- placement: 'bottom-end',
105
- strategy: 'fixed'
106
- },
107
- anchorElRef: buttonRef
108
- }, /*#__PURE__*/React.createElement(ActionMenuItem, {
109
- left: /*#__PURE__*/React.createElement(ActionMenuRadio, {
110
- name: "permissionLinkMenu",
111
- value: "true",
112
- checked: isReadOnlyPermissions
113
- }),
29
+ textVariant: "body2",
114
30
  onClick: function onClick() {
115
- toggleMenu();
116
- updateLinkPermissions({
117
- isReadOnly: true
118
- });
31
+ return setOpenShareRestrictionModal(true);
119
32
  }
120
- }, /*#__PURE__*/React.createElement(React.Fragment, null, (document === null || document === void 0 ? void 0 : document.type) === 'directory' ? t("Share.permissionLink.seeFolder") : t("Share.permissionLink.seeFile"), /*#__PURE__*/React.createElement(Typography, {
121
- className: "u-mt-half",
122
- variant: "caption",
123
- color: "textSecondary"
124
- }, t('Share.permissionLink.readDescription')))), !isOnlyReadOnlyLinkAllowed({
125
- documentType: documentType
126
- }) && /*#__PURE__*/React.createElement(ActionMenuItem, {
127
- left: /*#__PURE__*/React.createElement(ActionMenuRadio, {
128
- name: "permissionLinkMenu",
129
- value: "false",
130
- checked: !isReadOnlyPermissions
131
- }),
132
- onClick: function onClick() {
133
- toggleMenu();
134
- updateLinkPermissions({
135
- isReadOnly: false
136
- });
137
- }
138
- }, /*#__PURE__*/React.createElement(React.Fragment, null, (document === null || document === void 0 ? void 0 : document.type) === 'directory' ? t("Share.permissionLink.modifyFolder") : t("Share.permissionLink.modifyFile"), /*#__PURE__*/React.createElement(Typography, {
139
- className: "u-mt-half",
140
- variant: "caption",
141
- color: "textSecondary"
142
- }, t('Share.permissionLink.writeDescription')))), /*#__PURE__*/React.createElement("hr", null), /*#__PURE__*/React.createElement(ActionMenuItem, {
143
- left: /*#__PURE__*/React.createElement(Icon, {
144
- icon: TrashIcon,
145
- color: "var(--errorColor)"
146
- }),
147
- onClick: function onClick() {
148
- toggleMenu();
149
- deleteShareLink();
33
+ }, t("Share.type.".concat(isReadOnlyPermissions ? 'one-way' : 'two-way')).toLowerCase()), openShareRestrictionModal && /*#__PURE__*/React.createElement(ShareRestrictionModal, {
34
+ file: document,
35
+ onClose: function onClose() {
36
+ return setOpenShareRestrictionModal(false);
150
37
  }
151
- }, /*#__PURE__*/React.createElement(Typography, {
152
- className: "u-error",
153
- variant: "body1"
154
- }, t('Share.permissionLink.deactivate'))))));
38
+ })));
155
39
  };
156
40
 
41
+ LinkRecipientPermissions.propTypes = {
42
+ className: PropTypes.string,
43
+ document: PropTypes.object.isRequired,
44
+ permissions: PropTypes.arrayOf(PropTypes.object).isRequired
45
+ };
157
46
  export default LinkRecipientPermissions;
@@ -0,0 +1,71 @@
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 ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
5
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
6
+ import Radios from 'cozy-ui/transpiled/react/Radios';
7
+ import { isOnlyReadOnlyLinkAllowed } from '../../../helpers/link';
8
+ import { useSharingContext } from '../../../hooks/useSharingContext';
9
+
10
+ var makeComponent = function makeComponent(_ref) {
11
+ var label = _ref.label,
12
+ desc = _ref.desc,
13
+ editingRights = _ref.editingRights;
14
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
15
+ var _useSharingContext = useSharingContext(),
16
+ updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
17
+
18
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
19
+ ref: ref,
20
+ button: false,
21
+ onClick: function onClick() {
22
+ return props.onClick({
23
+ updateDocumentPermissions: updateDocumentPermissions
24
+ });
25
+ }
26
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
27
+ checked: editingRights === 'write'
28
+ })), /*#__PURE__*/React.createElement(ListItemText, {
29
+ primary: label,
30
+ secondary: desc
31
+ }));
32
+ });
33
+ Component.displayName = 'EditPermissionLink';
34
+ return Component;
35
+ };
36
+ /**
37
+ * @param {boolean} isDirectory - true if the document is a directory
38
+ * @param {function} t - translation function
39
+ * @param {string} editingRights - current editing rights
40
+ * @param {function} setEditingRights - function to set editing rights
41
+ * @param {string} documentType - type of the document
42
+ */
43
+
44
+
45
+ export var editPermissionLink = function editPermissionLink(_ref2) {
46
+ var isDirectory = _ref2.isDirectory,
47
+ t = _ref2.t,
48
+ editingRights = _ref2.editingRights,
49
+ setEditingRights = _ref2.setEditingRights,
50
+ documentType = _ref2.documentType;
51
+ var label = isDirectory ? t('Share.permissionLink.modifyFolder') : t('Share.permissionLink.modifyFile');
52
+ var desc = t('Share.permissionLink.writeDescription');
53
+ return {
54
+ name: 'editPermissionLink',
55
+ label: label,
56
+ icon: null,
57
+ displayCondition: function displayCondition() {
58
+ return !isOnlyReadOnlyLinkAllowed({
59
+ documentType: documentType
60
+ });
61
+ },
62
+ action: function action() {
63
+ setEditingRights('write');
64
+ },
65
+ Component: makeComponent({
66
+ label: label,
67
+ desc: desc,
68
+ editingRights: editingRights
69
+ })
70
+ };
71
+ };
@@ -0,0 +1,63 @@
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 ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
5
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
6
+ import Radios from 'cozy-ui/transpiled/react/Radios';
7
+ import { useSharingContext } from '../../../hooks/useSharingContext';
8
+
9
+ var makeComponent = function makeComponent(_ref) {
10
+ var label = _ref.label,
11
+ desc = _ref.desc,
12
+ editingRights = _ref.editingRights;
13
+ var Component = /*#__PURE__*/forwardRef(function (props, ref) {
14
+ var _useSharingContext = useSharingContext(),
15
+ updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
16
+
17
+ return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
18
+ ref: ref,
19
+ button: false,
20
+ onClick: function onClick() {
21
+ return props.onClick({
22
+ updateDocumentPermissions: updateDocumentPermissions
23
+ });
24
+ }
25
+ }), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Radios, {
26
+ checked: editingRights === 'readOnly'
27
+ })), /*#__PURE__*/React.createElement(ListItemText, {
28
+ primary: label,
29
+ secondary: desc
30
+ }));
31
+ });
32
+ Component.displayName = 'ReadOnlyPermissionLink';
33
+ return Component;
34
+ };
35
+ /**
36
+ * @param {boolean} isDirectory - true if the document is a directory
37
+ * @param {function} t - translation function
38
+ * @param {string} editingRights - current editing rights
39
+ * @param {function} setEditingRights - function to set editing rights
40
+ */
41
+
42
+
43
+ export var readOnlyPermissionLink = function readOnlyPermissionLink(_ref2) {
44
+ var isDirectory = _ref2.isDirectory,
45
+ t = _ref2.t,
46
+ editingRights = _ref2.editingRights,
47
+ setEditingRights = _ref2.setEditingRights;
48
+ var label = isDirectory ? t('Share.permissionLink.seeFolder') : t('Share.permissionLink.seeFile');
49
+ var desc = t('Share.permissionLink.readDescription');
50
+ return {
51
+ name: 'readOnlyPermissionLink',
52
+ label: label,
53
+ icon: null,
54
+ action: function action() {
55
+ setEditingRights('readOnly');
56
+ },
57
+ Component: makeComponent({
58
+ label: label,
59
+ desc: desc,
60
+ editingRights: editingRights
61
+ })
62
+ };
63
+ };