cozy-sharing 20.0.0 → 21.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.
- package/CHANGELOG.md +42 -0
- package/dist/actions/{openSharingLink.js → addToCozySharingLink.js} +12 -16
- package/dist/actions/createCozySharingLink.js +51 -0
- package/dist/actions/syncToCozySharingLink.js +51 -0
- package/dist/components/SharingBanner/components/PublicBanner.js +3 -3
- package/dist/components/SharingBanner/components/PublicBanner.spec.js +1 -1
- package/dist/components/SharingBanner/components/SharingBanner.js +3 -3
- package/dist/components/SharingBanner/hooks/useSharingInfos.js +37 -25
- package/dist/components/SharingBanner/hooks/useSharingInfos.spec.js +9 -9
- package/dist/index.js +3 -1
- package/package.json +2 -2
- package/src/actions/addToCozySharingLink.js +51 -0
- package/src/actions/createCozySharingLink.js +47 -0
- package/src/actions/{openSharingLink.js → syncToCozySharingLink.js} +10 -12
- package/src/components/SharingBanner/components/PublicBanner.jsx +3 -3
- package/src/components/SharingBanner/components/PublicBanner.spec.jsx +1 -1
- package/src/components/SharingBanner/components/SharingBanner.jsx +3 -3
- package/src/components/SharingBanner/hooks/useSharingInfos.jsx +12 -3
- package/src/components/SharingBanner/hooks/useSharingInfos.spec.js +7 -7
- package/src/index.jsx +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
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
|
+
# [21.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@20.0.0...cozy-sharing@21.0.0) (2025-01-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **sharing:** Add new links to `useSharingInfos` ([e9e51f7](https://github.com/cozy/cozy-libs/commit/e9e51f773698ea72af5aca218c65b597c4f918c7))
|
|
12
|
+
* **sharing:** Replace `openSharingLink` with 3 new actions ([9150b33](https://github.com/cozy/cozy-libs/commit/9150b33f7ef3cd55b986dffedd768f00408674dd))
|
|
13
|
+
* **sharing:** Update PublicBanner with new addSharingLink ([3be70fe](https://github.com/cozy/cozy-libs/commit/3be70fef1780806584cba1f07daaf0ebcd9596c7))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* **sharing:** We now need 3 separate actions to Cozy to Cozy sharing.
|
|
19
|
+
Replace the `openSharingLink` action with the desired
|
|
20
|
+
action with its link option
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
```
|
|
24
|
+
import {
|
|
25
|
+
addToCozySharingLink,
|
|
26
|
+
syncToCozySharingLink,
|
|
27
|
+
useSharingInfos
|
|
28
|
+
} from 'cozy-sharing'
|
|
29
|
+
|
|
30
|
+
const { addSharingLink, syncSharingLink } = useSharingInfos()
|
|
31
|
+
|
|
32
|
+
const actions = makeActions(
|
|
33
|
+
[
|
|
34
|
+
addToCozySharingLink,
|
|
35
|
+
syncToCozySharingLink
|
|
36
|
+
],
|
|
37
|
+
{
|
|
38
|
+
addSharingLink,
|
|
39
|
+
syncSharingLink
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
# [20.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@19.0.0...cozy-sharing@20.0.0) (2025-01-22)
|
|
7
49
|
|
|
8
50
|
|
|
@@ -2,9 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import React, { forwardRef } from 'react';
|
|
3
3
|
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
|
|
4
4
|
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
5
|
+
import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined';
|
|
5
6
|
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
6
7
|
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
7
|
-
import {
|
|
8
|
+
import { openExternalLink } from '../helpers/sharings';
|
|
8
9
|
import { getActionsI18n } from '../hoc/withLocales';
|
|
9
10
|
|
|
10
11
|
var makeComponent = function makeComponent(label, icon) {
|
|
@@ -17,39 +18,34 @@ var makeComponent = function makeComponent(label, icon) {
|
|
|
17
18
|
primary: label
|
|
18
19
|
}));
|
|
19
20
|
});
|
|
20
|
-
Component.displayName = '
|
|
21
|
+
Component.displayName = 'AddToCozySharingLink';
|
|
21
22
|
return Component;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
export var
|
|
25
|
+
export var addToCozySharingLink = function addToCozySharingLink(_ref) {
|
|
25
26
|
var isSharingShortcutCreated = _ref.isSharingShortcutCreated,
|
|
26
27
|
_ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
|
|
27
28
|
openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
|
|
28
29
|
_ref$isShortLabel = _ref.isShortLabel,
|
|
29
30
|
isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
|
|
30
|
-
|
|
31
|
+
addSharingLink = _ref.addSharingLink;
|
|
31
32
|
|
|
32
33
|
var _getActionsI18n = getActionsI18n(),
|
|
33
34
|
t = _getActionsI18n.t;
|
|
34
35
|
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
t: t
|
|
40
|
-
}),
|
|
41
|
-
icon = _getIconWithlabel.icon,
|
|
42
|
-
label = _getIconWithlabel.label;
|
|
43
|
-
|
|
36
|
+
var label = t('Share.banner.add_to_mine', {
|
|
37
|
+
smart_count: isShortLabel ? 1 : 2
|
|
38
|
+
});
|
|
39
|
+
var icon = CloudPlusOutlinedIcon;
|
|
44
40
|
return {
|
|
45
|
-
name: '
|
|
41
|
+
name: 'addToCozySharingLink',
|
|
46
42
|
label: label,
|
|
47
43
|
icon: icon,
|
|
48
44
|
displayCondition: function displayCondition() {
|
|
49
|
-
return openSharingLinkDisplayed;
|
|
45
|
+
return openSharingLinkDisplayed && !isSharingShortcutCreated;
|
|
50
46
|
},
|
|
51
47
|
action: function action() {
|
|
52
|
-
openExternalLink(
|
|
48
|
+
openExternalLink(addSharingLink);
|
|
53
49
|
},
|
|
54
50
|
Component: makeComponent(label, icon)
|
|
55
51
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud';
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
8
|
+
import { openExternalLink } from '../helpers/sharings';
|
|
9
|
+
import { getActionsI18n } from '../hoc/withLocales';
|
|
10
|
+
|
|
11
|
+
var makeComponent = function makeComponent(label, icon) {
|
|
12
|
+
var Component = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
13
|
+
return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
|
|
14
|
+
ref: ref
|
|
15
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
16
|
+
icon: icon
|
|
17
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
18
|
+
primary: label
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
Component.displayName = 'CreateCozySharingLink';
|
|
22
|
+
return Component;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export var createCozySharingLink = function createCozySharingLink(_ref) {
|
|
26
|
+
var _ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
|
|
27
|
+
openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
|
|
28
|
+
_ref$isShortLabel = _ref.isShortLabel,
|
|
29
|
+
isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
|
|
30
|
+
createSharingLink = _ref.createSharingLink;
|
|
31
|
+
|
|
32
|
+
var _getActionsI18n = getActionsI18n(),
|
|
33
|
+
t = _getActionsI18n.t;
|
|
34
|
+
|
|
35
|
+
var label = t('Share.create-cozy', {
|
|
36
|
+
smart_count: isShortLabel ? 1 : 2
|
|
37
|
+
});
|
|
38
|
+
var icon = ToTheCloudIcon;
|
|
39
|
+
return {
|
|
40
|
+
name: 'createCozySharingLink',
|
|
41
|
+
label: label,
|
|
42
|
+
icon: icon,
|
|
43
|
+
displayCondition: function displayCondition() {
|
|
44
|
+
return openSharingLinkDisplayed;
|
|
45
|
+
},
|
|
46
|
+
action: function action() {
|
|
47
|
+
openExternalLink(createSharingLink);
|
|
48
|
+
},
|
|
49
|
+
Component: makeComponent(label, icon)
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync';
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
8
|
+
import { openExternalLink } from '../helpers/sharings';
|
|
9
|
+
import { getActionsI18n } from '../hoc/withLocales';
|
|
10
|
+
|
|
11
|
+
var makeComponent = function makeComponent(label, icon) {
|
|
12
|
+
var Component = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
13
|
+
return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
|
|
14
|
+
ref: ref
|
|
15
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
16
|
+
icon: icon
|
|
17
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
18
|
+
primary: label
|
|
19
|
+
}));
|
|
20
|
+
});
|
|
21
|
+
Component.displayName = 'SyncToCozySharingLink';
|
|
22
|
+
return Component;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export var syncToCozySharingLink = function syncToCozySharingLink(_ref) {
|
|
26
|
+
var _ref$openSharingLinkD = _ref.openSharingLinkDisplayed,
|
|
27
|
+
openSharingLinkDisplayed = _ref$openSharingLinkD === void 0 ? true : _ref$openSharingLinkD,
|
|
28
|
+
_ref$isShortLabel = _ref.isShortLabel,
|
|
29
|
+
isShortLabel = _ref$isShortLabel === void 0 ? false : _ref$isShortLabel,
|
|
30
|
+
syncSharingLink = _ref.syncSharingLink;
|
|
31
|
+
|
|
32
|
+
var _getActionsI18n = getActionsI18n(),
|
|
33
|
+
t = _getActionsI18n.t;
|
|
34
|
+
|
|
35
|
+
var label = t('Share.banner.sync_to_mine', {
|
|
36
|
+
smart_count: isShortLabel ? 1 : 2
|
|
37
|
+
});
|
|
38
|
+
var icon = SyncIcon;
|
|
39
|
+
return {
|
|
40
|
+
name: 'syncToCozySharingLink',
|
|
41
|
+
label: label,
|
|
42
|
+
icon: icon,
|
|
43
|
+
displayCondition: function displayCondition() {
|
|
44
|
+
return openSharingLinkDisplayed;
|
|
45
|
+
},
|
|
46
|
+
action: function action() {
|
|
47
|
+
openExternalLink(syncSharingLink);
|
|
48
|
+
},
|
|
49
|
+
Component: makeComponent(label, icon)
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -55,14 +55,14 @@ var openExternalLink = function openExternalLink(url) {
|
|
|
55
55
|
var SharingBannerCozyToCozy = function SharingBannerCozyToCozy(_ref2) {
|
|
56
56
|
var sharing = _ref2.sharing,
|
|
57
57
|
isSharingShortcutCreated = _ref2.isSharingShortcutCreated,
|
|
58
|
-
|
|
58
|
+
addSharingLink = _ref2.addSharingLink,
|
|
59
59
|
onClose = _ref2.onClose;
|
|
60
60
|
|
|
61
61
|
var _useI18n2 = useI18n(),
|
|
62
62
|
t = _useI18n2.t;
|
|
63
63
|
|
|
64
64
|
var action = function action() {
|
|
65
|
-
return openExternalLink(
|
|
65
|
+
return openExternalLink(addSharingLink);
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
var buttonOne = isSharingShortcutCreated ? {
|
|
@@ -146,7 +146,7 @@ var SharingBannerByLink = function SharingBannerByLink(_ref3) {
|
|
|
146
146
|
SharingBannerCozyToCozy.propTypes = {
|
|
147
147
|
sharing: PropTypes.object.isRequired,
|
|
148
148
|
isSharingShortcutCreated: PropTypes.bool.isRequired,
|
|
149
|
-
|
|
149
|
+
addToCozySharingLink: PropTypes.string.isRequired,
|
|
150
150
|
onClose: PropTypes.func.isRequired
|
|
151
151
|
};
|
|
152
152
|
export { SharingBannerCozyToCozy, SharingBannerByLink };
|
|
@@ -36,7 +36,7 @@ describe('PublicBanner', function () {
|
|
|
36
36
|
var _render = render( /*#__PURE__*/React.createElement(SharingBannerCozyToCozy, {
|
|
37
37
|
sharing: sharing,
|
|
38
38
|
isSharingShortcutCreated: true,
|
|
39
|
-
|
|
39
|
+
addSharingLink: "discoveryLink",
|
|
40
40
|
onClose: function onClose() {}
|
|
41
41
|
})),
|
|
42
42
|
container = _render.container; // Then
|
|
@@ -14,16 +14,16 @@ export var SharingBanner = function SharingBanner(_ref) {
|
|
|
14
14
|
return setIsOpened(false);
|
|
15
15
|
}, [setIsOpened]);
|
|
16
16
|
var loading = sharingInfos.loading,
|
|
17
|
-
|
|
17
|
+
addSharingLink = sharingInfos.addSharingLink,
|
|
18
18
|
sharing = sharingInfos.sharing,
|
|
19
19
|
isSharingShortcutCreated = sharingInfos.isSharingShortcutCreated;
|
|
20
20
|
if (loading) return null;
|
|
21
|
-
return isOpened && (!
|
|
21
|
+
return isOpened && (!addSharingLink ? /*#__PURE__*/React.createElement(SharingBannerByLink, {
|
|
22
22
|
onClose: onClose
|
|
23
23
|
}) : /*#__PURE__*/React.createElement(SharingBannerCozyToCozy, {
|
|
24
24
|
isSharingShortcutCreated: isSharingShortcutCreated,
|
|
25
25
|
sharing: sharing,
|
|
26
|
-
|
|
26
|
+
addSharingLink: addSharingLink,
|
|
27
27
|
onClose: onClose
|
|
28
28
|
}));
|
|
29
29
|
};
|
|
@@ -13,34 +13,40 @@ var getSharingId = function getSharingId(permission) {
|
|
|
13
13
|
return sharingId;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
var CREATE_COZY_LINK = 'https://manager.cozycloud.cc/cozy/create';
|
|
16
17
|
export var useSharingInfos = function useSharingInfos() {
|
|
17
18
|
var previewPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/preview';
|
|
18
19
|
var client = useClient();
|
|
19
20
|
|
|
20
21
|
var _useState = useState(),
|
|
21
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
addSharingLink = _useState2[0],
|
|
24
|
+
setAddSharingLink = _useState2[1];
|
|
24
25
|
|
|
25
|
-
var _useState3 = useState(
|
|
26
|
+
var _useState3 = useState(),
|
|
26
27
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
syncSharingLink = _useState4[0],
|
|
29
|
+
setSyncSharingLink = _useState4[1];
|
|
29
30
|
|
|
30
|
-
var _useState5 = useState(),
|
|
31
|
+
var _useState5 = useState(false),
|
|
31
32
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
isSharingShortcutCreated = _useState6[0],
|
|
34
|
+
setIsSharingSharingcutCreated = _useState6[1];
|
|
34
35
|
|
|
35
|
-
var _useState7 = useState(
|
|
36
|
+
var _useState7 = useState(),
|
|
36
37
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
sharing = _useState8[0],
|
|
39
|
+
setSharing = _useState8[1];
|
|
40
|
+
|
|
41
|
+
var _useState9 = useState(true),
|
|
42
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
43
|
+
loading = _useState10[0],
|
|
44
|
+
setLoading = _useState10[1];
|
|
39
45
|
|
|
40
46
|
useEffect(function () {
|
|
41
47
|
var loadSharingDiscoveryLink = /*#__PURE__*/function () {
|
|
42
48
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
43
|
-
var response, _isSharingShortcutCreated, sharingId, _getQueryParameter2, sharecode, link, sharingsByIdQuery, _yield$client$query2, _sharing;
|
|
49
|
+
var response, _isSharingShortcutCreated, sharingId, _getQueryParameter2, sharecode, link, linkSync, sharingsByIdQuery, _yield$client$query2, _sharing;
|
|
44
50
|
|
|
45
51
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
46
52
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -55,35 +61,39 @@ export var useSharingInfos = function useSharingInfos() {
|
|
|
55
61
|
_isSharingShortcutCreated = models.permission.isShortcutCreatedOnTheRecipientCozy(response);
|
|
56
62
|
sharingId = getSharingId(response);
|
|
57
63
|
_getQueryParameter2 = getQueryParameter(), sharecode = _getQueryParameter2.sharecode;
|
|
58
|
-
link = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode
|
|
64
|
+
link = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode, {
|
|
65
|
+
shortcut: true
|
|
66
|
+
});
|
|
67
|
+
linkSync = client.collection('io.cozy.sharings').getDiscoveryLink(sharingId, sharecode);
|
|
59
68
|
sharingsByIdQuery = buildSharingsByIdQuery(sharingId);
|
|
60
|
-
_context.next =
|
|
69
|
+
_context.next = 13;
|
|
61
70
|
return client.query(sharingsByIdQuery.definition);
|
|
62
71
|
|
|
63
|
-
case
|
|
72
|
+
case 13:
|
|
64
73
|
_yield$client$query2 = _context.sent;
|
|
65
74
|
_sharing = _yield$client$query2.data;
|
|
66
|
-
|
|
75
|
+
setAddSharingLink(link);
|
|
76
|
+
setSyncSharingLink(linkSync);
|
|
67
77
|
setIsSharingSharingcutCreated(_isSharingShortcutCreated);
|
|
68
78
|
setSharing(_sharing);
|
|
69
|
-
_context.next =
|
|
79
|
+
_context.next = 24;
|
|
70
80
|
break;
|
|
71
81
|
|
|
72
|
-
case
|
|
73
|
-
_context.prev =
|
|
82
|
+
case 21:
|
|
83
|
+
_context.prev = 21;
|
|
74
84
|
_context.t0 = _context["catch"](1);
|
|
75
85
|
logger.warn('Failed to load sharing discovery link', _context.t0);
|
|
76
86
|
|
|
77
|
-
case
|
|
78
|
-
_context.prev =
|
|
87
|
+
case 24:
|
|
88
|
+
_context.prev = 24;
|
|
79
89
|
setLoading(false);
|
|
80
|
-
return _context.finish(
|
|
90
|
+
return _context.finish(24);
|
|
81
91
|
|
|
82
|
-
case
|
|
92
|
+
case 27:
|
|
83
93
|
case "end":
|
|
84
94
|
return _context.stop();
|
|
85
95
|
}
|
|
86
|
-
}, _callee, null, [[1,
|
|
96
|
+
}, _callee, null, [[1, 21, 24, 27]]);
|
|
87
97
|
}));
|
|
88
98
|
|
|
89
99
|
return function loadSharingDiscoveryLink() {
|
|
@@ -100,7 +110,9 @@ export var useSharingInfos = function useSharingInfos() {
|
|
|
100
110
|
return {
|
|
101
111
|
sharing: sharing,
|
|
102
112
|
loading: loading,
|
|
103
|
-
|
|
113
|
+
addSharingLink: addSharingLink,
|
|
114
|
+
syncSharingLink: syncSharingLink,
|
|
115
|
+
createCozyLink: CREATE_COZY_LINK,
|
|
104
116
|
isSharingShortcutCreated: isSharingShortcutCreated
|
|
105
117
|
};
|
|
106
118
|
};
|
|
@@ -86,13 +86,13 @@ describe('useSharingInfos', function () {
|
|
|
86
86
|
window.location = location;
|
|
87
87
|
});
|
|
88
88
|
it('returns the right infos when using useSharingInfo', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
89
|
-
var
|
|
89
|
+
var addSharingLink, _setup, result, waitForNextUpdate;
|
|
90
90
|
|
|
91
91
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
92
92
|
while (1) switch (_context.prev = _context.next) {
|
|
93
93
|
case 0:
|
|
94
|
-
|
|
95
|
-
getDiscoveryLinkMock.mockReturnValue(
|
|
94
|
+
addSharingLink = '/addSharingLink';
|
|
95
|
+
getDiscoveryLinkMock.mockReturnValue(addSharingLink);
|
|
96
96
|
fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithInstance);
|
|
97
97
|
queryMock.mockResolvedValue(mockSharing);
|
|
98
98
|
_setup = setup(), result = _setup.result, waitForNextUpdate = _setup.waitForNextUpdate; // default state
|
|
@@ -107,7 +107,7 @@ describe('useSharingInfos', function () {
|
|
|
107
107
|
expect(result.current.loading).toEqual(false);
|
|
108
108
|
expect(result.current.isSharingShortcutCreated).toEqual(true);
|
|
109
109
|
expect(result.current.sharing).toEqual(mockSharing.data);
|
|
110
|
-
expect(result.current.
|
|
110
|
+
expect(result.current.addSharingLink).toEqual(addSharingLink);
|
|
111
111
|
|
|
112
112
|
case 12:
|
|
113
113
|
case "end":
|
|
@@ -115,14 +115,14 @@ describe('useSharingInfos', function () {
|
|
|
115
115
|
}
|
|
116
116
|
}, _callee);
|
|
117
117
|
})));
|
|
118
|
-
it('returns the right infos when using useSharingInfo without
|
|
119
|
-
var
|
|
118
|
+
it('returns the right infos when using useSharingInfo without addSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
119
|
+
var addSharingLink, _setup2, result, waitForNextUpdate;
|
|
120
120
|
|
|
121
121
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
122
122
|
while (1) switch (_context2.prev = _context2.next) {
|
|
123
123
|
case 0:
|
|
124
|
-
|
|
125
|
-
getDiscoveryLinkMock.mockReturnValue(
|
|
124
|
+
addSharingLink = undefined;
|
|
125
|
+
getDiscoveryLinkMock.mockReturnValue(addSharingLink);
|
|
126
126
|
fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithoutInstance);
|
|
127
127
|
queryMock.mockResolvedValue(mockSharing);
|
|
128
128
|
_setup2 = setup(), result = _setup2.result, waitForNextUpdate = _setup2.waitForNextUpdate; // default state
|
|
@@ -137,7 +137,7 @@ describe('useSharingInfos', function () {
|
|
|
137
137
|
expect(result.current.loading).toEqual(false);
|
|
138
138
|
expect(result.current.isSharingShortcutCreated).toEqual(false);
|
|
139
139
|
expect(result.current.sharing).toEqual(mockSharing.data);
|
|
140
|
-
expect(result.current.
|
|
140
|
+
expect(result.current.addSharingLink).toEqual(addSharingLink);
|
|
141
141
|
|
|
142
142
|
case 12:
|
|
143
143
|
case "end":
|
package/dist/index.js
CHANGED
|
@@ -26,5 +26,7 @@ export { DOCUMENT_TYPE } from './helpers/documentType';
|
|
|
26
26
|
export { default as OpenSharingLinkButton } from './OpenSharingLinkButton';
|
|
27
27
|
export { default as OpenSharingLinkFabButton } from './OpenSharingLinkFabButton';
|
|
28
28
|
export { NativeFileSharingProvider, useNativeFileSharing } from './providers/NativeFileSharingProvider';
|
|
29
|
-
export {
|
|
29
|
+
export { createCozySharingLink } from './actions/createCozySharingLink';
|
|
30
|
+
export { addToCozySharingLink } from './actions/addToCozySharingLink';
|
|
31
|
+
export { syncToCozySharingLink } from './actions/syncToCozySharingLink';
|
|
30
32
|
export { shareNative } from './actions/shareNative';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.0.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"sideEffects": [
|
|
79
79
|
"*.css"
|
|
80
80
|
],
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "0c51f40c510be568da5c63ae617ec7493801161a"
|
|
82
82
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
5
|
+
import CloudPlusOutlinedIcon from 'cozy-ui/transpiled/react/Icons/CloudPlusOutlined'
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
8
|
+
|
|
9
|
+
import { openExternalLink } from '../helpers/sharings'
|
|
10
|
+
import { getActionsI18n } from '../hoc/withLocales'
|
|
11
|
+
|
|
12
|
+
const makeComponent = (label, icon) => {
|
|
13
|
+
const Component = forwardRef((props, ref) => {
|
|
14
|
+
return (
|
|
15
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
16
|
+
<ListItemIcon>
|
|
17
|
+
<Icon icon={icon} />
|
|
18
|
+
</ListItemIcon>
|
|
19
|
+
<ListItemText primary={label} />
|
|
20
|
+
</ActionsMenuItem>
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
Component.displayName = 'AddToCozySharingLink'
|
|
24
|
+
|
|
25
|
+
return Component
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const addToCozySharingLink = ({
|
|
29
|
+
isSharingShortcutCreated,
|
|
30
|
+
openSharingLinkDisplayed = true,
|
|
31
|
+
isShortLabel = false,
|
|
32
|
+
addSharingLink
|
|
33
|
+
}) => {
|
|
34
|
+
const { t } = getActionsI18n()
|
|
35
|
+
const label = t('Share.banner.add_to_mine', {
|
|
36
|
+
smart_count: isShortLabel ? 1 : 2
|
|
37
|
+
})
|
|
38
|
+
const icon = CloudPlusOutlinedIcon
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
name: 'addToCozySharingLink',
|
|
42
|
+
label,
|
|
43
|
+
icon,
|
|
44
|
+
displayCondition: () =>
|
|
45
|
+
openSharingLinkDisplayed && !isSharingShortcutCreated,
|
|
46
|
+
action: () => {
|
|
47
|
+
openExternalLink(addSharingLink)
|
|
48
|
+
},
|
|
49
|
+
Component: makeComponent(label, icon)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
5
|
+
import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud'
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
8
|
+
|
|
9
|
+
import { openExternalLink } from '../helpers/sharings'
|
|
10
|
+
import { getActionsI18n } from '../hoc/withLocales'
|
|
11
|
+
|
|
12
|
+
const makeComponent = (label, icon) => {
|
|
13
|
+
const Component = forwardRef((props, ref) => {
|
|
14
|
+
return (
|
|
15
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
16
|
+
<ListItemIcon>
|
|
17
|
+
<Icon icon={icon} />
|
|
18
|
+
</ListItemIcon>
|
|
19
|
+
<ListItemText primary={label} />
|
|
20
|
+
</ActionsMenuItem>
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
Component.displayName = 'CreateCozySharingLink'
|
|
24
|
+
|
|
25
|
+
return Component
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const createCozySharingLink = ({
|
|
29
|
+
openSharingLinkDisplayed = true,
|
|
30
|
+
isShortLabel = false,
|
|
31
|
+
createSharingLink
|
|
32
|
+
}) => {
|
|
33
|
+
const { t } = getActionsI18n()
|
|
34
|
+
const label = t('Share.create-cozy', { smart_count: isShortLabel ? 1 : 2 })
|
|
35
|
+
const icon = ToTheCloudIcon
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name: 'createCozySharingLink',
|
|
39
|
+
label,
|
|
40
|
+
icon,
|
|
41
|
+
displayCondition: () => openSharingLinkDisplayed,
|
|
42
|
+
action: () => {
|
|
43
|
+
openExternalLink(createSharingLink)
|
|
44
|
+
},
|
|
45
|
+
Component: makeComponent(label, icon)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -2,10 +2,11 @@ import React, { forwardRef } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
|
|
4
4
|
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
5
|
+
import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync'
|
|
5
6
|
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
6
7
|
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { openExternalLink } from '../helpers/sharings'
|
|
9
10
|
import { getActionsI18n } from '../hoc/withLocales'
|
|
10
11
|
|
|
11
12
|
const makeComponent = (label, icon) => {
|
|
@@ -19,32 +20,29 @@ const makeComponent = (label, icon) => {
|
|
|
19
20
|
</ActionsMenuItem>
|
|
20
21
|
)
|
|
21
22
|
})
|
|
22
|
-
Component.displayName = '
|
|
23
|
+
Component.displayName = 'SyncToCozySharingLink'
|
|
23
24
|
|
|
24
25
|
return Component
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export const
|
|
28
|
-
isSharingShortcutCreated,
|
|
28
|
+
export const syncToCozySharingLink = ({
|
|
29
29
|
openSharingLinkDisplayed = true,
|
|
30
30
|
isShortLabel = false,
|
|
31
|
-
|
|
31
|
+
syncSharingLink
|
|
32
32
|
}) => {
|
|
33
33
|
const { t } = getActionsI18n()
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
isSharingShortcutCreated,
|
|
37
|
-
isShortLabel,
|
|
38
|
-
t
|
|
34
|
+
const label = t('Share.banner.sync_to_mine', {
|
|
35
|
+
smart_count: isShortLabel ? 1 : 2
|
|
39
36
|
})
|
|
37
|
+
const icon = SyncIcon
|
|
40
38
|
|
|
41
39
|
return {
|
|
42
|
-
name: '
|
|
40
|
+
name: 'syncToCozySharingLink',
|
|
43
41
|
label,
|
|
44
42
|
icon,
|
|
45
43
|
displayCondition: () => openSharingLinkDisplayed,
|
|
46
44
|
action: () => {
|
|
47
|
-
openExternalLink(
|
|
45
|
+
openExternalLink(syncSharingLink)
|
|
48
46
|
},
|
|
49
47
|
Component: makeComponent(label, icon)
|
|
50
48
|
}
|
|
@@ -49,12 +49,12 @@ const openExternalLink = url => (window.location = url)
|
|
|
49
49
|
const SharingBannerCozyToCozy = ({
|
|
50
50
|
sharing,
|
|
51
51
|
isSharingShortcutCreated,
|
|
52
|
-
|
|
52
|
+
addSharingLink,
|
|
53
53
|
onClose
|
|
54
54
|
}) => {
|
|
55
55
|
const { t } = useI18n()
|
|
56
56
|
|
|
57
|
-
const action = () => openExternalLink(
|
|
57
|
+
const action = () => openExternalLink(addSharingLink)
|
|
58
58
|
const buttonOne = isSharingShortcutCreated
|
|
59
59
|
? {
|
|
60
60
|
label: t('Share.banner.sync_to_mine', { smart_count: 2 }),
|
|
@@ -139,7 +139,7 @@ const SharingBannerByLink = ({ onClose }) => {
|
|
|
139
139
|
SharingBannerCozyToCozy.propTypes = {
|
|
140
140
|
sharing: PropTypes.object.isRequired,
|
|
141
141
|
isSharingShortcutCreated: PropTypes.bool.isRequired,
|
|
142
|
-
|
|
142
|
+
addToCozySharingLink: PropTypes.string.isRequired,
|
|
143
143
|
onClose: PropTypes.func.isRequired
|
|
144
144
|
}
|
|
145
145
|
export { SharingBannerCozyToCozy, SharingBannerByLink }
|
|
@@ -7,19 +7,19 @@ export const SharingBanner = ({ sharingInfos }) => {
|
|
|
7
7
|
const [isOpened, setIsOpened] = useState(true)
|
|
8
8
|
const onClose = useCallback(() => setIsOpened(false), [setIsOpened])
|
|
9
9
|
|
|
10
|
-
const { loading,
|
|
10
|
+
const { loading, addSharingLink, sharing, isSharingShortcutCreated } =
|
|
11
11
|
sharingInfos
|
|
12
12
|
|
|
13
13
|
if (loading) return null
|
|
14
14
|
return (
|
|
15
15
|
isOpened &&
|
|
16
|
-
(!
|
|
16
|
+
(!addSharingLink ? (
|
|
17
17
|
<SharingBannerByLink onClose={onClose} />
|
|
18
18
|
) : (
|
|
19
19
|
<SharingBannerCozyToCozy
|
|
20
20
|
isSharingShortcutCreated={isSharingShortcutCreated}
|
|
21
21
|
sharing={sharing}
|
|
22
|
-
|
|
22
|
+
addSharingLink={addSharingLink}
|
|
23
23
|
onClose={onClose}
|
|
24
24
|
/>
|
|
25
25
|
))
|
|
@@ -12,10 +12,13 @@ const getSharingId = permission => {
|
|
|
12
12
|
return sharingId
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const CREATE_COZY_LINK = 'https://manager.cozycloud.cc/cozy/create'
|
|
16
|
+
|
|
15
17
|
export const useSharingInfos = (previewPath = '/preview') => {
|
|
16
18
|
const client = useClient()
|
|
17
19
|
|
|
18
|
-
const [
|
|
20
|
+
const [addSharingLink, setAddSharingLink] = useState()
|
|
21
|
+
const [syncSharingLink, setSyncSharingLink] = useState()
|
|
19
22
|
const [isSharingShortcutCreated, setIsSharingSharingcutCreated] =
|
|
20
23
|
useState(false)
|
|
21
24
|
const [sharing, setSharing] = useState()
|
|
@@ -35,6 +38,9 @@ export const useSharingInfos = (previewPath = '/preview') => {
|
|
|
35
38
|
const { sharecode } = getQueryParameter()
|
|
36
39
|
|
|
37
40
|
const link = client
|
|
41
|
+
.collection('io.cozy.sharings')
|
|
42
|
+
.getDiscoveryLink(sharingId, sharecode, { shortcut: true })
|
|
43
|
+
const linkSync = client
|
|
38
44
|
.collection('io.cozy.sharings')
|
|
39
45
|
.getDiscoveryLink(sharingId, sharecode)
|
|
40
46
|
const sharingsByIdQuery = buildSharingsByIdQuery(sharingId)
|
|
@@ -42,7 +48,8 @@ export const useSharingInfos = (previewPath = '/preview') => {
|
|
|
42
48
|
sharingsByIdQuery.definition
|
|
43
49
|
)
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
setAddSharingLink(link)
|
|
52
|
+
setSyncSharingLink(linkSync)
|
|
46
53
|
setIsSharingSharingcutCreated(isSharingShortcutCreated)
|
|
47
54
|
setSharing(sharing)
|
|
48
55
|
} catch (e) {
|
|
@@ -62,7 +69,9 @@ export const useSharingInfos = (previewPath = '/preview') => {
|
|
|
62
69
|
return {
|
|
63
70
|
sharing,
|
|
64
71
|
loading,
|
|
65
|
-
|
|
72
|
+
addSharingLink,
|
|
73
|
+
syncSharingLink,
|
|
74
|
+
createCozyLink: CREATE_COZY_LINK,
|
|
66
75
|
isSharingShortcutCreated
|
|
67
76
|
}
|
|
68
77
|
}
|
|
@@ -81,8 +81,8 @@ describe('useSharingInfos', () => {
|
|
|
81
81
|
})
|
|
82
82
|
|
|
83
83
|
it('returns the right infos when using useSharingInfo', async () => {
|
|
84
|
-
const
|
|
85
|
-
getDiscoveryLinkMock.mockReturnValue(
|
|
84
|
+
const addSharingLink = '/addSharingLink'
|
|
85
|
+
getDiscoveryLinkMock.mockReturnValue(addSharingLink)
|
|
86
86
|
fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithInstance)
|
|
87
87
|
queryMock.mockResolvedValue(mockSharing)
|
|
88
88
|
const { result, waitForNextUpdate } = setup()
|
|
@@ -93,12 +93,12 @@ describe('useSharingInfos', () => {
|
|
|
93
93
|
expect(result.current.loading).toEqual(false)
|
|
94
94
|
expect(result.current.isSharingShortcutCreated).toEqual(true)
|
|
95
95
|
expect(result.current.sharing).toEqual(mockSharing.data)
|
|
96
|
-
expect(result.current.
|
|
96
|
+
expect(result.current.addSharingLink).toEqual(addSharingLink)
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
it('returns the right infos when using useSharingInfo without
|
|
100
|
-
const
|
|
101
|
-
getDiscoveryLinkMock.mockReturnValue(
|
|
99
|
+
it('returns the right infos when using useSharingInfo without addSharingLink', async () => {
|
|
100
|
+
const addSharingLink = undefined
|
|
101
|
+
getDiscoveryLinkMock.mockReturnValue(addSharingLink)
|
|
102
102
|
fetchOwnPermissionsMock.mockResolvedValue(mockedPermissionsWithoutInstance)
|
|
103
103
|
queryMock.mockResolvedValue(mockSharing)
|
|
104
104
|
const { result, waitForNextUpdate } = setup()
|
|
@@ -109,7 +109,7 @@ describe('useSharingInfos', () => {
|
|
|
109
109
|
expect(result.current.loading).toEqual(false)
|
|
110
110
|
expect(result.current.isSharingShortcutCreated).toEqual(false)
|
|
111
111
|
expect(result.current.sharing).toEqual(mockSharing.data)
|
|
112
|
-
expect(result.current.
|
|
112
|
+
expect(result.current.addSharingLink).toEqual(addSharingLink)
|
|
113
113
|
})
|
|
114
114
|
|
|
115
115
|
it('returns loading false if there is nothing to do aka sharing by link', () => {
|
package/src/index.jsx
CHANGED
|
@@ -33,5 +33,7 @@ export {
|
|
|
33
33
|
NativeFileSharingProvider,
|
|
34
34
|
useNativeFileSharing
|
|
35
35
|
} from './providers/NativeFileSharingProvider'
|
|
36
|
-
export {
|
|
36
|
+
export { createCozySharingLink } from './actions/createCozySharingLink'
|
|
37
|
+
export { addToCozySharingLink } from './actions/addToCozySharingLink'
|
|
38
|
+
export { syncToCozySharingLink } from './actions/syncToCozySharingLink'
|
|
37
39
|
export { shareNative } from './actions/shareNative'
|